00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #pragma once
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 ValueIteratorBase::ValueIteratorBase()
00052 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00053 : current_()
00054 , isNull_( true )
00055 {
00056 }
00057 #else
00058 : isArray_( true )
00059 , isNull_( true )
00060 {
00061 iterator_.array_ = ValueInternalArray::IteratorState();
00062 }
00063 #endif
00064
00065
00066 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00067 ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t )
00068 : current_( current )
00069 , isNull_( false )
00070 {
00071 }
00072 #else
00073 ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state )
00074 : isArray_( true )
00075 {
00076 iterator_.array_ = state;
00077 }
00078
00079
00080 ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state )
00081 : isArray_( false )
00082 {
00083 iterator_.map_ = state;
00084 }
00085 #endif
00086
00087 Value &
00088 ValueIteratorBase::deref() const
00089 {
00090 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00091 return current_->second;
00092 #else
00093 if ( isArray_ )
00094 return ValueInternalArray::dereference( iterator_.array_ );
00095 return ValueInternalMap::value( iterator_.map_ );
00096 #endif
00097 }
00098
00099
00100 void
00101 ValueIteratorBase::increment()
00102 {
00103 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00104 ++current_;
00105 #else
00106 if ( isArray_ )
00107 ValueInternalArray::increment( iterator_.array_ );
00108 ValueInternalMap::increment( iterator_.map_ );
00109 #endif
00110 }
00111
00112
00113 void
00114 ValueIteratorBase::decrement()
00115 {
00116 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00117 --current_;
00118 #else
00119 if ( isArray_ )
00120 ValueInternalArray::decrement( iterator_.array_ );
00121 ValueInternalMap::decrement( iterator_.map_ );
00122 #endif
00123 }
00124
00125
00126 ValueIteratorBase::difference_type
00127 ValueIteratorBase::computeDistance( const SelfType &other ) const
00128 {
00129 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00130 # ifdef JSON_USE_CPPTL_SMALLMAP
00131 return current_ - other.current_;
00132 # else
00133
00134
00135
00136
00137
00138 if ( isNull_ && other.isNull_ )
00139 {
00140 return 0;
00141 }
00142
00143
00144
00145
00146
00147
00148 difference_type myDistance = 0;
00149 for ( Value::ObjectValues::iterator it = current_; it != other.current_; ++it )
00150 {
00151 ++myDistance;
00152 }
00153 return myDistance;
00154 # endif
00155 #else
00156 if ( isArray_ )
00157 return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ );
00158 return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ );
00159 #endif
00160 }
00161
00162
00163 bool
00164 ValueIteratorBase::isEqual( const SelfType &other ) const
00165 {
00166 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00167 if ( isNull_ )
00168 {
00169 return other.isNull_;
00170 }
00171 return current_ == other.current_;
00172 #else
00173 if ( isArray_ )
00174 return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ );
00175 return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ );
00176 #endif
00177 }
00178
00179
00180 void
00181 ValueIteratorBase::copy( const SelfType &other )
00182 {
00183 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00184 current_ = other.current_;
00185 #else
00186 if ( isArray_ )
00187 iterator_.array_ = other.iterator_.array_;
00188 iterator_.map_ = other.iterator_.map_;
00189 #endif
00190 }
00191
00192
00193 Value
00194 ValueIteratorBase::key() const
00195 {
00196 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00197 const Value::CZString czstring = (*current_).first;
00198 if ( czstring.c_str() )
00199 {
00200 if ( czstring.isStaticString() )
00201 return Value( StaticString( czstring.c_str() ) );
00202 return Value( czstring.c_str() );
00203 }
00204 return Value( czstring.index() );
00205 #else
00206 if ( isArray_ )
00207 return Value( ValueInternalArray::indexOf( iterator_.array_ ) );
00208 bool isStatic;
00209 const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic );
00210 if ( isStatic )
00211 return Value( StaticString( memberName ) );
00212 return Value( memberName );
00213 #endif
00214 }
00215
00216
00217 UInt
00218 ValueIteratorBase::index() const
00219 {
00220 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00221 const Value::CZString czstring = (*current_).first;
00222 if ( !czstring.c_str() )
00223 return czstring.index();
00224 return Value::UInt( -1 );
00225 #else
00226 if ( isArray_ )
00227 return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) );
00228 return Value::UInt( -1 );
00229 #endif
00230 }
00231
00232
00233 const char *
00234 ValueIteratorBase::memberName() const
00235 {
00236 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00237 const char *name = (*current_).first.c_str();
00238 return name ? name : "";
00239 #else
00240 if ( !isArray_ )
00241 return ValueInternalMap::key( iterator_.map_ );
00242 return "";
00243 #endif
00244 }
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 ValueConstIterator::ValueConstIterator()
00256 {
00257 }
00258
00259
00260 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00261 ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator ¤t )
00262 : ValueIteratorBase( current )
00263 {
00264 }
00265 #else
00266 ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state )
00267 : ValueIteratorBase( state )
00268 {
00269 }
00270
00271 ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state )
00272 : ValueIteratorBase( state )
00273 {
00274 }
00275 #endif
00276
00277 ValueConstIterator &
00278 ValueConstIterator::operator =( const ValueIteratorBase &other )
00279 {
00280 copy( other );
00281 return *this;
00282 }
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 ValueIterator::ValueIterator()
00294 {
00295 }
00296
00297
00298 #ifndef JSON_VALUE_USE_INTERNAL_MAP
00299 ValueIterator::ValueIterator( const Value::ObjectValues::iterator ¤t )
00300 : ValueIteratorBase( current )
00301 {
00302 }
00303 #else
00304 ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state )
00305 : ValueIteratorBase( state )
00306 {
00307 }
00308
00309 ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state )
00310 : ValueIteratorBase( state )
00311 {
00312 }
00313 #endif
00314
00315 ValueIterator::ValueIterator( const ValueConstIterator &other )
00316 : ValueIteratorBase( other )
00317 {
00318 }
00319
00320 ValueIterator::ValueIterator( const ValueIterator &other )
00321 : ValueIteratorBase( other )
00322 {
00323 }
00324
00325 ValueIterator &
00326 ValueIterator::operator =( const SelfType &other )
00327 {
00328 copy( other );
00329 return *this;
00330 }