Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-17 23:57:26

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