mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-12 10:03:51 +01:00
Fixed compilation warnings. Added -Wall to linux-gcc compilation. JSON_ASSERT_MESSAGE now throws exception (but JSON_ASSERT does not).
This commit is contained in:
parent
842d64e8d7
commit
a44cffb342
@ -76,7 +76,7 @@ elif platform == 'mingw':
|
||||
env.Append( CPPDEFINES=[ "WIN32", "NDEBUG", "_MT" ] )
|
||||
elif platform == 'linux-gcc':
|
||||
env.Tool( 'default' )
|
||||
env.Append( LIBS = ['pthread'] )
|
||||
env.Append( LIBS = ['pthread'], CCFLAGS = "-Wall" )
|
||||
else:
|
||||
print "UNSUPPORTED PLATFORM."
|
||||
env.Exit(1)
|
||||
|
@ -518,7 +518,7 @@ namespace Json {
|
||||
class ValueAllocator
|
||||
{
|
||||
public:
|
||||
enum { unknown = -1 };
|
||||
enum { unknown = (unsigned)-1 };
|
||||
|
||||
virtual ~ValueAllocator();
|
||||
|
||||
|
@ -13,12 +13,12 @@ readInputTestFile( const char *path )
|
||||
if ( !file )
|
||||
return std::string("");
|
||||
fseek( file, 0, SEEK_END );
|
||||
int size = ftell( file );
|
||||
long size = ftell( file );
|
||||
fseek( file, 0, SEEK_SET );
|
||||
std::string text;
|
||||
char *buffer = new char[size+1];
|
||||
buffer[size] = 0;
|
||||
if ( fread( buffer, 1, size, file ) == size )
|
||||
if ( fread( buffer, 1, size, file ) == (unsigned long)size )
|
||||
text = buffer;
|
||||
fclose( file );
|
||||
delete[] buffer;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <json/value.h>
|
||||
#include <json/writer.h>
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include "assert.h"
|
||||
#ifdef JSON_USE_CPPTL
|
||||
# include <cpptl/conststring.h>
|
||||
@ -13,7 +14,7 @@
|
||||
|
||||
#define JSON_ASSERT_UNREACHABLE assert( false )
|
||||
#define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw
|
||||
#define JSON_ASSERT_MESSAGE( condition, message ) assert( condition && message ); // @todo <= change this into an exception throw
|
||||
#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
|
||||
|
||||
namespace Json {
|
||||
|
||||
@ -265,8 +266,8 @@ Value::CZString::isStaticString() const
|
||||
*/
|
||||
Value::Value( ValueType type )
|
||||
: type_( type )
|
||||
, comments_( 0 )
|
||||
, allocated_( 0 )
|
||||
, comments_( 0 )
|
||||
# ifdef JSON_VALUE_USE_INTERNAL_MAP
|
||||
, itemIsUsed_( 0 )
|
||||
#endif
|
||||
@ -680,7 +681,7 @@ Value::asString() const
|
||||
case realValue:
|
||||
case arrayValue:
|
||||
case objectValue:
|
||||
JSON_ASSERT( "Type is not convertible to double" && false );
|
||||
JSON_ASSERT_MESSAGE( false, "Type is not convertible to string" );
|
||||
default:
|
||||
JSON_ASSERT_UNREACHABLE;
|
||||
}
|
||||
@ -705,17 +706,17 @@ Value::asInt() const
|
||||
case intValue:
|
||||
return value_.int_;
|
||||
case uintValue:
|
||||
JSON_ASSERT( value_.uint_ < maxInt && "integer out of signed integer range" );
|
||||
JSON_ASSERT_MESSAGE( value_.uint_ < (unsigned)maxInt, "integer out of signed integer range" );
|
||||
return value_.uint_;
|
||||
case realValue:
|
||||
JSON_ASSERT( value_.real_ >= minInt && value_.real_ <= maxInt && "Real out of signed integer range" );
|
||||
JSON_ASSERT_MESSAGE( value_.real_ >= minInt && value_.real_ <= maxInt, "Real out of signed integer range" );
|
||||
return Int( value_.real_ );
|
||||
case booleanValue:
|
||||
return value_.bool_ ? 1 : 0;
|
||||
case stringValue:
|
||||
case arrayValue:
|
||||
case objectValue:
|
||||
JSON_ASSERT( "Type is not convertible to double" && false );
|
||||
JSON_ASSERT_MESSAGE( false, "Type is not convertible to int" );
|
||||
default:
|
||||
JSON_ASSERT_UNREACHABLE;
|
||||
}
|
||||
@ -730,19 +731,19 @@ Value::asUInt() const
|
||||
case nullValue:
|
||||
return 0;
|
||||
case intValue:
|
||||
JSON_ASSERT( value_.int_ >= 0 && "Negative integer can not be converted to unsigned integer" );
|
||||
JSON_ASSERT_MESSAGE( value_.int_ >= 0, "Negative integer can not be converted to unsigned integer" );
|
||||
return value_.int_;
|
||||
case uintValue:
|
||||
return value_.uint_;
|
||||
case realValue:
|
||||
JSON_ASSERT( value_.real_ >= 0 && value_.real_ <= maxUInt && "Real out of unsigned integer range" );
|
||||
JSON_ASSERT_MESSAGE( value_.real_ >= 0 && value_.real_ <= maxUInt, "Real out of unsigned integer range" );
|
||||
return UInt( value_.real_ );
|
||||
case booleanValue:
|
||||
return value_.bool_ ? 1 : 0;
|
||||
case stringValue:
|
||||
case arrayValue:
|
||||
case objectValue:
|
||||
JSON_ASSERT( "Type is not convertible to double" && false );
|
||||
JSON_ASSERT_MESSAGE( false, "Type is not convertible to uint" );
|
||||
default:
|
||||
JSON_ASSERT_UNREACHABLE;
|
||||
}
|
||||
@ -767,7 +768,7 @@ Value::asDouble() const
|
||||
case stringValue:
|
||||
case arrayValue:
|
||||
case objectValue:
|
||||
JSON_ASSERT( "Type is not convertible to double" && false );
|
||||
JSON_ASSERT_MESSAGE( false, "Type is not convertible to double" );
|
||||
default:
|
||||
JSON_ASSERT_UNREACHABLE;
|
||||
}
|
||||
@ -816,7 +817,7 @@ Value::isConvertibleTo( ValueType other ) const
|
||||
|| other == booleanValue;
|
||||
case uintValue:
|
||||
return ( other == nullValue && value_.uint_ == 0 )
|
||||
|| ( other == intValue && value_.uint_ <= maxInt )
|
||||
|| ( other == intValue && value_.uint_ <= (unsigned)maxInt )
|
||||
|| other == uintValue
|
||||
|| other == realValue
|
||||
|| other == stringValue
|
||||
@ -1499,22 +1500,22 @@ PathArgument::PathArgument()
|
||||
|
||||
|
||||
PathArgument::PathArgument( Value::UInt index )
|
||||
: kind_( kindIndex )
|
||||
, index_( index )
|
||||
: index_( index )
|
||||
, kind_( kindIndex )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PathArgument::PathArgument( const char *key )
|
||||
: kind_( kindKey )
|
||||
, key_( key )
|
||||
: key_( key )
|
||||
, kind_( kindKey )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
PathArgument::PathArgument( const std::string &key )
|
||||
: kind_( kindKey )
|
||||
, key_( key.c_str() )
|
||||
: key_( key.c_str() )
|
||||
, kind_( kindKey )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ StyledWriter::writeValue( const Value &value )
|
||||
void
|
||||
StyledWriter::writeArrayValue( const Value &value )
|
||||
{
|
||||
int size = value.size();
|
||||
unsigned size = value.size();
|
||||
if ( size == 0 )
|
||||
pushValue( "[]" );
|
||||
else
|
||||
@ -301,7 +301,7 @@ StyledWriter::writeArrayValue( const Value &value )
|
||||
writeWithIndent( "[" );
|
||||
indent();
|
||||
bool hasChildValue = !childValues_.empty();
|
||||
int index =0;
|
||||
unsigned index =0;
|
||||
while ( true )
|
||||
{
|
||||
const Value &childValue = value[index];
|
||||
@ -328,7 +328,7 @@ StyledWriter::writeArrayValue( const Value &value )
|
||||
{
|
||||
assert( childValues_.size() == size );
|
||||
document_ += "[ ";
|
||||
for ( int index =0; index < size; ++index )
|
||||
for ( unsigned index =0; index < size; ++index )
|
||||
{
|
||||
if ( index > 0 )
|
||||
document_ += ", ";
|
||||
|
Loading…
Reference in New Issue
Block a user