File indexing completed on 2024-04-06 12:11:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0025 ValueIteratorBase::ValueIteratorBase(const Value::ObjectValues::iterator ¤t)
0026 : current_(current), isNull_(false) {
0027 }
0028 #else
0029
0030 ValueIteratorBase::ValueIteratorBase(const ValueInternalArray::IteratorState &state) : isArray_(true) {
0031 iterator_.array_ = state;
0032 }
0033
0034
0035 ValueIteratorBase::ValueIteratorBase(const ValueInternalMap::IteratorState &state) : isArray_(false) {
0036 iterator_.map_ = state;
0037 }
0038 #endif
0039
0040
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
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
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
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
0080
0081
0082
0083
0084 if (isNull_ && other.isNull_) {
0085 return 0;
0086 }
0087
0088
0089
0090
0091
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
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
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
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
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
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
0181
0182
0183
0184
0185
0186 ValueConstIterator::ValueConstIterator() {}
0187
0188 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0189
0190 ValueConstIterator::ValueConstIterator(const Value::ObjectValues::iterator ¤t) : ValueIteratorBase(current) {}
0191 #else
0192
0193 ValueConstIterator::ValueConstIterator(const ValueInternalArray::IteratorState &state) : ValueIteratorBase(state) {}
0194
0195
0196 ValueConstIterator::ValueConstIterator(const ValueInternalMap::IteratorState &state) : ValueIteratorBase(state) {}
0197 #endif
0198
0199
0200 ValueConstIterator &ValueConstIterator::operator=(const ValueIteratorBase &other) {
0201 copy(other);
0202 return *this;
0203 }
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214 ValueIterator::ValueIterator() {}
0215
0216 #ifndef JSON_VALUE_USE_INTERNAL_MAP
0217
0218 ValueIterator::ValueIterator(const Value::ObjectValues::iterator ¤t) : ValueIteratorBase(current) {}
0219 #else
0220
0221 ValueIterator::ValueIterator(const ValueInternalArray::IteratorState &state) : ValueIteratorBase(state) {}
0222
0223
0224 ValueIterator::ValueIterator(const ValueInternalMap::IteratorState &state) : ValueIteratorBase(state) {}
0225 #endif
0226
0227
0228 ValueIterator::ValueIterator(const ValueConstIterator &other) : ValueIteratorBase(other) {}
0229
0230
0231 ValueIterator::ValueIterator(const ValueIterator &other) : ValueIteratorBase(other) {}
0232
0233
0234 ValueIterator &ValueIterator::operator=(const SelfType &other) {
0235 copy(other);
0236 return *this;
0237 }