Skip to content

Commit

Permalink
- added Int/UInt typedef in Json namespace. Modified Value::Int and V…
Browse files Browse the repository at this point in the history
…alue::UInt to be typedef on those. Modified code to use Json::Int instead of Value::Int.

- added Value constructor taking begin/end pointer to initialize the Value with a non-zero terminated string.


git-svn-id: https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/trunk/jsoncpp@95 1f120ed1-78a5-a849-adca-83f0a9e25bb6
  • Loading branch information
blep committed Feb 21, 2010
1 parent dff347e commit 232e179
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
7 changes: 6 additions & 1 deletion include/json/forwards.h
Expand Up @@ -5,14 +5,19 @@

namespace Json {

// writer.h
class FastWriter;
class Reader;
class StyledWriter;

// reader.h
class Reader;

// features.h
class Features;

// value.h
typedef int Int;
typedef unsigned int UInt;
class StaticString;
class Path;
class PathArgument;
Expand Down
11 changes: 6 additions & 5 deletions include/json/value.h
Expand Up @@ -117,10 +117,10 @@ namespace Json {
# endif
public:
typedef std::vector<std::string> Members;
typedef int Int;
typedef unsigned int UInt;
typedef ValueIterator iterator;
typedef ValueConstIterator const_iterator;
typedef Json::UInt UInt;
typedef Json::Int Int;
typedef UInt ArrayIndex;

static const Value null;
Expand Down Expand Up @@ -186,6 +186,7 @@ namespace Json {
Value( UInt value );
Value( double value );
Value( const char *value );
Value( const char *beginValue, const char *endValue );
/** \brief Constructs a value from a static string.
* Like other value string constructor but do not duplicate the string for
Expand Down Expand Up @@ -453,7 +454,7 @@ namespace Json {
friend class Path;

PathArgument();
PathArgument( Value::UInt index );
PathArgument( UInt index );
PathArgument( const char *key );
PathArgument( const std::string &key );

Expand All @@ -465,7 +466,7 @@ namespace Json {
kindKey
};
std::string key_;
Value::UInt index_;
UInt index_;
Kind kind_;
};

Expand Down Expand Up @@ -909,7 +910,7 @@ class DefaultValueArrayAllocator : public ValueArrayAllocator
Value key() const;

/// Return the index of the referenced Value. -1 if it is not an arrayValue.
Value::UInt index() const;
UInt index() const;

/// Return the member name of the referenced Value. "" if it is not an objectValue.
const char *memberName() const;
Expand Down
4 changes: 2 additions & 2 deletions include/json/writer.h
Expand Up @@ -157,8 +157,8 @@ namespace Json {
bool addChildValues_;
};

std::string JSON_API valueToString( Value::Int value );
std::string JSON_API valueToString( Value::UInt value );
std::string JSON_API valueToString( Int value );
std::string JSON_API valueToString( UInt value );
std::string JSON_API valueToString( double value );
std::string JSON_API valueToString( bool value );
std::string JSON_API valueToQuotedString( const char *value );
Expand Down
21 changes: 18 additions & 3 deletions src/lib_json/json_value.cpp
Expand Up @@ -20,9 +20,9 @@
namespace Json {

const Value Value::null;
const Value::Int Value::minInt = Value::Int( ~(Value::UInt(-1)/2) );
const Value::Int Value::maxInt = Value::Int( Value::UInt(-1)/2 );
const Value::UInt Value::maxUInt = Value::UInt(-1);
const Int Value::minInt = Int( ~(UInt(-1)/2) );
const Int Value::maxInt = Int( UInt(-1)/2 );
const UInt Value::maxUInt = UInt(-1);

// A "safe" implementation of strdup. Allow null pointer to be passed.
// Also avoid warning on msvc80.
Expand Down Expand Up @@ -351,6 +351,21 @@ Value::Value( const char *value )
value_.string_ = valueAllocator()->duplicateStringValue( value );
}


Value::Value( const char *beginValue,
const char *endValue )
: type_( stringValue )
, allocated_( true )
, comments_( 0 )
# ifdef JSON_VALUE_USE_INTERNAL_MAP
, itemIsUsed_( 0 )
#endif
{
value_.string_ = valueAllocator()->duplicateStringValue( beginValue,
UInt(endValue - beginValue) );
}


Value::Value( const std::string &value )
: type_( stringValue )
, allocated_( true )
Expand Down
2 changes: 1 addition & 1 deletion src/lib_json/json_valueiterator.inl
Expand Up @@ -176,7 +176,7 @@ ValueIteratorBase::key() const
}


Value::UInt
UInt
ValueIteratorBase::index() const
{
#ifndef JSON_VALUE_USE_INTERNAL_MAP
Expand Down
6 changes: 3 additions & 3 deletions src/lib_json/json_writer.cpp
Expand Up @@ -39,22 +39,22 @@ static void uintToString( unsigned int value,
while ( value != 0 );
}

std::string valueToString( Value::Int value )
std::string valueToString( Int value )
{
char buffer[32];
char *current = buffer + sizeof(buffer);
bool isNegative = value < 0;
if ( isNegative )
value = -value;
uintToString( Value::UInt(value), current );
uintToString( UInt(value), current );
if ( isNegative )
*--current = '-';
assert( current >= buffer );
return current;
}


std::string valueToString( Value::UInt value )
std::string valueToString( UInt value )
{
char buffer[32];
char *current = buffer + sizeof(buffer);
Expand Down

0 comments on commit 232e179

Please sign in to comment.