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