- Moved definition of Json::Int and Json::UInt to config.h which compiler detection logic to define them to 64 bits integer if JSON_NO_INT64 is not defined.

- Added Json::ArrayIndex as an unsigned int to forwards.h
- Modified Json::Value to consistently use Json::ArrayIndex.
- Added int/unsigned int constructor overload to Json::Value to avoid ambiguous constructor call.
- Modified jsontestrunner/main.cpp to use Json::valueToString for Value::asInt() conversion to string.
- Modified Json::Reader to only overflow to double when the number is too large (previous code relied on the fact that an int fitted in a double without precision loss).
- Generalized uintToString() helpers and buffer size to automatically adapt to the precision of Json::UInt.
- Added specific conversion logic for UInt to double conversion on Microsoft Visual Studio 6 which only support __int64 to double conversion (unsigned __int64 conversion is not supported)
- Added test for 64 bits parsing/writing. Notes: those will fail when compiled with JSON_NO_INT64 (more dev required to adapt).
This commit is contained in:
Baptiste Lepilleur
2010-04-19 07:37:41 +00:00
parent 377d21e145
commit 201fb2cf0d
15 changed files with 170 additions and 43 deletions

View File

@@ -40,4 +40,32 @@
# define JSON_API
# endif
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
// Storages.
// #define JSON_NO_INT64 1
#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
// Microsoft Visual Studio 6 only support conversion from __int64 to double
// (no conversion from unsigned __int64).
#define JSON_USE_INT64_DOUBLE_CONVERSION 1
#endif // if defined(_MSC_VER) && _MSC_VER < 1200 // MSVC 6
namespace Json {
# if defined(JSON_NO_INT64)
typedef int Int;
typedef unsigned int UInt;
# else // if defined(JSON_NO_INT64)
// For Microsoft Visual use specific types as long long is not supported
# if defined(_MSC_VER) // Microsoft Visual Studio
typedef __int64 Int;
typedef unsigned __int64 UInt;
# else // if defined(_MSC_VER) // Other platforms, use long long
typedef long long int Int;
typedef unsigned long long int UInt;
# endif // if defined(_MSC_VER)
# endif // if defined(JSON_NO_INT64)
} // end namespace Json
#endif // JSON_CONFIG_H_INCLUDED

View File

@@ -16,8 +16,7 @@ namespace Json {
class Features;
// value.h
typedef int Int;
typedef unsigned int UInt;
typedef unsigned int ArrayIndex;
class StaticString;
class Path;
class PathArgument;

View File

@@ -121,7 +121,7 @@ namespace Json {
typedef ValueConstIterator const_iterator;
typedef Json::UInt UInt;
typedef Json::Int Int;
typedef UInt ArrayIndex;
typedef Json::ArrayIndex ArrayIndex;
static const Value null;
static const Int minInt;
@@ -140,20 +140,20 @@ namespace Json {
duplicate,
duplicateOnCopy
};
CZString( int index );
CZString( ArrayIndex index );
CZString( const char *cstr, DuplicationPolicy allocate );
CZString( const CZString &other );
~CZString();
CZString &operator =( const CZString &other );
bool operator<( const CZString &other ) const;
bool operator==( const CZString &other ) const;
int index() const;
ArrayIndex index() const;
const char *c_str() const;
bool isStaticString() const;
private:
void swap( CZString &other );
const char *cstr_;
int index_;
ArrayIndex index_;
};
public:
@@ -182,6 +182,10 @@ namespace Json {
\endcode
*/
Value( ValueType type = nullValue );
#if !defined(JSON_NO_INT64)
Value( int value );
Value( ArrayIndex value );
#endif // if !defined(JSON_NO_INT64)
Value( Int value );
Value( UInt value );
Value( double value );
@@ -248,7 +252,7 @@ namespace Json {
bool isConvertibleTo( ValueType other ) const;
/// Number of values in array or object
UInt size() const;
ArrayIndex size() const;
/// \brief Return true if empty array, empty object, or null;
/// otherwise, false.
@@ -267,24 +271,24 @@ namespace Json {
/// May only be called on nullValue or arrayValue.
/// \pre type() is arrayValue or nullValue
/// \post type() is arrayValue
void resize( UInt size );
void resize( ArrayIndex size );
/// Access an array element (zero based index ).
/// If the array contains less than index element, then null value are inserted
/// in the array so that its size is index+1.
/// (You may need to say 'value[0u]' to get your compiler to distinguish
/// this from the operator[] which takes a string.)
Value &operator[]( UInt index );
Value &operator[]( ArrayIndex index );
/// Access an array element (zero based index )
/// (You may need to say 'value[0u]' to get your compiler to distinguish
/// this from the operator[] which takes a string.)
const Value &operator[]( UInt index ) const;
const Value &operator[]( ArrayIndex index ) const;
/// If the array contains at least index+1 elements, returns the element value,
/// otherwise returns defaultValue.
Value get( UInt index,
Value get( ArrayIndex index,
const Value &defaultValue ) const;
/// Return true if index < size().
bool isValidIndex( UInt index ) const;
bool isValidIndex( ArrayIndex index ) const;
/// \brief Append value to array at the end.
///
/// Equivalent to jsonvalue[jsonvalue.size()] = value;
@@ -454,7 +458,7 @@ namespace Json {
friend class Path;
PathArgument();
PathArgument( UInt index );
PathArgument( ArrayIndex index );
PathArgument( const char *key );
PathArgument( const std::string &key );
@@ -466,7 +470,7 @@ namespace Json {
kindKey
};
std::string key_;
UInt index_;
ArrayIndex index_;
Kind kind_;
};