[Cppunit-cvs] cppunit2/include/json config.h, 1.1, 1.2 forwards.h, 1.1, 1.2 reader.h, 1.1, 1.2 valu
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2006-06-06 03:31:31
|
Update of /cvsroot/cppunit/cppunit2/include/json In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv26100/include/json Modified Files: config.h forwards.h reader.h value.h writer.h Log Message: - synchronized with lastest jsoncpp. Index: config.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/json/config.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** config.h 7 Nov 2005 22:43:07 -0000 1.1 --- config.h 5 Jun 2006 13:22:58 -0000 1.2 *************** *** 3,10 **** /// If defined, indicates that json library is embedded in CppTL library. ! # define JSON_IN_CPPTL 1 /// If defined, indicates that json may leverage CppTL library ! # define JSON_USE_CPPTL 1 --- 3,11 ---- /// If defined, indicates that json library is embedded in CppTL library. ! //# define JSON_IN_CPPTL 1 /// If defined, indicates that json may leverage CppTL library ! //# define JSON_USE_CPPTL 1 ! //# define JSON_USE_CPPTL_SMALLMAP 1 Index: value.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/json/value.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** value.h 7 Nov 2005 22:43:07 -0000 1.1 --- value.h 5 Jun 2006 13:22:58 -0000 1.2 *************** *** 4,10 **** # include "forwards.h" # include <string> - # include <map> # include <vector> # ifdef JSON_USE_CPPTL # include <cpptl/forwards.h> --- 4,14 ---- # include "forwards.h" # include <string> # include <vector> + # ifndef JSON_USE_CPPTL_SMALLMAP + # include <map> + # else + # include <cpptl/smallmap.h> + # endif # ifdef JSON_USE_CPPTL # include <cpptl/forwards.h> *************** *** 13,18 **** namespace Json { - class Value; - /** \brief Type of the value held by a Value object. */ --- 17,20 ---- *************** *** 75,78 **** --- 77,82 ---- typedef int Int; typedef unsigned int UInt; + typedef ValueIterator iterator; + typedef ValueConstIterator const_iterator; static const Value null; *************** *** 80,84 **** --- 84,121 ---- static const Int maxInt; static const UInt maxUInt; + private: + class CZString + { + public: + enum DuplicationPolicy + { + noDuplication = 0, + duplicate, + duplicateOnCopy + }; + CZString( int 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; + const char *c_str() const; + private: + void swap( CZString &other ); + const char *cstr_; + int index_; + }; + + public: + # ifndef JSON_USE_CPPTL_SMALLMAP + typedef std::map<CZString, Value> ObjectValues; + # else + typedef CppTL::SmallMap<CZString, Value> ObjectValues; + # endif + + public: Value( ValueType type = nullValue ); Value( Int value ); *************** *** 209,212 **** --- 246,255 ---- std::string toStyledString() const; + const_iterator begin() const; + const_iterator end() const; + + iterator begin(); + iterator end(); + private: struct CommentInfo *************** *** 220,248 **** }; - struct CZString - { - enum DuplicationPolicy - { - noDuplication = 0, - duplicate, - duplicateOnCopy - }; - CZString( int 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; - const char *c_str() const; - private: - void swap( CZString &other ); - const char *cstr_; - int index_; - }; - - typedef std::map<CZString, Value> ObjectValues; - struct MemberNamesTransform { --- 263,266 ---- *************** *** 263,271 **** ObjectValues *map_; } value_; ! ValueType type_; CommentInfo *comments_; }; /** \brief Experimental and untested: represents an element of the "path" to access a node. */ --- 281,440 ---- ObjectValues *map_; } value_; ! ValueType type_ : 8; ! bool allocated_ : 1; CommentInfo *comments_; }; + /** \brief Experimental and untested: base class for Value iterators. + * + */ + class ValueIteratorBase + { + public: + typedef unsigned int size_t; + typedef int difference_type; + typedef ValueIteratorBase SelfType; + + ValueIteratorBase(); + explicit ValueIteratorBase( const Value::ObjectValues::iterator ¤t ); + + bool operator ==( const SelfType &other ) const + { + return isEqual( other ); + } + + bool operator !=( const SelfType &other ) const + { + return !isEqual( other ); + } + + difference_type operator -( const SelfType &other ) const + { + return computeDistance( other ); + } + + protected: + Value &deref() const; + + void increment(); + + void decrement(); + + difference_type computeDistance( const SelfType &other ) const; + + bool isEqual( const SelfType &other ) const; + + void copy( const SelfType &other ); + + private: + Value::ObjectValues::iterator current_; + }; + + /** \brief Experimental and untested: const iterator for object and array value. + * + */ + class ValueConstIterator : public ValueIteratorBase + { + public: + typedef unsigned int size_t; + typedef int difference_type; + typedef const Value &reference; + typedef const Value *pointer; + typedef ValueConstIterator SelfType; + + ValueConstIterator(); + /*! \internal Use by Value to create an iterator. + */ + explicit ValueConstIterator( const Value::ObjectValues::iterator ¤t ); + SelfType &operator =( const ValueIteratorBase &other ); + + SelfType operator++( int ) + { + SelfType temp( *this ); + ++*this; + return temp; + } + + SelfType operator--( int ) + { + SelfType temp( *this ); + --*this; + return temp; + } + + SelfType &operator--() + { + decrement(); + return *this; + } + + SelfType &operator++() + { + increment(); + return *this; + } + + reference operator *() const + { + return deref(); + } + }; + + + /** \brief Experimental and untested: iterator for object and array value. + */ + class ValueIterator : public ValueIteratorBase + { + public: + typedef unsigned int size_t; + typedef int difference_type; + typedef Value &reference; + typedef Value *pointer; + typedef ValueIterator SelfType; + + ValueIterator(); + ValueIterator( const ValueConstIterator &other ); + ValueIterator( const ValueIterator &other ); + /*! \internal Use by Value to create an iterator. + */ + explicit ValueIterator( const Value::ObjectValues::iterator ¤t ); + + SelfType &operator =( const SelfType &other ); + + SelfType operator++( int ) + { + SelfType temp( *this ); + ++*this; + return temp; + } + + SelfType operator--( int ) + { + SelfType temp( *this ); + --*this; + return temp; + } + + SelfType &operator--() + { + decrement(); + return *this; + } + + SelfType &operator++() + { + increment(); + return *this; + } + + reference operator *() const + { + return deref(); + } + }; + + + /** \brief Experimental and untested: represents an element of the "path" to access a node. */ Index: forwards.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/json/forwards.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** forwards.h 7 Nov 2005 22:43:07 -0000 1.1 --- forwards.h 5 Jun 2006 13:22:58 -0000 1.2 *************** *** 7,15 **** class FastWriter; - class Path; - class PathArgument; class Reader; class StyledWriter; class Value; } // namespace Json --- 7,20 ---- class FastWriter; class Reader; class StyledWriter; + + // value.h + class Path; + class PathArgument; class Value; + class ValueIteratorBase; + class ValueIterator; + class ValueConstIterator; } // namespace Json Index: reader.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/json/reader.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** reader.h 7 Nov 2005 22:43:07 -0000 1.1 --- reader.h 5 Jun 2006 13:22:58 -0000 1.2 *************** *** 5,9 **** # include "value.h" # include <deque> - # include <map> # include <stack> # include <string> --- 5,8 ---- *************** *** 37,40 **** --- 36,51 ---- bool collectComments = true ); + /** \brief Read a Value from a <a HREF="http://www.json.org">JSON</a> document. + * \param document UTF-8 encoded string containing the document to read. + * \param root [out] Contains the root value of the document if it was + * successfully parsed. + * \param collectComments \c true to collect comment and allow writing them back during + * serialization, \c false to discard comments. + * \return \c true if the document was successfully parsed, \c false if an error occurred. + */ + bool parse( const char *beginDoc, const char *endDoc, + Value &root, + bool collectComments = true ); + /** \brief Returns a user friendly string that list errors in the parsed document. * \return Formatted error message with the list of errors with their location in Index: writer.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/json/writer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** writer.h 7 Nov 2005 22:43:07 -0000 1.1 --- writer.h 5 Jun 2006 13:22:58 -0000 1.2 *************** *** 3,7 **** # include "value.h" ! # include <deque> # include <string> --- 3,7 ---- # include "value.h" ! # include <vector> # include <string> |