22#include < json/value.h>
33#include < json/writer.h>
44#include < utility>
5+ #include < stdexcept>
56#include " assert.h"
67#ifdef JSON_USE_CPPTL
78# include < cpptl/conststring.h>
1314
1415#define JSON_ASSERT_UNREACHABLE assert ( false )
1516#define JSON_ASSERT ( condition ) assert ( condition ); // @todo <= change this into an exception throw
16- #define JSON_ASSERT_MESSAGE ( condition, message ) assert ( condition && message ); // @todo <= change this into an exception throw
17+ #define JSON_ASSERT_MESSAGE ( condition, message ) if (!( condition )) throw std::runtime_error ( message );
1718
1819namespace Json {
1920
@@ -265,8 +266,8 @@ Value::CZString::isStaticString() const
265266 */
266267Value::Value ( ValueType type )
267268 : type_( type )
268- , comments_( 0 )
269269 , allocated_( 0 )
270+ , comments_( 0 )
270271# ifdef JSON_VALUE_USE_INTERNAL_MAP
271272 , itemIsUsed_( 0 )
272273#endif
@@ -680,7 +681,7 @@ Value::asString() const
680681 case realValue:
681682 case arrayValue:
682683 case objectValue:
683- JSON_ASSERT ( " Type is not convertible to double " && false );
684+ JSON_ASSERT_MESSAGE ( false , " Type is not convertible to string " );
684685 default :
685686 JSON_ASSERT_UNREACHABLE;
686687 }
@@ -705,17 +706,17 @@ Value::asInt() const
705706 case intValue:
706707 return value_.int_ ;
707708 case uintValue:
708- JSON_ASSERT ( value_.uint_ < maxInt && " integer out of signed integer range" );
709+ JSON_ASSERT_MESSAGE ( value_.uint_ < ( unsigned ) maxInt, " integer out of signed integer range" );
709710 return value_.uint_ ;
710711 case realValue:
711- JSON_ASSERT ( value_.real_ >= minInt && value_.real_ <= maxInt && " Real out of signed integer range" );
712+ JSON_ASSERT_MESSAGE ( value_.real_ >= minInt && value_.real_ <= maxInt, " Real out of signed integer range" );
712713 return Int ( value_.real_ );
713714 case booleanValue:
714715 return value_.bool_ ? 1 : 0 ;
715716 case stringValue:
716717 case arrayValue:
717718 case objectValue:
718- JSON_ASSERT ( " Type is not convertible to double " && false );
719+ JSON_ASSERT_MESSAGE ( false , " Type is not convertible to int " );
719720 default :
720721 JSON_ASSERT_UNREACHABLE;
721722 }
@@ -730,19 +731,19 @@ Value::asUInt() const
730731 case nullValue:
731732 return 0 ;
732733 case intValue:
733- JSON_ASSERT ( value_.int_ >= 0 && " Negative integer can not be converted to unsigned integer" );
734+ JSON_ASSERT_MESSAGE ( value_.int_ >= 0 , " Negative integer can not be converted to unsigned integer" );
734735 return value_.int_ ;
735736 case uintValue:
736737 return value_.uint_ ;
737738 case realValue:
738- JSON_ASSERT ( value_.real_ >= 0 && value_.real_ <= maxUInt && " Real out of unsigned integer range" );
739+ JSON_ASSERT_MESSAGE ( value_.real_ >= 0 && value_.real_ <= maxUInt, " Real out of unsigned integer range" );
739740 return UInt ( value_.real_ );
740741 case booleanValue:
741742 return value_.bool_ ? 1 : 0 ;
742743 case stringValue:
743744 case arrayValue:
744745 case objectValue:
745- JSON_ASSERT ( " Type is not convertible to double " && false );
746+ JSON_ASSERT_MESSAGE ( false , " Type is not convertible to uint " );
746747 default :
747748 JSON_ASSERT_UNREACHABLE;
748749 }
@@ -767,7 +768,7 @@ Value::asDouble() const
767768 case stringValue:
768769 case arrayValue:
769770 case objectValue:
770- JSON_ASSERT ( " Type is not convertible to double" && false );
771+ JSON_ASSERT_MESSAGE ( false , " Type is not convertible to double" );
771772 default :
772773 JSON_ASSERT_UNREACHABLE;
773774 }
@@ -816,7 +817,7 @@ Value::isConvertibleTo( ValueType other ) const
816817 || other == booleanValue;
817818 case uintValue:
818819 return ( other == nullValue && value_.uint_ == 0 )
819- || ( other == intValue && value_.uint_ <= maxInt )
820+ || ( other == intValue && value_.uint_ <= ( unsigned ) maxInt )
820821 || other == uintValue
821822 || other == realValue
822823 || other == stringValue
@@ -1499,22 +1500,22 @@ PathArgument::PathArgument()
14991500
15001501
15011502PathArgument::PathArgument ( Value::UInt index )
1502- : kind_( kindIndex )
1503- , index_( index )
1503+ : index_( index )
1504+ , kind_( kindIndex )
15041505{
15051506}
15061507
15071508
15081509PathArgument::PathArgument ( const char *key )
1509- : kind_( kindKey )
1510- , key_( key )
1510+ : key_( key )
1511+ , kind_( kindKey )
15111512{
15121513}
15131514
15141515
15151516PathArgument::PathArgument ( const std::string &key )
1516- : kind_( kindKey )
1517- , key_( key.c_str() )
1517+ : key_( key.c_str() )
1518+ , kind_( kindKey )
15181519{
15191520}
15201521
0 commit comments