arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/ionic-plugin-keyboard/src/blackberry10/native/public/json_valueiterator.inl
plugins/ionic-plugin-keyboard/src/blackberry10/native/public/json_valueiterator.inlRaw
  1// included by json_value.cpp
  2// everything is within Json namespace
  3
  4
  5// //////////////////////////////////////////////////////////////////
  6// //////////////////////////////////////////////////////////////////
  7// //////////////////////////////////////////////////////////////////
  8// class ValueIteratorBase
  9// //////////////////////////////////////////////////////////////////
 10// //////////////////////////////////////////////////////////////////
 11// //////////////////////////////////////////////////////////////////
 12
 13ValueIteratorBase::ValueIteratorBase()
 14#ifndef JSON_VALUE_USE_INTERNAL_MAP
 15   : current_()
 16   , isNull_( true )
 17{
 18}
 19#else
 20   : isArray_( true )
 21   , isNull_( true )
 22{
 23   iterator_.array_ = ValueInternalArray::IteratorState();
 24}
 25#endif
 26
 27
 28#ifndef JSON_VALUE_USE_INTERNAL_MAP
 29ValueIteratorBase::ValueIteratorBase( const Value::ObjectValues::iterator &current )
 30   : current_( current )
 31   , isNull_( false )
 32{
 33}
 34#else
 35ValueIteratorBase::ValueIteratorBase( const ValueInternalArray::IteratorState &state )
 36   : isArray_( true )
 37{
 38   iterator_.array_ = state;
 39}
 40
 41
 42ValueIteratorBase::ValueIteratorBase( const ValueInternalMap::IteratorState &state )
 43   : isArray_( false )
 44{
 45   iterator_.map_ = state;
 46}
 47#endif
 48
 49Value &
 50ValueIteratorBase::deref() const
 51{
 52#ifndef JSON_VALUE_USE_INTERNAL_MAP
 53   return current_->second;
 54#else
 55   if ( isArray_ )
 56      return ValueInternalArray::dereference( iterator_.array_ );
 57   return ValueInternalMap::value( iterator_.map_ );
 58#endif
 59}
 60
 61
 62void 
 63ValueIteratorBase::increment()
 64{
 65#ifndef JSON_VALUE_USE_INTERNAL_MAP
 66   ++current_;
 67#else
 68   if ( isArray_ )
 69      ValueInternalArray::increment( iterator_.array_ );
 70   ValueInternalMap::increment( iterator_.map_ );
 71#endif
 72}
 73
 74
 75void 
 76ValueIteratorBase::decrement()
 77{
 78#ifndef JSON_VALUE_USE_INTERNAL_MAP
 79   --current_;
 80#else
 81   if ( isArray_ )
 82      ValueInternalArray::decrement( iterator_.array_ );
 83   ValueInternalMap::decrement( iterator_.map_ );
 84#endif
 85}
 86
 87
 88ValueIteratorBase::difference_type 
 89ValueIteratorBase::computeDistance( const SelfType &other ) const
 90{
 91#ifndef JSON_VALUE_USE_INTERNAL_MAP
 92# ifdef JSON_USE_CPPTL_SMALLMAP
 93   return current_ - other.current_;
 94# else
 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_ )
