From: Baptiste L. <bl...@us...> - 2005-10-31 17:30:35
|
Update of /cvsroot/jsoncpp/jsoncpp/src/lib_json In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7828/src/lib_json Modified Files: json_value.cpp Log Message: * added optional support for CppTL library enumerator and ConstString. Index: json_value.cpp =================================================================== RCS file: /cvsroot/jsoncpp/jsoncpp/src/lib_json/json_value.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** json_value.cpp 30 Jul 2005 17:40:59 -0000 1.5 --- json_value.cpp 31 Oct 2005 17:30:10 -0000 1.6 *************** *** 1,5 **** --- 1,10 ---- #include <json/json_value.h> + #include <json/json_writer.h> #include <utility> #include "assert.h" + #ifdef JSON_USE_CPPTL + # include <cpptl/conststring.h> + # include <cpptl/enumerator.h> + #endif #define JSON_ASSERT_UNREACHABLE assert( false ) *************** *** 178,182 **** --- 183,196 ---- { value_.string_ = value.empty() ? 0 : strdup( value.c_str() ); + } + # ifdef JSON_USE_CPPTL + Value::Value( const CppTL::ConstString &value ) + : type_( stringValue ) + , comments_( 0 ) + { + value_.string_ = value.empty() ? 0 : strdup( value.c_str() ); + } + # endif Value::Value( bool value ) *************** *** 366,370 **** { case nullValue: ! return false; case intValue: return value_.int_ == other.value_.int_; --- 380,384 ---- { case nullValue: ! return true; case intValue: return value_.int_ == other.value_.int_; *************** *** 427,430 **** --- 441,452 ---- } + # ifdef JSON_USE_CPPTL + CppTL::ConstString + Value::asConstString() const + { + return CppTL::ConstString( asString().c_str() ); + } + # endif + Value::Int Value::asInt() const *************** *** 532,535 **** --- 554,608 ---- + bool + Value::isConvertibleTo( ValueType other ) const + { + switch ( type_ ) + { + case nullValue: + return true; + case intValue: + return ( other == nullValue && value_.int_ == 0 ) + || other == intValue + || ( other == uintValue && value_.int_ >= 0 ) + || other == realValue + || other == stringValue + || other == booleanValue; + case uintValue: + return ( other == nullValue && value_.uint_ == 0 ) + || ( other == intValue && value_.uint_ <= maxInt ) + || other == uintValue + || other == realValue + || other == stringValue + || other == booleanValue; + case realValue: + return ( other == nullValue && value_.real_ == 0.0 ) + || ( other == intValue && value_.real_ >= minInt && value_.real_ <= maxInt ) + || ( other == uintValue && value_.real_ >= 0 && value_.real_ <= maxUInt ) + || other == realValue + || other == stringValue + || other == booleanValue; + case booleanValue: + return ( other == nullValue && value_.bool_ == false ) + || other == intValue + || other == uintValue + || other == realValue + || other == stringValue + || other == booleanValue; + case stringValue: + return other == stringValue + || ( other == nullValue && (!value_.string_ || value_.string_[0] == 0) ); + case arrayValue: + return other == arrayValue + || ( other == nullValue && value_.map_->size() == 0 ); + case objectValue: + return other == objectValue + || ( other == nullValue && value_.map_->size() == 0 ); + default: + JSON_ASSERT_UNREACHABLE; + } + return false; // unreachable; + } + + /// Number of values in array or object Value::UInt *************** *** 691,694 **** --- 764,790 ---- + # ifdef JSON_USE_CPPTL + Value & + Value::operator[]( const CppTL::ConstString &key ) + { + return (*this)[ key.c_str() ]; + } + + + const Value & + Value::operator[]( const CppTL::ConstString &key ) const + { + return (*this)[ key.c_str() ]; + } + # endif + + + Value & + Value::append( const Value &value ) + { + return (*this)[size()] = value; + } + + Value Value::get( const char *key, *************** *** 708,711 **** --- 804,816 ---- + # ifdef JSON_USE_CPPTL + Value + Value::get( const CppTL::ConstString &key, + const Value &defaultValue ) const + { + return get( key.c_str(), defaultValue ); + } + # endif + bool Value::isMember( const char *key ) const *************** *** 723,726 **** --- 828,839 ---- + # ifdef JSON_USE_CPPTL + bool + Value::isMember( const CppTL::ConstString &key ) const + { + return isMember( key.c_str() ); + } + #endif + Value::Members Value::getMemberNames() const *************** *** 736,739 **** --- 849,877 ---- } + # ifdef JSON_USE_CPPTL + EnumMemberNames + Value::enumMemberNames() const + { + if ( type_ == objectValue ) + { + return CppTL::Enum::any( CppTL::Enum::transform( + CppTL::Enum::keys( *(value_.map_), CppTL::Type<const CZString &>() ), + MemberNamesTransform() ) ); + } + return EnumMemberNames(); + } + + + EnumValues + Value::enumValues() const + { + if ( type_ == objectValue || type_ == arrayValue ) + return CppTL::Enum::anyValues( *(value_.map_), + CppTL::Type<const Value &>() ); + return EnumValues(); + } + + # endif + bool *************** *** 835,838 **** --- 973,984 ---- + std::string + Value::toStyledString() const + { + StyledWriter writer; + return writer.write( *this ); + } + + // class PathArgument // ////////////////////////////////////////////////////////////////// |