[Cppunit-cvs] cppunit2/src/cpptl json_reader.cpp, 1.2, 1.3 json_value.cpp, 1.2, 1.3
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2006-06-06 03:31:52
|
Update of /cvsroot/cppunit/cppunit2/src/cpptl In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv26100/src/cpptl Modified Files: json_reader.cpp json_value.cpp Log Message: - synchronized with lastest jsoncpp. Index: json_value.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpptl/json_value.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** json_value.cpp 9 Nov 2005 23:16:05 -0000 1.2 --- json_value.cpp 5 Jun 2006 13:22:58 -0000 1.3 *************** *** 7,13 **** --- 7,15 ---- # include <cpptl/enumerator.h> #endif + #include <stddef.h> // size_t #define JSON_ASSERT_UNREACHABLE assert( false ) #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 namespace Json { *************** *** 18,21 **** --- 20,187 ---- const Value::UInt Value::maxUInt = Value::UInt(-1); + // A "safe" implementation of strdup. Allow null pointer to be passed. + // Also avoid warning on msvc80. + + inline char *safeStringDup( const char *czstring ) + { + if ( czstring ) + { + const size_t length = (unsigned int)( strlen(czstring) + 1 ); + char *newString = static_cast<char *>( malloc( length ) ); + memcpy( newString, czstring, length ); + return newString; + } + return 0; + } + + inline char *safeStringDup( const std::string &str ) + { + if ( !str.empty() ) + { + const size_t length = str.length(); + char *newString = static_cast<char *>( malloc( length + 1 ) ); + memcpy( newString, str.c_str(), length ); + newString[length] = 0; + return newString; + } + return 0; + } + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class ValueIteratorBase + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + ValueIteratorBase::ValueIteratorBase() + { + } + + + ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t ) + : current_( current ) + { + } + + + Value & + ValueIteratorBase::deref() const + { + return current_->second; + } + + + void + ValueIteratorBase::increment() + { + ++current_; + } + + + void + ValueIteratorBase::decrement() + { + --current_; + } + + + ValueIteratorBase::difference_type + ValueIteratorBase::computeDistance( const SelfType &other ) const + { + # ifdef JSON_USE_CPPTL_SMALLMAP + return current_ - other.current_; + # else + return difference_type( std::distance( current_, other.current_ ) ); + # endif + } + + + bool + ValueIteratorBase::isEqual( const SelfType &other ) const + { + return current_ == other.current_; + } + + + void + ValueIteratorBase::copy( const SelfType &other ) + { + current_ = other.current_; + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class ValueConstIterator + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + ValueConstIterator::ValueConstIterator() + { + } + + + ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator ¤t ) + : ValueIteratorBase( current ) + { + } + + ValueConstIterator & + ValueConstIterator::operator =( const ValueIteratorBase &other ) + { + copy( other ); + return *this; + } + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class ValueIterator + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + ValueIterator::ValueIterator() + { + } + + + ValueIterator::ValueIterator( const Value::ObjectValues::iterator ¤t ) + : ValueIteratorBase( current ) + { + } + + ValueIterator::ValueIterator( const ValueConstIterator &other ) + : ValueIteratorBase( other ) + { + } + + ValueIterator::ValueIterator( const ValueIterator &other ) + : ValueIteratorBase( other ) + { + } + + ValueIterator & + ValueIterator::operator =( const SelfType &other ) + { + copy( other ); + return *this; + } + + + + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class Value::CommentInfo + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + Value::CommentInfo::CommentInfo() *************** *** 36,43 **** if ( comment_ ) free( comment_ ); ! comment_ = text ? strdup( text ) : 0; } // Notes: index_ indicates if the string was allocated when --- 202,216 ---- if ( comment_ ) free( comment_ ); ! comment_ = safeStringDup( text ); } + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class Value::CZString + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// // Notes: index_ indicates if the string was allocated when *************** *** 51,55 **** Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) ! : cstr_( allocate == duplicate ? strdup(cstr) : cstr ) , index_( allocate ) { --- 224,228 ---- Value::CZString::CZString( const char *cstr, DuplicationPolicy allocate ) ! : cstr_( allocate == duplicate ? safeStringDup(cstr) : cstr ) , index_( allocate ) { *************** *** 57,61 **** Value::CZString::CZString( const CZString &other ) ! : cstr_( other.index_ != noDuplication && other.cstr_ != 0 ? strdup( other.cstr_ ) : other.cstr_ ) , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) --- 230,234 ---- Value::CZString::CZString( const CZString &other ) ! : cstr_( other.index_ != noDuplication && other.cstr_ != 0 ? safeStringDup( other.cstr_ ) : other.cstr_ ) , index_( other.cstr_ ? (other.index_ == noDuplication ? noDuplication : duplicate) *************** *** 66,70 **** Value::CZString::~CZString() { ! if ( index_ == duplicate ) free( const_cast<char *>( cstr_ ) ); } --- 239,243 ---- Value::CZString::~CZString() { ! if ( cstr_ && index_ == duplicate ) free( const_cast<char *>( cstr_ ) ); } *************** *** 116,119 **** --- 289,299 ---- + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // class Value::Value + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// *************** *** 121,124 **** --- 301,305 ---- : type_( type ) , comments_( 0 ) + , allocated_( 0 ) { switch ( type ) *************** *** 173,186 **** Value::Value( const char *value ) : type_( stringValue ) , comments_( 0 ) { ! value_.string_ = value ? strdup( value ) : 0; } Value::Value( const std::string &value ) : type_( stringValue ) , comments_( 0 ) { ! value_.string_ = value.empty() ? 0 : strdup( value.c_str() ); } --- 354,369 ---- Value::Value( const char *value ) : type_( stringValue ) + , allocated_( true ) , comments_( 0 ) { ! value_.string_ = safeStringDup( value ); } Value::Value( const std::string &value ) : type_( stringValue ) + , allocated_( true ) , comments_( 0 ) { ! value_.string_ = safeStringDup( value ); } *************** *** 188,194 **** Value::Value( const CppTL::ConstString &value ) : type_( stringValue ) , comments_( 0 ) { ! value_.string_ = value.empty() ? 0 : strdup( value.c_str() ); } # endif --- 371,378 ---- Value::Value( const CppTL::ConstString &value ) : type_( stringValue ) + , allocated_( true ) , comments_( 0 ) { ! value_.string_ = safeStringDup( value ); } # endif *************** *** 217,221 **** case stringValue: if ( other.value_.string_ ) ! value_.string_ = strdup( other.value_.string_ ); else value_.string_ = 0; --- 401,408 ---- case stringValue: if ( other.value_.string_ ) ! { ! value_.string_ = safeStringDup( other.value_.string_ ); ! allocated_ = true; ! } else value_.string_ = 0; *************** *** 253,257 **** break; case stringValue: ! free( value_.string_ ); break; case arrayValue: --- 440,445 ---- break; case stringValue: ! if ( allocated_ ) ! free( value_.string_ ); break; case arrayValue: *************** *** 278,283 **** Value::swap( Value &other ) { ! std::swap( type_, other.type_ ); std::swap( value_, other.value_ ); } --- 466,476 ---- Value::swap( Value &other ) { ! ValueType temp = type_; ! type_ = other.type_; ! other.type_ = temp; std::swap( value_, other.value_ ); + bool temp2 = allocated_; + allocated_ = other.allocated_; + other.allocated_ = temp2; } *************** *** 984,987 **** --- 1177,1242 ---- + Value::const_iterator + Value::begin() const + { + switch ( type_ ) + { + case arrayValue: + case objectValue: + if ( value_.map_ ) + return const_iterator( value_.map_->begin() ); + // fall through default if no valid map + default: + return const_iterator(); + } + } + + Value::const_iterator + Value::end() const + { + switch ( type_ ) + { + case arrayValue: + case objectValue: + if ( value_.map_ ) + return const_iterator( value_.map_->end() ); + // fall through default if no valid map + default: + return const_iterator(); + } + } + + + Value::iterator + Value::begin() + { + switch ( type_ ) + { + case arrayValue: + case objectValue: + if ( value_.map_ ) + return iterator( value_.map_->begin() ); + // fall through default if no valid map + default: + return iterator(); + } + } + + Value::iterator + Value::end() + { + switch ( type_ ) + { + case arrayValue: + case objectValue: + if ( value_.map_ ) + return iterator( value_.map_->end() ); + // fall through default if no valid map + default: + return iterator(); + } + } + + // class PathArgument // ////////////////////////////////////////////////////////////////// Index: json_reader.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpptl/json_reader.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** json_reader.cpp 1 Feb 2006 18:26:16 -0000 1.2 --- json_reader.cpp 5 Jun 2006 13:22:58 -0000 1.3 *************** *** 47,54 **** bool collectComments ) { - collectComments_ = collectComments; document_ = document; ! begin_ = document_.c_str(); ! end_ = begin_ + document_.length(); current_ = begin_; lastValueEnd_ = 0; --- 47,64 ---- bool collectComments ) { document_ = document; ! const char *begin = document_.c_str(); ! const char *end = begin + document_.length(); ! return parse( begin, end, root, collectComments ); ! } ! ! bool ! Reader::parse( const char *beginDoc, const char *endDoc, ! Value &root, ! bool collectComments ) ! { ! begin_ = beginDoc; ! end_ = endDoc; ! collectComments_ = collectComments; current_ = begin_; lastValueEnd_ = 0; |