1
// included by json_value.cpp
2
// everything is within Json namespace
5
// //////////////////////////////////////////////////////////////////
6
// //////////////////////////////////////////////////////////////////
7
// //////////////////////////////////////////////////////////////////
8
// class ValueIteratorBase
9
// //////////////////////////////////////////////////////////////////
10
// //////////////////////////////////////////////////////////////////
11
// //////////////////////////////////////////////////////////////////
13
ValueIteratorBase::ValueIteratorBase()
14
#ifndef JSON_VALUE_USE_INTERNAL_MAP
23
iterator_.array_ = ValueInternalArray::IteratorState();
28
#ifndef JSON_VALUE_USE_INTERNAL_MAP
29
ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t )
35
ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state )
38
iterator_.array_ = state;
42
ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state )
45
iterator_.map_ = state;
50
ValueIteratorBase::deref() const
52
#ifndef JSON_VALUE_USE_INTERNAL_MAP
53
return current_->second;
56
return ValueInternalArray::dereference( iterator_.array_ );
57
return ValueInternalMap::value( iterator_.map_ );
63
ValueIteratorBase::increment()
65
#ifndef JSON_VALUE_USE_INTERNAL_MAP
69
ValueInternalArray::increment( iterator_.array_ );
70
ValueInternalMap::increment( iterator_.map_ );
76
ValueIteratorBase::decrement()
78
#ifndef JSON_VALUE_USE_INTERNAL_MAP
82
ValueInternalArray::decrement( iterator_.array_ );
83
ValueInternalMap::decrement( iterator_.map_ );
88
ValueIteratorBase::difference_type
89
ValueIteratorBase::computeDistance( const SelfType &other ) const
91
#ifndef JSON_VALUE_USE_INTERNAL_MAP
92
# ifdef JSON_USE_CPPTL_SMALLMAP
93
return current_ - other.current_;
95
// Iterator for null value are initialized using the default
96
// constructor, which initialize current_ to the default
97
// std::map::iterator. As begin() and end() are two instance
98
// of the default std::map::iterator, they can not be compared.
99
// To allow this, we handle this comparison specifically.
100
if ( isNull_ && other.isNull_ )
106
// Usage of std::distance is not portable (does not compile with Sun Studio 12 RogueWave STL,
107
// which is the one used by default).
108
// Using a portable hand-made version for non random iterator instead:
109
// return difference_type( std::distance( current_, other.current_ ) );
110
difference_type myDistance = 0;
111
for ( Value::ObjectValues::iterator it = current_; it != other.current_; ++it )
119
return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ );
120
return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ );
126
ValueIteratorBase::isEqual( const SelfType &other ) const
128
#ifndef JSON_VALUE_USE_INTERNAL_MAP
131
return other.isNull_;
133
return current_ == other.current_;
136
return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ );
137
return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ );
143
ValueIteratorBase::copy( const SelfType &other )
145
#ifndef JSON_VALUE_USE_INTERNAL_MAP
146
current_ = other.current_;
149
iterator_.array_ = other.iterator_.array_;
150
iterator_.map_ = other.iterator_.map_;
156
ValueIteratorBase::key() const
158
#ifndef JSON_VALUE_USE_INTERNAL_MAP
159
const Value::CZString czstring = (*current_).first;
160
if ( czstring.c_str() )
162
if ( czstring.isStaticString() )
163
return Value( StaticString( czstring.c_str() ) );
164
return Value( czstring.c_str() );
166
return Value( czstring.index() );
169
return Value( ValueInternalArray::indexOf( iterator_.array_ ) );
171
const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic );
173
return Value( StaticString( memberName ) );
174
return Value( memberName );
180
ValueIteratorBase::index() const
182
#ifndef JSON_VALUE_USE_INTERNAL_MAP
183
const Value::CZString czstring = (*current_).first;
184
if ( !czstring.c_str() )
185
return czstring.index();
186
return Value::UInt( -1 );
189
return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) );
190
return Value::UInt( -1 );
196
ValueIteratorBase::memberName() const
198
#ifndef JSON_VALUE_USE_INTERNAL_MAP
199
const char *name = (*current_).first.c_str();
200
return name ? name : "";
203
return ValueInternalMap::key( iterator_.map_ );
209
// //////////////////////////////////////////////////////////////////
210
// //////////////////////////////////////////////////////////////////
211
// //////////////////////////////////////////////////////////////////
212
// class ValueConstIterator
213
// //////////////////////////////////////////////////////////////////
214
// //////////////////////////////////////////////////////////////////
215
// //////////////////////////////////////////////////////////////////
217
ValueConstIterator::ValueConstIterator()
222
#ifndef JSON_VALUE_USE_INTERNAL_MAP
223
ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator ¤t )
224
: ValueIteratorBase( current )
228
ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state )
229
: ValueIteratorBase( state )
233
ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state )
234
: ValueIteratorBase( state )
240
ValueConstIterator::operator =( const ValueIteratorBase &other )
247
// //////////////////////////////////////////////////////////////////
248
// //////////////////////////////////////////////////////////////////
249
// //////////////////////////////////////////////////////////////////
250
// class ValueIterator
251
// //////////////////////////////////////////////////////////////////
252
// //////////////////////////////////////////////////////////////////
253
// //////////////////////////////////////////////////////////////////
255
ValueIterator::ValueIterator()
260
#ifndef JSON_VALUE_USE_INTERNAL_MAP
261
ValueIterator::ValueIterator( const Value::ObjectValues::iterator ¤t )
262
: ValueIteratorBase( current )
266
ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state )
267
: ValueIteratorBase( state )
271
ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state )
272
: ValueIteratorBase( state )
277
ValueIterator::ValueIterator( const ValueConstIterator &other )
278
: ValueIteratorBase( other )
282
ValueIterator::ValueIterator( const ValueIterator &other )
283
: ValueIteratorBase( other )
288
ValueIterator::operator =( const SelfType &other )