Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:10

0001 // included by json_value.cpp
0002 // everything is within Json namespace
0003 
0004 // //////////////////////////////////////////////////////////////////
0005 // //////////////////////////////////////////////////////////////////
0006 // //////////////////////////////////////////////////////////////////
0007 // class ValueIteratorBase
0008 // //////////////////////////////////////////////////////////////////
0009 // //////////////////////////////////////////////////////////////////
0010 // //////////////////////////////////////////////////////////////////
0011 
0012 //NOLINTNEXTLINE(misc-definitions-in-headers)
0013 ValueIteratorBase::ValueIteratorBase()
0014 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0015     : current_(),
0016       isNull_(true){}
0017 #else
0018     : isArray_(true), isNull_(true) {
0019   iterator_.array_ = ValueInternalArray::IteratorState();
0020 }
0021 #endif
0022 
0023 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0024       //NOLINTNEXTLINE(misc-definitions-in-headers)
0025       ValueIteratorBase::ValueIteratorBase(const Value::ObjectValues::iterator &current)
0026     : current_(current), isNull_(false) {
0027 }
0028 #else
0029 //NOLINTNEXTLINE(misc-definitions-in-headers)
0030 ValueIteratorBase::ValueIteratorBase(const ValueInternalArray::IteratorState &state) : isArray_(true) {
0031   iterator_.array_ = state;
0032 }
0033 
0034 //NOLINTNEXTLINE(misc-definitions-in-headers)
0035 ValueIteratorBase::ValueIteratorBase(const ValueInternalMap::IteratorState &state) : isArray_(false) {
0036   iterator_.map_ = state;
0037 }
0038 #endif
0039 
0040 //NOLINTNEXTLINE(misc-definitions-in-headers)
0041 Value &ValueIteratorBase::deref() const {
0042 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0043   return current_->second;
0044 #else
0045   if (isArray_)
0046     return ValueInternalArray::dereference(iterator_.array_);
0047   return ValueInternalMap::value(iterator_.map_);
0048 #endif
0049 }
0050 
0051 //NOLINTNEXTLINE(misc-definitions-in-headers)
0052 void ValueIteratorBase::increment() {
0053 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0054   ++current_;
0055 #else
0056   if (isArray_)
0057     ValueInternalArray::increment(iterator_.array_);
0058   ValueInternalMap::increment(iterator_.map_);
0059 #endif
0060 }
0061 
0062 //NOLINTNEXTLINE(misc-definitions-in-headers)
0063 void ValueIteratorBase::decrement() {
0064 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0065   --current_;
0066 #else
0067   if (isArray_)
0068     ValueInternalArray::decrement(iterator_.array_);
0069   ValueInternalMap::decrement(iterator_.map_);
0070 #endif
0071 }
0072 
0073 //NOLINTNEXTLINE(misc-definitions-in-headers)
0074 ValueIteratorBase::difference_type ValueIteratorBase::computeDistance(const SelfType &other) const {
0075 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0076 #ifdef JSON_USE_CPPTL_SMALLMAP
0077   return current_ - other.current_;
0078 #else
0079   // Iterator for null value are initialized using the default
0080   // constructor, which initialize current_ to the default
0081   // std::map::iterator. As begin() and end() are two instance
0082   // of the default std::map::iterator, they can not be compared.
0083   // To allow this, we handle this comparison specifically.
0084   if (isNull_ && other.isNull_) {
0085     return 0;
0086   }
0087 
0088   // Usage of std::distance is not portable (does not compile with Sun Studio 12 RogueWave STL,
0089   // which is the one used by default).
0090   // Using a portable hand-made version for non random iterator instead:
0091   //   return difference_type( std::distance( current_, other.current_ ) );
0092   difference_type myDistance = 0;
0093   for (Value::ObjectValues::iterator it = current_; it != other.current_; ++it) {
0094     ++myDistance;
0095   }
0096   return myDistance;
0097 #endif
0098 #else
0099   if (isArray_)
0100     return ValueInternalArray::distance(iterator_.array_, other.iterator_.array_);
0101   return ValueInternalMap::distance(iterator_.map_, other.iterator_.map_);
0102 #endif
0103 }
0104 
0105 //NOLINTNEXTLINE(misc-definitions-in-headers)
0106 bool ValueIteratorBase::isEqual(const SelfType &other) const {
0107 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0108   if (isNull_) {
0109     return other.isNull_;
0110   }
0111   return current_ == other.current_;
0112 #else
0113   if (isArray_)
0114     return ValueInternalArray::equals(iterator_.array_, other.iterator_.array_);
0115   return ValueInternalMap::equals(iterator_.map_, other.iterator_.map_);
0116 #endif
0117 }
0118 
0119 //NOLINTNEXTLINE(misc-definitions-in-headers)
0120 void ValueIteratorBase::copy(const SelfType &other) {
0121 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0122   current_ = other.current_;
0123 #else
0124   if (isArray_)
0125     iterator_.array_ = other.iterator_.array_;
0126   iterator_.map_ = other.iterator_.map_;
0127 #endif
0128 }
0129 
0130 //NOLINTNEXTLINE(misc-definitions-in-headers)
0131 Value ValueIteratorBase::key() const {
0132 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0133   const Value::CZString czstring = (*current_).first;
0134   if (czstring.c_str()) {
0135     if (czstring.isStaticString())
0136       return Value(StaticString(czstring.c_str()));
0137     return Value(czstring.c_str());
0138   }
0139   return Value(czstring.index());
0140 #else
0141   if (isArray_)
0142     return Value(ValueInternalArray::indexOf(iterator_.array_));
0143   bool isStatic;
0144   const char *memberName = ValueInternalMap::key(iterator_.map_, isStatic);
0145   if (isStatic)
0146     return Value(StaticString(memberName));
0147   return Value(memberName);
0148 #endif
0149 }
0150 
0151 //NOLINTNEXTLINE(misc-definitions-in-headers)
0152 UInt ValueIteratorBase::index() const {
0153 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0154   const Value::CZString czstring = (*current_).first;
0155   if (!czstring.c_str())
0156     return czstring.index();
0157   return Value::UInt(-1);
0158 #else
0159   if (isArray_)
0160     return Value::UInt(ValueInternalArray::indexOf(iterator_.array_));
0161   return Value::UInt(-1);
0162 #endif
0163 }
0164 
0165 //NOLINTNEXTLINE(misc-definitions-in-headers)
0166 const char *ValueIteratorBase::memberName() const {
0167 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0168   const char *name = (*current_).first.c_str();
0169   return name ? name : "";
0170 #else
0171   if (!isArray_)
0172     return ValueInternalMap::key(iterator_.map_);
0173   return "";
0174 #endif
0175 }
0176 
0177 // //////////////////////////////////////////////////////////////////
0178 // //////////////////////////////////////////////////////////////////
0179 // //////////////////////////////////////////////////////////////////
0180 // class ValueConstIterator
0181 // //////////////////////////////////////////////////////////////////
0182 // //////////////////////////////////////////////////////////////////
0183 // //////////////////////////////////////////////////////////////////
0184 
0185 //NOLINTNEXTLINE(misc-definitions-in-headers)
0186 ValueConstIterator::ValueConstIterator() {}
0187 
0188 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0189 //NOLINTNEXTLINE(misc-definitions-in-headers)
0190 ValueConstIterator::ValueConstIterator(const Value::ObjectValues::iterator &current) : ValueIteratorBase(current) {}
0191 #else
0192 //NOLINTNEXTLINE(misc-definitions-in-headers)
0193 ValueConstIterator::ValueConstIterator(const ValueInternalArray::IteratorState &state) : ValueIteratorBase(state) {}
0194 
0195 //NOLINTNEXTLINE(misc-definitions-in-headers)
0196 ValueConstIterator::ValueConstIterator(const ValueInternalMap::IteratorState &state) : ValueIteratorBase(state) {}
0197 #endif
0198 
0199 //NOLINTNEXTLINE(misc-definitions-in-headers)
0200 ValueConstIterator &ValueConstIterator::operator=(const ValueIteratorBase &other) {
0201   copy(other);
0202   return *this;
0203 }
0204 
0205 // //////////////////////////////////////////////////////////////////
0206 // //////////////////////////////////////////////////////////////////
0207 // //////////////////////////////////////////////////////////////////
0208 // class ValueIterator
0209 // //////////////////////////////////////////////////////////////////
0210 // //////////////////////////////////////////////////////////////////
0211 // //////////////////////////////////////////////////////////////////
0212 
0213 //NOLINTNEXTLINE(misc-definitions-in-headers)
0214 ValueIterator::ValueIterator() {}
0215 
0216 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0217 //NOLINTNEXTLINE(misc-definitions-in-headers)
0218 ValueIterator::ValueIterator(const Value::ObjectValues::iterator &current) : ValueIteratorBase(current) {}
0219 #else
0220 //NOLINTNEXTLINE(misc-definitions-in-headers)
0221 ValueIterator::ValueIterator(const ValueInternalArray::IteratorState &state) : ValueIteratorBase(state) {}
0222 
0223 //NOLINTNEXTLINE(misc-definitions-in-headers)
0224 ValueIterator::ValueIterator(const ValueInternalMap::IteratorState &state) : ValueIteratorBase(state) {}
0225 #endif
0226 
0227 //NOLINTNEXTLINE(misc-definitions-in-headers)
0228 ValueIterator::ValueIterator(const ValueConstIterator &other) : ValueIteratorBase(other) {}
0229 
0230 //NOLINTNEXTLINE(misc-definitions-in-headers)
0231 ValueIterator::ValueIterator(const ValueIterator &other) : ValueIteratorBase(other) {}
0232 
0233 //NOLINTNEXTLINE(misc-definitions-in-headers)
0234 ValueIterator &ValueIterator::operator=(const SelfType &other) {
0235   copy(other);
0236   return *this;
0237 }