RTBKit  0.9
Open-source framework to create real-time ad bidding systems.
soa/jsoncpp/value.h
00001 // Copyright 2007-2010 Baptiste Lepilleur
00002 // Distributed under MIT license, or public domain if desired and
00003 // recognized in your jurisdiction.
00004 // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
00005 #ifndef CPPTL_JSON_H_INCLUDED
00006 # define CPPTL_JSON_H_INCLUDED
00007 
00008 # include "forwards.h"
00009 # include <string>
00010 # include <vector>
00011 # include <boost/type_traits/is_integral.hpp>
00012 # include <boost/type_traits/is_signed.hpp>
00013 # include <boost/type_traits/is_unsigned.hpp>
00014 # include <boost/type_traits/is_convertible.hpp>
00015 # include <boost/utility/enable_if.hpp>
00016 
00017 # ifndef JSON_USE_CPPTL_SMALLMAP
00018 #  include <map>
00019 # else
00020 #  include <cpptl/smallmap.h>
00021 # endif
00022 # ifdef JSON_USE_CPPTL
00023 #  include <cpptl/forwards.h>
00024 # endif
00025 
00026 #include <stdexcept>
00027 #define JSON_ASSERT_UNREACHABLE throw std::runtime_error( "Json unreachable error" );
00028 #define JSON_ASSERT( condition ) if (!( condition )) throw std::runtime_error( "Json assertion error" );
00029 #define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message );
00030 namespace Datacratic{
00031     class Utf8String;
00032 }
00033 
00036 namespace Json {
00037 
00040    enum ValueType
00041    {
00042       nullValue = 0, 
00043       intValue,      
00044       uintValue,     
00045       realValue,     
00046       stringValue,   
00047       booleanValue,  
00048       arrayValue,    
00049       objectValue    
00050    };
00051 
00052    enum CommentPlacement
00053    {
00054       commentBefore = 0,        
00055       commentAfterOnSameLine,   
00056       commentAfter,             
00057       numberOfCommentPlacement
00058    };
00059 
00060 //# ifdef JSON_USE_CPPTL
00061 //   typedef CppTL::AnyEnumerator<const char *> EnumMemberNames;
00062 //   typedef CppTL::AnyEnumerator<const Value &> EnumValues;
00063 //# endif
00064 
00079    class JSON_API StaticString
00080    {
00081    public:
00082       explicit StaticString( const char *czstring )
00083          : str_( czstring )
00084       {
00085       }
00086 
00087       operator const char *() const
00088       {
00089          return str_;
00090       }
00091 
00092       const char *c_str() const
00093       {
00094          return str_;
00095       }
00096 
00097    private:
00098       const char *str_;
00099    };
00100 
00128    class JSON_API Value
00129    {
00130       friend class ValueIteratorBase;
00131 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00132       friend class ValueInternalLink;
00133       friend class ValueInternalMap;
00134 # endif
00135    public:
00136       typedef std::vector<std::string> Members;
00137       typedef ValueIterator iterator;
00138       typedef ValueConstIterator const_iterator;
00139       typedef Json::UInt UInt;
00140       typedef Json::Int Int;
00141       typedef UInt ArrayIndex;
00142 
00143       static const Value null;
00144       static const Int minInt;
00145       static const Int maxInt;
00146       static const UInt maxUInt;
00147 
00148    private:
00149 #ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00150 # ifndef JSON_VALUE_USE_INTERNAL_MAP
00151       class CZString
00152       {
00153       public:
00154          enum DuplicationPolicy
00155          {
00156             noDuplication = 0,
00157             duplicate,
00158             duplicateOnCopy
00159          };
00160          CZString( int index );
00161          CZString( const char *cstr, DuplicationPolicy allocate );
00162          CZString( const CZString &other );
00163          CZString( CZString && other);
00164          ~CZString();
00165          CZString &operator =( const CZString &other );
00166          CZString &operator =( CZString &&other );
00167          bool operator<( const CZString &other ) const;
00168          bool operator==( const CZString &other ) const;
00169          int index() const;
00170          const char *c_str() const;
00171          bool isStaticString() const;
00172       private:
00173          void swap( CZString &other );
00174          const char *cstr_;
00175          int index_;
00176       };
00177 
00178    public:
00179 #  ifndef JSON_USE_CPPTL_SMALLMAP
00180       typedef std::map<CZString, Value> ObjectValues;
00181 #  else
00182       typedef CppTL::SmallMap<CZString, Value> ObjectValues;
00183 #  endif // ifndef JSON_USE_CPPTL_SMALLMAP
00184 # endif // ifndef JSON_VALUE_USE_INTERNAL_MAP
00185 #endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00186 
00187    public:
00203       Value( ValueType type = nullValue );
00204 
00205       template<typename T>
00206       Value(const T & t, typename boost::enable_if<typename boost::is_integral<T>::type>::type * = 0)
00207           : comments_( 0 )
00208       {
00209           setIntegral(t);
00210       }
00211 
00212       template<typename T>
00213       void setIntegral(T t, typename boost::enable_if<typename boost::is_unsigned<T>::type>::type * = 0)
00214       {
00215           type_ = uintValue;
00216           value_.uint_ = t;
00217       }
00218 
00219       template<typename T>
00220       void setIntegral(T t, typename boost::enable_if<typename boost::is_signed<T>::type>::type * = 0)
00221       {
00222           type_ = intValue;
00223           value_.int_ = t;
00224       }
00225 
00226       Value( double value );
00227       Value( const char *value );
00228       Value( const char *beginValue, const char *endValue );
00239       Value( const StaticString &value );
00240       Value( const std::string &value );
00241       Value( const Datacratic::Utf8String &value );
00242 # ifdef JSON_USE_CPPTL
00243       Value( const CppTL::ConstString &value );
00244 # endif
00245       Value( bool value );
00246       Value( const Value &other );
00247       Value( Value &&other );
00248       ~Value();
00249 
00250       Value &operator=( const Value &other );
00251       Value &operator=( Value &&other );
00255       void swap( Value &other );
00256 
00257       ValueType type() const;
00258 
00259       bool operator <( const Value &other ) const;
00260       bool operator <=( const Value &other ) const;
00261       bool operator >=( const Value &other ) const;
00262       bool operator >( const Value &other ) const;
00263 
00264       bool operator ==( const Value &other ) const;
00265       bool operator !=( const Value &other ) const;
00266 
00267       int compare( const Value &other );
00268 
00269       const char *asCString() const;
00270       std::string asString() const;
00271 # ifdef JSON_USE_CPPTL
00272       CppTL::ConstString asConstString() const;
00273 # endif
00274       Int asInt() const;
00275       UInt asUInt() const;
00276       double asDouble() const;
00277       bool asBool() const;
00278 
00279       bool isNull() const;
00280       bool isBool() const;
00281       bool isInt() const;
00282       bool isUInt() const;
00283       bool isIntegral() const;
00284       bool isDouble() const;
00285       bool isNumeric() const;
00286       bool isString() const;
00287       bool isArray() const;
00288       bool isObject() const;
00289 
00290       bool isConvertibleTo( ValueType other ) const;
00291 
00293       UInt size() const;
00294 
00297       bool empty() const;
00298 
00300       bool operator!() const;
00301 
00305       void clear();
00306 
00312       void resize( UInt size );
00313 
00314       template<typename T,
00315            bool I = boost::is_integral<T>::value,
00316            bool S = boost::is_convertible<T, std::string>::value>
00317       struct doIndex {
00318       };
00319 
00320       template<typename T>
00321       struct doIndex<T, true, false> {
00322           typedef Value R;
00323           static Value & get(Value * obj, int index)
00324           {
00325               return obj->atIndex(index);
00326           }
00327 
00328           static const Value & get(const Value * obj, int index)
00329           {
00330               return obj->atIndex(index);
00331           }
00332       };
00333 
00334       template<typename T>
00335       struct doIndex<T, false, true> {
00336           typedef Value R;
00337           static Value & get(Value * obj, const T & index)
00338           {
00339               return obj->atStr(index);
00340           }
00341 
00342           static const Value & get(const Value * obj, const T & index)
00343           {
00344               return obj->atStr(index);
00345           }
00346       };
00347 
00353       template<typename T>
00354       typename doIndex<T>::R & operator[]( const T & index )
00355       {
00356           return doIndex<T>::get(this, index);
00357       }
00358 
00359       template<typename T>
00360       const typename doIndex<T>::R & operator[]( const T & index ) const
00361       {
00362           return doIndex<T>::get(this, index);
00363       }
00364 
00366       Value & atIndex( UInt index );
00370       const Value & atIndex( UInt index ) const;
00372 
00373 
00375       Value get( UInt index,
00376                  const Value &defaultValue ) const;
00378       bool isValidIndex( UInt index ) const;
00382       Value &append( const Value &value );
00383 
00385       Value &atStr( const char *key );
00387       const Value &atStr( const char *key ) const;
00389       Value &atStr( const std::string &key );
00391       const Value &atStr( const std::string &key ) const;
00402       Value &atStr( const StaticString &key );
00403 # ifdef JSON_USE_CPPTL
00404 
00405       Value &atStr( const CppTL::ConstString &key );
00407       const Value &atStr( const CppTL::ConstString &key ) const;
00408 # endif
00409 
00411       Value get( const char *key,
00412                  const Value &defaultValue ) const;
00414       Value get( const std::string &key,
00415                  const Value &defaultValue ) const;
00416 # ifdef JSON_USE_CPPTL
00417 
00418       Value get( const CppTL::ConstString &key,
00419                  const Value &defaultValue ) const;
00420 # endif
00421 
00422 
00423 
00424 
00425 
00426 
00427       Value removeMember( const char* key );
00429       Value removeMember( const std::string &key );
00430 
00432       bool isMember( const char *key ) const;
00434       bool isMember( const std::string &key ) const;
00435 # ifdef JSON_USE_CPPTL
00436 
00437       bool isMember( const CppTL::ConstString &key ) const;
00438 # endif
00439 
00445       Members getMemberNames() const;
00446 
00447 //# ifdef JSON_USE_CPPTL
00448 //      EnumMemberNames enumMemberNames() const;
00449 //      EnumValues enumValues() const;
00450 //# endif
00451 
00453       void setComment( const char *comment,
00454                        CommentPlacement placement );
00456       void setComment( const std::string &comment,
00457                        CommentPlacement placement );
00458       bool hasComment( CommentPlacement placement ) const;
00460       std::string getComment( CommentPlacement placement ) const;
00461 
00462       std::string toStyledString() const;
00463       std::string toString() const;
00464 
00465       const_iterator begin() const;
00466       const_iterator end() const;
00467 
00468       iterator begin();
00469       iterator end();
00470 
00471    private:
00472       Value &resolveReference( const char *key,
00473                                bool isStatic );
00474 
00475 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00476       inline bool isItemAvailable() const
00477       {
00478          return itemIsUsed_ == 0;
00479       }
00480 
00481       inline void setItemUsed( bool isUsed = true )
00482       {
00483          itemIsUsed_ = isUsed ? 1 : 0;
00484       }
00485 
00486       inline bool isMemberNameStatic() const
00487       {
00488          return memberNameIsStatic_ == 0;
00489       }
00490 
00491       inline void setMemberNameIsStatic( bool isStatic )
00492       {
00493          memberNameIsStatic_ = isStatic ? 1 : 0;
00494       }
00495 # endif // # ifdef JSON_VALUE_USE_INTERNAL_MAP
00496 
00497    private:
00498       struct CommentInfo
00499       {
00500          CommentInfo();
00501          ~CommentInfo();
00502 
00503          void setComment( const char *text );
00504 
00505          char *comment_;
00506       };
00507 
00508       //struct MemberNamesTransform
00509       //{
00510       //   typedef const char *result_type;
00511       //   const char *operator()( const CZString &name ) const
00512       //   {
00513       //      return name.c_str();
00514       //   }
00515       //};
00516 
00517       union ValueHolder
00518       {
00519          Int int_;
00520          UInt uint_;
00521          double real_;
00522          bool bool_;
00523          char *string_;
00524 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00525          ValueInternalArray *array_;
00526          ValueInternalMap *map_;
00527 #else
00528          ObjectValues *map_;
00529 # endif
00530       } value_;
00531       ValueType type_ : 8;
00532       int allocated_ : 1;     // Notes: if declared as bool, bitfield is useless.
00533 # ifdef JSON_VALUE_USE_INTERNAL_MAP
00534       unsigned int itemIsUsed_ : 1;      // used by the ValueInternalMap container.
00535       int memberNameIsStatic_ : 1;       // used by the ValueInternalMap container.
00536 # endif
00537       CommentInfo *comments_;
00538    };
00539 
00540 
00543    class PathArgument
00544    {
00545    public:
00546       friend class Path;
00547 
00548       PathArgument();
00549       PathArgument( UInt index );
00550       PathArgument( const char *key );
00551       PathArgument( const std::string &key );
00552 
00553    private:
00554       enum Kind
00555       {
00556          kindNone = 0,
00557          kindIndex,
00558          kindKey
00559       };
00560       std::string key_;
00561       UInt index_;
00562       Kind kind_;
00563    };
00564 
00576    class Path
00577    {
00578    public:
00579       Path( const std::string &path,
00580             const PathArgument &a1 = PathArgument(),
00581             const PathArgument &a2 = PathArgument(),
00582             const PathArgument &a3 = PathArgument(),
00583             const PathArgument &a4 = PathArgument(),
00584             const PathArgument &a5 = PathArgument() );
00585 
00586       const Value &resolve( const Value &root ) const;
00587       Value resolve( const Value &root,
00588                      const Value &defaultValue ) const;
00590       Value &make( Value &root ) const;
00591 
00592    private:
00593       typedef std::vector<const PathArgument *> InArgs;
00594       typedef std::vector<PathArgument> Args;
00595 
00596       void makePath( const std::string &path,
00597                      const InArgs &in );
00598       void addPathInArg( const std::string &path,
00599                          const InArgs &in,
00600                          InArgs::const_iterator &itInArg,
00601                          PathArgument::Kind kind );
00602       void invalidPath( const std::string &path,
00603                         int location );
00604 
00605       Args args_;
00606    };
00607 
00615    class ValueAllocator
00616    {
00617    public:
00618       enum { unknown = (unsigned)-1 };
00619 
00620       virtual ~ValueAllocator();
00621 
00622       virtual char *makeMemberName( const char *memberName ) = 0;
00623       virtual void releaseMemberName( char *memberName ) = 0;
00624       virtual char *duplicateStringValue( const char *value,
00625                                           unsigned int length = unknown ) = 0;
00626       virtual void releaseStringValue( char *value ) = 0;
00627    };
00628 
00629 #ifdef JSON_VALUE_USE_INTERNAL_MAP
00630 
00674    class JSON_API ValueMapAllocator
00675    {
00676    public:
00677       virtual ~ValueMapAllocator();
00678       virtual ValueInternalMap *newMap() = 0;
00679       virtual ValueInternalMap *newMapCopy( const ValueInternalMap &other ) = 0;
00680       virtual void destructMap( ValueInternalMap *map ) = 0;
00681       virtual ValueInternalLink *allocateMapBuckets( unsigned int size ) = 0;
00682       virtual void releaseMapBuckets( ValueInternalLink *links ) = 0;
00683       virtual ValueInternalLink *allocateMapLink() = 0;
00684       virtual void releaseMapLink( ValueInternalLink *link ) = 0;
00685    };
00686 
00690    class JSON_API ValueInternalLink
00691    {
00692    public:
00693       enum { itemPerLink = 6 };  // sizeof(ValueInternalLink) = 128 on 32 bits architecture.
00694       enum InternalFlags {
00695          flagAvailable = 0,
00696          flagUsed = 1
00697       };
00698 
00699       ValueInternalLink();
00700 
00701       ~ValueInternalLink();
00702 
00703       Value items_[itemPerLink];
00704       char *keys_[itemPerLink];
00705       ValueInternalLink *previous_;
00706       ValueInternalLink *next_;
00707    };
00708 
00709 
00722    class JSON_API ValueInternalMap
00723    {
00724       friend class ValueIteratorBase;
00725       friend class Value;
00726    public:
00727       typedef unsigned int HashKey;
00728       typedef unsigned int BucketIndex;
00729 
00730 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00731       struct IteratorState
00732       {
00733          IteratorState()
00734             : map_(0)
00735             , link_(0)
00736             , itemIndex_(0)
00737             , bucketIndex_(0)
00738          {
00739          }
00740          ValueInternalMap *map_;
00741          ValueInternalLink *link_;
00742          BucketIndex itemIndex_;
00743          BucketIndex bucketIndex_;
00744       };
00745 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00746 
00747       ValueInternalMap();
00748       ValueInternalMap( const ValueInternalMap &other );
00749       ValueInternalMap &operator =( const ValueInternalMap &other );
00750       ~ValueInternalMap();
00751 
00752       void swap( ValueInternalMap &other );
00753 
00754       BucketIndex size() const;
00755 
00756       void clear();
00757 
00758       bool reserveDelta( BucketIndex growth );
00759 
00760       bool reserve( BucketIndex newItemCount );
00761 
00762       const Value *find( const char *key ) const;
00763 
00764       Value *find( const char *key );
00765 
00766       Value &resolveReference( const char *key,
00767                                bool isStatic );
00768 
00769       void remove( const char *key );
00770 
00771       void doActualRemove( ValueInternalLink *link,
00772                            BucketIndex index,
00773                            BucketIndex bucketIndex );
00774 
00775       ValueInternalLink *&getLastLinkInBucket( BucketIndex bucketIndex );
00776 
00777       Value &setNewItem( const char *key,
00778                          bool isStatic,
00779                          ValueInternalLink *link,
00780                          BucketIndex index );
00781 
00782       Value &unsafeAdd( const char *key,
00783                         bool isStatic,
00784                         HashKey hashedKey );
00785 
00786       HashKey hash( const char *key ) const;
00787 
00788       int compare( const ValueInternalMap &other ) const;
00789 
00790    private:
00791       void makeBeginIterator( IteratorState &it ) const;
00792       void makeEndIterator( IteratorState &it ) const;
00793       static bool equals( const IteratorState &x, const IteratorState &other );
00794       static void increment( IteratorState &iterator );
00795       static void incrementBucket( IteratorState &iterator );
00796       static void decrement( IteratorState &iterator );
00797       static const char *key( const IteratorState &iterator );
00798       static const char *key( const IteratorState &iterator, bool &isStatic );
00799       static Value &value( const IteratorState &iterator );
00800       static int distance( const IteratorState &x, const IteratorState &y );
00801 
00802    private:
00803       ValueInternalLink *buckets_;
00804       ValueInternalLink *tailLink_;
00805       BucketIndex bucketsSize_;
00806       BucketIndex itemCount_;
00807    };
00808 
00820    class JSON_API ValueInternalArray
00821    {
00822       friend class Value;
00823       friend class ValueIteratorBase;
00824    public:
00825       enum { itemsPerPage = 8 };    // should be a power of 2 for fast divide and modulo.
00826       typedef Value::ArrayIndex ArrayIndex;
00827       typedef unsigned int PageIndex;
00828 
00829 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00830       struct IteratorState // Must be a POD
00831       {
00832          IteratorState()
00833             : array_(0)
00834             , currentPageIndex_(0)
00835             , currentItemIndex_(0)
00836          {
00837          }
00838          ValueInternalArray *array_;
00839          Value **currentPageIndex_;
00840          unsigned int currentItemIndex_;
00841       };
00842 # endif // ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION
00843 
00844       ValueInternalArray();
00845       ValueInternalArray( const ValueInternalArray &other );
00846       ValueInternalArray &operator =( const ValueInternalArray &other );
00847       ~ValueInternalArray();
00848       void swap( ValueInternalArray &other );
00849 
00850       void clear();
00851       void resize( ArrayIndex newSize );
00852 
00853       Value &resolveReference( ArrayIndex index );
00854 
00855       Value *find( ArrayIndex index ) const;
00856 
00857       ArrayIndex size() const;
00858 
00859       int compare( const ValueInternalArray &other ) const;
00860 
00861    private:
00862       static bool equals( const IteratorState &x, const IteratorState &other );
00863       static void increment( IteratorState &iterator );
00864       static void decrement( IteratorState &iterator );
00865       static Value &dereference( const IteratorState &iterator );
00866       static Value &unsafeDereference( const IteratorState &iterator );
00867       static int distance( const IteratorState &x, const IteratorState &y );
00868       static ArrayIndex indexOf( const IteratorState &iterator );
00869       void makeBeginIterator( IteratorState &it ) const;
00870       void makeEndIterator( IteratorState &it ) const;
00871       void makeIterator( IteratorState &it, ArrayIndex index ) const;
00872 
00873       void makeIndexValid( ArrayIndex index );
00874 
00875       Value **pages_;
00876       ArrayIndex size_;
00877       PageIndex pageCount_;
00878    };
00879 
00939    class JSON_API ValueArrayAllocator
00940    {
00941    public:
00942       virtual ~ValueArrayAllocator();
00943       virtual ValueInternalArray *newArray() = 0;
00944       virtual ValueInternalArray *newArrayCopy( const ValueInternalArray &other ) = 0;
00945       virtual void destructArray( ValueInternalArray *array ) = 0;
00957       virtual void reallocateArrayPageIndex( Value **&indexes,
00958                                              ValueInternalArray::PageIndex &indexCount,
00959                                              ValueInternalArray::PageIndex minNewIndexCount ) = 0;
00960       virtual void releaseArrayPageIndex( Value **indexes,
00961                                           ValueInternalArray::PageIndex indexCount ) = 0;
00962       virtual Value *allocateArrayPage() = 0;
00963       virtual void releaseArrayPage( Value *value ) = 0;
00964    };
00965 #endif // #ifdef JSON_VALUE_USE_INTERNAL_MAP
00966 
00967 
00971    class ValueIteratorBase
00972    {
00973    public:
00974       typedef unsigned int size_t;
00975       typedef int difference_type;
00976       typedef ValueIteratorBase SelfType;
00977       typedef std::bidirectional_iterator_tag iterator_category;
00978       typedef Value value_type;
00979       typedef Value& reference;
00980       typedef const Value& const_reference;
00981 
00982       ValueIteratorBase();
00983 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00984       explicit ValueIteratorBase( const Value::ObjectValues::iterator &current );
00985 #else
00986       ValueIteratorBase( const ValueInternalArray::IteratorState &state );
00987       ValueIteratorBase( const ValueInternalMap::IteratorState &state );
00988 #endif
00989 
00990       bool operator ==( const SelfType &other ) const
00991       {
00992          return isEqual( other );
00993       }
00994 
00995       bool operator !=( const SelfType &other ) const
00996       {
00997          return !isEqual( other );
00998       }
00999 
01000       difference_type operator -( const SelfType &other ) const
01001       {
01002          return computeDistance( other );
01003       }
01004 
01006       Value key() const;
01007 
01009       UInt index() const;
01010 
01012       const char *memberNameC() const;
01013 
01014       std::string memberName() const { return memberNameC(); }
01015 
01016    protected:
01017       Value &deref() const;
01018 
01019       void increment();
01020 
01021       void decrement();
01022 
01023       difference_type computeDistance( const SelfType &other ) const;
01024 
01025       bool isEqual( const SelfType &other ) const;
01026 
01027       void copy( const SelfType &other );
01028 
01029    private:
01030 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01031       Value::ObjectValues::iterator current_;
01032       // Indicates that iterator is for a null value.
01033       bool isNull_;
01034 #else
01035       union
01036       {
01037          ValueInternalArray::IteratorState array_;
01038          ValueInternalMap::IteratorState map_;
01039       } iterator_;
01040       bool isArray_;
01041 #endif
01042    };
01043 
01047    class ValueConstIterator : public ValueIteratorBase
01048    {
01049       friend class Value;
01050    public:
01051       typedef unsigned int size_t;
01052       typedef int difference_type;
01053       typedef const Value &reference;
01054       typedef const Value *pointer;
01055       typedef ValueConstIterator SelfType;
01056 
01057       ValueConstIterator();
01058    private:
01061 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01062       explicit ValueConstIterator( const Value::ObjectValues::iterator &current );
01063 #else
01064       ValueConstIterator( const ValueInternalArray::IteratorState &state );
01065       ValueConstIterator( const ValueInternalMap::IteratorState &state );
01066 #endif
01067    public:
01068       SelfType &operator =( const ValueIteratorBase &other );
01069 
01070       SelfType operator++( int )
01071       {
01072          SelfType temp( *this );
01073          ++*this;
01074          return temp;
01075       }
01076 
01077       SelfType operator--( int )
01078       {
01079          SelfType temp( *this );
01080          --*this;
01081          return temp;
01082       }
01083 
01084       SelfType &operator--()
01085       {
01086          decrement();
01087          return *this;
01088       }
01089 
01090       SelfType &operator++()
01091       {
01092          increment();
01093          return *this;
01094       }
01095 
01096       reference operator *() const
01097       {
01098          return deref();
01099       }
01100 
01101       pointer operator -> () const
01102       {
01103           return &deref();
01104       }
01105    };
01106 
01107 
01110    class ValueIterator : public ValueIteratorBase
01111    {
01112       friend class Value;
01113    public:
01114       typedef unsigned int size_t;
01115       typedef int difference_type;
01116       typedef Value &reference;
01117       typedef Value *pointer;
01118       typedef ValueIterator SelfType;
01119 
01120       ValueIterator();
01121       ValueIterator( const ValueConstIterator &other );
01122       ValueIterator( const ValueIterator &other );
01123    private:
01126 #ifndef JSON_VALUE_USE_INTERNAL_MAP
01127       explicit ValueIterator( const Value::ObjectValues::iterator &current );
01128 #else
01129       ValueIterator( const ValueInternalArray::IteratorState &state );
01130       ValueIterator( const ValueInternalMap::IteratorState &state );
01131 #endif
01132    public:
01133 
01134       SelfType &operator =( const SelfType &other );
01135 
01136       SelfType operator++( int )
01137       {
01138          SelfType temp( *this );
01139          ++*this;
01140          return temp;
01141       }
01142 
01143       SelfType operator--( int )
01144       {
01145          SelfType temp( *this );
01146          --*this;
01147          return temp;
01148       }
01149 
01150       SelfType &operator--()
01151       {
01152          decrement();
01153          return *this;
01154       }
01155 
01156       SelfType &operator++()
01157       {
01158          increment();
01159          return *this;
01160       }
01161 
01162       reference operator *() const
01163       {
01164          return deref();
01165       }
01166    };
01167 
01168 
01169 } // namespace Json
01170 
01171 
01172 #endif // CPPTL_JSON_H_INCLUDED
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator