Major rework of 64 integer support: 64 bits integer are only returned when explicitly request via Json::Value::asInt64(), unlike previous implementation where Json::Value::asInt() returned a 64 bits integer.
This eases porting portable code and does not break compatibility with the previous release.
Json::Value::asLargestInt() has also be added to ease writing portable code independent of 64 bits integer support. It is typically used to implement writers.
diff --git a/include/json/config.h b/include/json/config.h
index 3fe08f2..55f0583 100644
--- a/include/json/config.h
+++ b/include/json/config.h
@@ -46,7 +46,7 @@
# endif
// If JSON_NO_INT64 is defined, then Json only support C++ "int" type for integer
-// Storages.
+// Storages, and 64 bits integer support is disabled.
// #define JSON_NO_INT64 1
#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC 6
@@ -57,18 +57,24 @@
namespace Json {
-# if defined(JSON_NO_INT64)
typedef int Int;
typedef unsigned int UInt;
+# if defined(JSON_NO_INT64)
+ typedef int LargestInt;
+ typedef unsigned int LargestUInt;
+# undef JSON_HAS_INT64
# 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;
+ typedef __int64 Int64;
+ typedef unsigned __int64 UInt64;
# else // if defined(_MSC_VER) // Other platforms, use long long
- typedef long long int Int;
- typedef unsigned long long int UInt;
+ typedef long long int Int64;
+ typedef unsigned long long int UInt64;
# endif // if defined(_MSC_VER)
+ typedef Int64 LargestInt;
+ typedef UInt64 LargestUInt;
+# define JSON_HAS_INT64
# endif // if defined(JSON_NO_INT64)
} // end namespace Json
diff --git a/include/json/value.h b/include/json/value.h
index 8d0d4c1..14464e4 100644
--- a/include/json/value.h
+++ b/include/json/value.h
@@ -126,13 +126,36 @@
typedef ValueConstIterator const_iterator;
typedef Json::UInt UInt;
typedef Json::Int Int;
+# if defined(JSON_HAS_INT64)
+ typedef Json::UInt64 UInt64;
+ typedef Json::Int64 Int64;
+#endif // defined(JSON_HAS_INT64)
+ typedef Json::LargestInt LargestInt;
+ typedef Json::LargestUInt LargestUInt;
typedef Json::ArrayIndex ArrayIndex;
static const Value null;
- static const Int minInt;
+ /// Minimum signed integer value that can be stored in a Json::Value.
+ static const LargestInt minLargestInt;
+ /// Maximum signed integer value that can be stored in a Json::Value.
+ static const LargestInt maxLargestInt;
+ /// Maximum unsigned integer value that can be stored in a Json::Value.
+ static const LargestUInt maxLargestUInt;
+
+ /// Minimum signed int value that can be stored in a Json::Value.
+ static const Int minInt;
+ /// Maximum signed int value that can be stored in a Json::Value.
static const Int maxInt;
+ /// Maximum unsigned int value that can be stored in a Json::Value.
static const UInt maxUInt;
+ /// Minimum signed 64 bits int value that can be stored in a Json::Value.
+ static const Int64 minInt64;
+ /// Maximum signed 64 bits int value that can be stored in a Json::Value.
+ static const Int64 maxInt64;
+ /// Maximum unsigned 64 bits int value that can be stored in a Json::Value.
+ static const UInt64 maxUInt64;
+
private:
#ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
# ifndef JSON_VALUE_USE_INTERNAL_MAP
@@ -187,12 +210,12 @@
\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 );
+#if defined(JSON_HAS_INT64)
+ Value( Int64 value );
+ Value( UInt64 value );
+#endif // if defined(JSON_HAS_INT64)
Value( double value );
Value( const char *value );
Value( const char *beginValue, const char *endValue );
@@ -240,6 +263,10 @@
# endif
Int asInt() const;
UInt asUInt() const;
+ Int64 asInt64() const;
+ UInt64 asUInt64() const;
+ LargestInt asLargestInt() const;
+ LargestUInt asLargestUInt() const;
float asFloat() const;
double asDouble() const;
bool asBool() const;
@@ -448,8 +475,8 @@
union ValueHolder
{
- Int int_;
- UInt uint_;
+ LargestInt int_;
+ LargestUInt uint_;
double real_;
bool bool_;
char *string_;
diff --git a/include/json/writer.h b/include/json/writer.h
index 4d74f93..2ee13de 100644
--- a/include/json/writer.h
+++ b/include/json/writer.h
@@ -162,8 +162,12 @@
bool addChildValues_;
};
+# if defined(JSON_HAS_INT64)
std::string JSON_API valueToString( Int value );
std::string JSON_API valueToString( UInt value );
+# endif // if defined(JSON_HAS_INT64)
+ std::string JSON_API valueToString( LargestInt value );
+ std::string JSON_API valueToString( LargestUInt value );
std::string JSON_API valueToString( double value );
std::string JSON_API valueToString( bool value );
std::string JSON_API valueToQuotedString( const char *value );