101   {
102      return 0;
103   }
104
105
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 )
112   {
113      ++myDistance;
114   }
115   return myDistance;
116# endif
117#else
118   if ( isArray_ )
119      return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ );
120   return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ );
121#endif
122}
123
124
125bool 
126ValueIteratorBase::isEqual( const SelfType &other ) const
127{
128#ifndef JSON_VALUE_USE_INTERNAL_MAP
129   if ( isNull_ )
130   {
131      return other.isNull_;
132   }
133   return current_ == other.current_;
134#else
135   if ( isArray_ )
136      return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ );
137   return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ );
138#endif
139}
140
141
142void 
143ValueIteratorBase::copy( const SelfType &other )
144{
145#ifndef JSON_VALUE_USE_INTERNAL_MAP
146   current_ = other.current_;
147#else
148   if ( isArray_ )
149      iterator_.array_ = other.iterator_.array_;
150   iterator_.map_ = other.iterator_.map_;
151#endif
152}
153
154
155Value 
156ValueIteratorBase::key() const
157{
158#ifndef JSON_VALUE_USE_INTERNAL_MAP
159   const Value::CZString czstring = (*current_).first;
160   if ( czstring.c_str() )
161   {
162      if ( czstring.isStaticString() )
163         return Value( StaticString( czstring.c_str() ) );
164      return Value( czstring.c_str() );
165   }
166   return Value( czstring.index() );
167#else
168   if ( isArray_ )
169      return Value( ValueInternalArray::indexOf( iterator_.array_ ) );
170   bool isStatic;
171   const char *memberName = ValueInternalMap::key( iterator_.map_, isStatic );
172   if ( isStatic )
173      return Value( StaticString( memberName ) );
174   return Value( memberName );
175#endif
176}
177
178
179UInt 
180ValueIteratorBase::index() const
181{
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 );
187#else
188   if ( isArray_ )
189      return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) );
190   return Value::UInt( -1 );
191#endif
192}
193
194
195const char *
196ValueIteratorBase::memberName() const
197{
198#ifndef JSON_VALUE_USE_INTERNAL_MAP
199   const char *name = (*current_).first.c_str();
200   return name ? name : "";
201#else
202   if ( !isArray_ )
203      return ValueInternalMap::key( iterator_.map_ );
204   return "";
205#endif
206}
207
208
209// //////////////////////////////////////////////////////////////////
210// //////////////////////////////////////////////////////////////////
211// //////////////////////////////////////////////////////////////////
212// class ValueConstIterator
213// //////////////////////////////////////////////////////////////////
214// //////////////////////////////////////////////////////////////////
215// //////////////////////////////////////////////////////////////////
216
217ValueConstIterator::ValueConstIterator()
218{
219}
220
221
222#ifndef JSON_VALUE_USE_INTERNAL_MAP
223ValueConstIterator::ValueConstIterator( const Value::ObjectValues::iterator &current )
224   : ValueIteratorBase( current )
225{
226}
227#else
228ValueConstIterator::ValueConstIterator( const ValueInternalArray::IteratorState &state )
229   : ValueIteratorBase( state )
230{
231}
232
233ValueConstIterator::ValueConstIterator( const ValueInternalMap::IteratorState &state )
234   : ValueIteratorBase( state )
235{
236}
237#endif
238
239ValueConstIterator &
240ValueConstIterator::operator =( const ValueIteratorBase &other )
241{
242   copy( other );
243   return *this;
244}
245
246
247// //////////////////////////////////////////////////////////////////
248// //////////////////////////////////////////////////////////////////
249// //////////////////////////////////////////////////////////////////
250// class ValueIterator
251// //////////////////////////////////////////////////////////////////
252// //////////////////////////////////////////////////////////////////
253// //////////////////////////////////////////////////////////////////
254
255ValueIterator::ValueIterator()
256{
257}
258
259
260#ifndef JSON_VALUE_USE_INTERNAL_MAP
261ValueIterator::ValueIterator( const Value::ObjectValues::iterator &current )
262   : ValueIteratorBase( current )
263{
264}
265#else
266ValueIterator::ValueIterator( const ValueInternalArray::IteratorState &state )
267   : ValueIteratorBase( state )
268{
269}
270
271ValueIterator::ValueIterator( const ValueInternalMap::IteratorState &state )
272   : ValueIteratorBase( state )
273{
274}
275#endif
276
277ValueIterator::ValueIterator( const ValueConstIterator &other )
278   : ValueIteratorBase( other )
279{
280}
281
282ValueIterator::ValueIterator( const ValueIterator &other )
283   : ValueIteratorBase( other )
284{
285}
286
287ValueIterator &
288ValueIterator::operator =( const SelfType &other )
289{
290   copy( other );
291   return *this;
292}