1
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
* JSON Library, originally from http://jsoncpp.sourceforge.net/
5
* Copyright (C) 2011 Stewart Smith
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions are
12
* * Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* * Redistributions in binary form must reproduce the above
16
* copyright notice, this list of conditions and the following disclaimer
17
* in the documentation and/or other materials provided with the
20
* * The names of its contributors may not be used to endorse or
21
* promote products derived from this software without specific prior
24
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
// included by json_value.cpp
40
// everything is within Json namespace
43
// //////////////////////////////////////////////////////////////////
44
// //////////////////////////////////////////////////////////////////
45
// //////////////////////////////////////////////////////////////////
46
// class ValueIteratorBase
47
// //////////////////////////////////////////////////////////////////
48
// //////////////////////////////////////////////////////////////////
49
// //////////////////////////////////////////////////////////////////
51
ValueIteratorBase::ValueIteratorBase()
52
#ifndef JSON_VALUE_USE_INTERNAL_MAP
61
iterator_.array_ = ValueInternalArray::IteratorState();
66
#ifndef JSON_VALUE_USE_INTERNAL_MAP
67
ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator ¤t )
73
ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state )
76
iterator_.array_ = state;
80
ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state )
83
iterator_.map_ = state;
88
ValueIteratorBase::deref() const
90
#ifndef JSON_VALUE_USE_INTERNAL_MAP
91
return current_->second;
94
return ValueInternalArray::dereference( iterator_.array_ );
95
return ValueInternalMap::value( iterator_.map_ );
101
ValueIteratorBase::increment()
103
#ifndef JSON_VALUE_USE_INTERNAL_MAP
107
ValueInternalArray::increment( iterator_.array_ );
108
ValueInternalMap::increment( iterator_.map_ );
114
ValueIteratorBase::decrement()
116
#ifndef JSON_VALUE_USE_INTERNAL_MAP
120
ValueInternalArray::decrement( iterator_.array_ );
121
ValueInternalMap::decrement( iterator_.map_ );
126
ValueIteratorBase::difference_type
127
ValueIteratorBase::computeDistance( const SelfType &other ) const
129
#ifndef JSON_VALUE_USE_INTERNAL_MAP
130
# ifdef JSON_USE_CPPTL_SMALLMAP
131
return current_ - other.current_;
133
// Iterator for null value are initialized using the default
134
// constructor, which initialize current_ to the default
135
// std::map::iterator. As begin() and end() are two instance
136
// of the default std::map::iterator, they can not be compared.
137
// To allow this, we handle this comparison specifically.
138
if ( isNull_ && other.isNull_ )
144
// Usage of std::distance is not portable (does not compile with Sun Studio 12 RogueWave STL,
145
// which is the one used by default).
146
// Using a portable hand-made version for non random iterator instead:
147
// return difference_type( std::distance( current_, other.current_ ) );
148
difference_type myDistance = 0;
149
for ( Value::ObjectValues::iterator it = current_; it != other.current_; ++it )
157
return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ );
158
return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ );
164
ValueIteratorBase::isEqual( const SelfType &other ) const
166
#ifndef JSON_VALUE_USE_INTERNAL_MAP
169
return other.isNull_;
171
return current_ == other.current_;
174
return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ );
175
return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ );
181
ValueIteratorBase::copy( const SelfType &other )
183
#ifndef JSON_VALUE_USE_INTERNAL_MAP
184
current_ = other.current_;
187
iterator_.array_ = other.iterator_.array_;
188
iterator_.map_ = other.iterator_.map_;
194
ValueIteratorBase::key() const
196
#ifndef JSON_VALUE_USE_INTERNAL_MAP
197
const Value::CZString czstring = (*current_).first;
198
if ( czstring.c_str() )
200
if ( czstring.isStaticString() )
201
return Value( StaticString( czstring.c_str() ) );
202
return Value( czstring.c_str() );
204
return Value( czstring.index() );
207
return Value( ValueInternalArray::indexOf( iterator_.array_ ) );
209
const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic );
211
return Value( StaticString( memberName ) );
212
return Value( memberName );
218
ValueIteratorBase::index() const
220
#ifndef JSON_VALUE_USE_INTERNAL_MAP
221
const Value::CZString czstring = (*current_).first;
222
if ( !czstring.c_str() )
223
return czstring.index();
224
return Value::UInt( -1 );
227
return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) );
228
return Value::UInt( -1 );
234
ValueIteratorBase::memberName() const
236
#ifndef JSON_VALUE_USE_INTERNAL_MAP
237
const char *name = (*current_).first.c_str();
238
return name ? name : "";
241
return ValueInternalMap::key( iterator_.map_ );
247
// //////////////////////////////////////////////////////////////////
248
// //////////////////////////////////////////////////////////////////
249
// //////////////////////////////////////////////////////////////////
250
// class ValueConstIterator
251
// //////////////////////////////////////////////////////////////////
252
// //////////////////////////////////////////////////////////////////
253
// //////////////////////////////////////////////////////////////////
255
ValueConstIterator::ValueConstIterator()
260
#ifndef JSON_VALUE_USE_INTERNAL_MAP
261
ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator ¤t )
262
: ValueIteratorBase( current )
266
ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state )
267
: ValueIteratorBase( state )
271
ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state )
272
: ValueIteratorBase( state )
278
ValueConstIterator::operator =( const ValueIteratorBase &other )
285
// //////////////////////////////////////////////////////////////////
286
// //////////////////////////////////////////////////////////////////
287
// //////////////////////////////////////////////////////////////////
288
// class ValueIterator
289
// //////////////////////////////////////////////////////////////////
290
// //////////////////////////////////////////////////////////////////
291
// //////////////////////////////////////////////////////////////////
293
ValueIterator::ValueIterator()
298
#ifndef JSON_VALUE_USE_INTERNAL_MAP
299
ValueIterator::ValueIterator( const Value::ObjectValues::iterator ¤t )
300
: ValueIteratorBase( current )
304
ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state )
305
: ValueIteratorBase( state )
309
ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state )
310
: ValueIteratorBase( state )
315
ValueIterator::ValueIterator( const ValueConstIterator &other )
316
: ValueIteratorBase( other )
320
ValueIterator::ValueIterator( const ValueIterator &other )
321
: ValueIteratorBase( other )
326
ValueIterator::operator =( const SelfType &other )