6 #if !defined(JSON_IS_AMALGAMATION)
10 #endif // if !defined(JSON_IS_AMALGAMATION)
21 #if defined(_MSC_VER) && _MSC_VER < 1900
24 const char* format, va_list ap) {
27 count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
29 count = _vscprintf(format, ap);
34 const char* format, ...) {
45 #pragma warning(disable : 4702)
48 #define JSON_ASSERT_UNREACHABLE assert(false)
52 static std::unique_ptr<T>
cloneUnique(
const std::unique_ptr<T>& p) {
55 r = std::unique_ptr<T>(
new T(*p));
63 #if defined(__ARMEL__)
64 #define ALIGNAS(byte_alignment) __attribute__((aligned(byte_alignment)))
66 #define ALIGNAS(byte_alignment)
71 static Value const nullStatic;
85 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
86 template <
typename T,
typename U>
87 static inline bool InRange(
double d, T min, U max) {
90 return d >=
static_cast<double>(min) && d <= static_cast<double>(max) &&
91 !(
static_cast<U
>(d) == min && d != static_cast<double>(min));
93 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
94 static inline double integerToDouble(
Json::UInt64 value) {
95 return static_cast<double>(
Int64(value / 2)) * 2.0 +
96 static_cast<double>(
Int64(value & 1));
99 template <
typename T>
static inline double integerToDouble(T value) {
100 return static_cast<double>(value);
103 template <
typename T,
typename U>
104 static inline bool InRange(
double d, T min, U max) {
105 return d >= integerToDouble(min) && d <= integerToDouble(max) &&
106 !(
static_cast<U
>(d) == min && d != integerToDouble(min));
108 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
123 auto newString =
static_cast<char*
>(malloc(length + 1));
124 if (newString ==
nullptr) {
125 throwRuntimeError(
"in Json::Value::duplicateStringValue(): "
126 "Failed to allocate string value buffer");
128 memcpy(newString, value, length);
129 newString[length] = 0;
136 unsigned int length) {
140 sizeof(
unsigned) - 1U,
141 "in Json::Value::duplicateAndPrefixStringValue(): "
142 "length too big for prefixing");
143 size_t actualLength =
sizeof(length) + length + 1;
144 auto newString =
static_cast<char*
>(malloc(actualLength));
145 if (newString ==
nullptr) {
146 throwRuntimeError(
"in Json::Value::duplicateAndPrefixStringValue(): "
147 "Failed to allocate string value buffer");
149 *
reinterpret_cast<unsigned*
>(newString) = length;
150 memcpy(newString +
sizeof(
unsigned), value, length);
151 newString[actualLength - 1U] =
156 unsigned* length,
char const** value) {
158 *length =
static_cast<unsigned>(strlen(prefixed));
161 *length = *
reinterpret_cast<unsigned const*
>(prefixed);
162 *value = prefixed +
sizeof(unsigned);
168 #if JSONCPP_USE_SECURE_MEMORY
171 char const* valueDecoded;
173 size_t const size =
sizeof(unsigned) + length + 1U;
174 memset(value, 0, size);
179 size_t size = (length == 0) ? strlen(value) : length;
180 memset(value, 0, size);
183 #else // !JSONCPP_USE_SECURE_MEMORY
186 #endif // JSONCPP_USE_SECURE_MEMORY
210 return "stringValue";
212 return "booleanValue";
216 return "objectValue";
223 #if !defined(JSON_IS_AMALGAMATION)
226 #endif // if !defined(JSON_IS_AMALGAMATION)
230 #if JSON_USE_EXCEPTION
233 char const*
Exception::what() const noexcept {
return msg_.c_str(); }
240 throw LogicError(msg);
242 #else // !JSON_USE_EXCEPTION
244 std::cerr << msg << std::endl;
248 std::cerr << msg << std::endl;
264 Value::CZString::CZString(
ArrayIndex index) : cstr_(nullptr), index_(index) {}
266 Value::CZString::CZString(
char const* str,
unsigned length,
267 DuplicationPolicy allocate)
270 storage_.policy_ = allocate & 0x3;
271 storage_.length_ = length & 0x3FFFFFFF;
274 Value::CZString::CZString(
const CZString& other) {
275 cstr_ = (other.storage_.policy_ != noDuplication && other.cstr_ !=
nullptr
280 static_cast<unsigned>(
282 ? (
static_cast<DuplicationPolicy
>(other.storage_.policy_) ==
286 :
static_cast<DuplicationPolicy
>(other.storage_.policy_)) &
288 storage_.length_ = other.storage_.length_;
290 index_ = other.index_;
294 Value::CZString::CZString(CZString&& other) noexcept : cstr_(other.cstr_) {
296 storage_.policy_ = other.storage_.policy_;
297 storage_.length_ = other.storage_.length_;
299 index_ = other.index_;
301 other.cstr_ =
nullptr;
304 Value::CZString::~CZString() {
305 if (cstr_ && storage_.policy_ == duplicate) {
307 storage_.length_ + 1U);
319 Value::CZString& Value::CZString::operator=(
const CZString& other) {
321 index_ = other.index_;
325 Value::CZString& Value::CZString::operator=(CZString&& other) noexcept {
326 if (cstr_ && storage_.policy_ == duplicate) {
331 storage_.policy_ = other.storage_.policy_;
332 storage_.length_ = other.storage_.length_;
334 index_ = other.index_;
336 other.cstr_ =
nullptr;
340 bool Value::CZString::operator<(
const CZString& other)
const {
342 return index_ < other.index_;
345 unsigned this_len = this->storage_.length_;
346 unsigned other_len = other.storage_.length_;
347 unsigned min_len = std::min<unsigned>(this_len, other_len);
349 int comp = memcmp(this->cstr_, other.cstr_, min_len);
354 return (this_len < other_len);
359 return index_ == other.index_;
362 unsigned this_len = this->storage_.length_;
363 unsigned other_len = other.storage_.length_;
364 if (this_len != other_len)
367 int comp = memcmp(this->cstr_, other.cstr_, this_len);
371 ArrayIndex Value::CZString::index()
const {
return index_; }
374 const char* Value::CZString::data()
const {
return cstr_; }
375 unsigned Value::CZString::length()
const {
return storage_.length_; }
376 bool Value::CZString::isStaticString()
const {
377 return storage_.policy_ == noDuplication;
393 static char const emptyString[] =
"";
407 value_.string_ =
const_cast<char*
>(
static_cast<char const*
>(emptyString));
411 value_.map_ =
new ObjectValues();
414 value_.bool_ =
false;
428 value_.uint_ = value;
430 #if defined(JSON_HAS_INT64)
437 value_.uint_ = value;
439 #endif // defined(JSON_HAS_INT64)
441 Value::Value(
double value) {
443 value_.real_ = value;
446 Value::Value(
const char* value) {
449 "Null Value Passed to Value Constructor");
451 value, static_cast<unsigned>(strlen(value)));
454 Value::Value(
const char* begin,
const char* end) {
463 value.data(),
static_cast<unsigned>(value.length()));
468 value_.string_ =
const_cast<char*
>(value.
c_str());
471 Value::Value(
bool value) {
473 value_.bool_ = value;
481 Value::Value(
Value&& other) noexcept {
501 void Value::swapPayload(
Value& other) {
506 void Value::copyPayload(
const Value& other) {
518 void Value::copy(
const Value& other) {
524 return static_cast<ValueType>(bits_.value_type_);
527 int Value::compare(
const Value& other)
const {
535 bool Value::operator<(
const Value& other)
const {
536 int typeDelta = type() - other.
type();
538 return typeDelta < 0;
543 return value_.int_ < other.value_.int_;
545 return value_.uint_ < other.value_.uint_;
547 return value_.real_ < other.value_.real_;
549 return value_.bool_ < other.value_.bool_;
551 if ((value_.string_ ==
nullptr) || (other.value_.string_ ==
nullptr)) {
552 return other.value_.string_ !=
nullptr;
556 char const* this_str;
557 char const* other_str;
562 unsigned min_len = std::min<unsigned>(this_len, other_len);
564 int comp = memcmp(this_str, other_str, min_len);
569 return (this_len < other_len);
573 auto thisSize = value_.map_->size();
574 auto otherSize = other.value_.map_->size();
575 if (thisSize != otherSize)
576 return thisSize < otherSize;
577 return (*value_.map_) < (*other.value_.map_);
585 bool Value::operator<=(
const Value& other)
const {
return !(other < *
this); }
587 bool Value::operator>=(
const Value& other)
const {
return !(*
this < other); }
589 bool Value::operator>(
const Value& other)
const {
return other < *
this; }
592 if (type() != other.
type())
598 return value_.int_ == other.value_.int_;
600 return value_.uint_ == other.value_.uint_;
602 return value_.real_ == other.value_.real_;
604 return value_.bool_ == other.value_.bool_;
606 if ((value_.string_ ==
nullptr) || (other.value_.string_ ==
nullptr)) {
607 return (value_.string_ == other.value_.string_);
611 char const* this_str;
612 char const* other_str;
617 if (this_len != other_len)
620 int comp = memcmp(this_str, other_str, this_len);
625 return value_.map_->size() == other.value_.map_->size() &&
626 (*value_.map_) == (*other.value_.map_);
635 const char* Value::asCString()
const {
637 "in Json::Value::asCString(): requires stringValue");
638 if (value_.string_ ==
nullptr)
641 char const* this_str;
647 #if JSONCPP_USE_SECURE_MEMORY
648 unsigned Value::getCStringLength()
const {
650 "in Json::Value::asCString(): requires stringValue");
651 if (value_.string_ == 0)
654 char const* this_str;
661 bool Value::getString(
char const** begin,
char const** end)
const {
664 if (value_.string_ ==
nullptr)
669 *end = *begin + length;
678 if (value_.string_ ==
nullptr)
681 char const* this_str;
684 return String(this_str, this_len);
687 return value_.bool_ ?
"true" :
"false";
703 return Int(value_.int_);
706 return Int(value_.uint_);
709 "double out of Int range");
710 return Int(value_.real_);
714 return value_.bool_ ? 1 : 0;
725 return UInt(value_.int_);
728 return UInt(value_.uint_);
731 "double out of UInt range");
732 return UInt(value_.real_);
736 return value_.bool_ ? 1 : 0;
743 #if defined(JSON_HAS_INT64)
748 return Int64(value_.int_);
751 return Int64(value_.uint_);
756 value_.real_ != minInt64,
757 "Double value is minInt64, precise value cannot be determined");
759 "double out of Int64 range");
760 return Int64(value_.real_);
764 return value_.bool_ ? 1 : 0;
775 return UInt64(value_.int_);
777 return UInt64(value_.uint_);
780 "double out of UInt64 range");
781 return UInt64(value_.real_);
785 return value_.bool_ ? 1 : 0;
791 #endif // if defined(JSON_HAS_INT64)
794 #if defined(JSON_NO_INT64)
802 #if defined(JSON_NO_INT64)
809 double Value::asDouble()
const {
812 return static_cast<double>(value_.int_);
814 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
815 return static_cast<double>(value_.uint_);
816 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
817 return integerToDouble(value_.uint_);
818 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
824 return value_.bool_ ? 1.0 : 0.0;
831 float Value::asFloat()
const {
834 return static_cast<float>(value_.int_);
836 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
837 return static_cast<float>(value_.uint_);
838 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
840 return static_cast<float>(integerToDouble(value_.uint_));
841 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
843 return static_cast<float>(value_.real_);
847 return value_.bool_ ? 1.0F : 0.0F;
854 bool Value::asBool()
const {
861 return value_.int_ != 0;
863 return value_.uint_ != 0;
866 const auto value_classification = std::fpclassify(value_.real_);
867 return value_classification != FP_ZERO && value_classification != FP_NAN;
878 return (isNumeric() && asDouble() == 0.0) ||
881 (type() ==
arrayValue && value_.map_->empty()) ||
919 if (!value_.map_->empty()) {
920 ObjectValues::const_iterator itLast = value_.map_->end();
922 return (*itLast).first.index() + 1;
932 bool Value::empty()
const {
933 if (isNull() || isArray() || isObject())
938 Value::operator bool()
const {
return !isNull(); }
940 void Value::clear() {
943 "in Json::Value::clear(): requires complex value");
949 value_.map_->clear();
959 "in Json::Value::resize(): requires arrayValue, but found "
966 else if (newSize > oldSize)
967 for (
ArrayIndex i = oldSize; i < newSize; ++i)
970 for (
ArrayIndex index = newSize; index < oldSize; ++index) {
971 value_.map_->erase(index);
980 "in Json::Value::operator[](ArrayIndex): requires arrayValue");
984 auto it = value_.map_->lower_bound(key);
985 if (it != value_.map_->end() && (*it).first == key)
988 ObjectValues::value_type defaultValue(key, nullSingleton());
989 it = value_.map_->insert(it, defaultValue);
993 Value& Value::operator[](
int index) {
996 "in Json::Value::operator[](int index): index cannot be negative");
1003 "in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
1005 return nullSingleton();
1006 CZString key(index);
1007 ObjectValues::const_iterator it = value_.map_->find(key);
1008 if (it == value_.map_->end())
1009 return nullSingleton();
1010 return (*it).second;
1013 const Value& Value::operator[](
int index)
const {
1016 "in Json::Value::operator[](int index) const: index cannot be negative");
1020 void Value::initBasic(
ValueType type,
bool allocated) {
1022 setIsAllocated(allocated);
1023 comments_ = Comments{};
1028 void Value::dupPayload(
const Value& other) {
1029 setType(other.type());
1030 setIsAllocated(
false);
1037 value_ = other.value_;
1040 if (other.value_.string_ && other.isAllocated()) {
1046 setIsAllocated(
true);
1048 value_.string_ = other.value_.string_;
1053 value_.map_ =
new ObjectValues(*other.value_.map_);
1060 void Value::releasePayload() {
1081 void Value::dupMeta(
const Value& other) {
1082 comments_ = other.comments_;
1083 start_ = other.start_;
1084 limit_ = other.limit_;
1090 Value& Value::resolveReference(
const char* key) {
1093 "in Json::Value::resolveReference(): requires objectValue, but found "
1097 CZString actualKey(key, static_cast<unsigned>(strlen(key)),
1098 CZString::noDuplication);
1099 auto it = value_.map_->lower_bound(actualKey);
1100 if (it != value_.map_->end() && (*it).first == actualKey)
1101 return (*it).second;
1103 ObjectValues::value_type defaultValue(actualKey, nullSingleton());
1104 it = value_.map_->insert(it, defaultValue);
1105 Value& value = (*it).second;
1110 Value& Value::resolveReference(
char const* key,
char const* end) {
1112 "in Json::Value::resolveReference(key, end): requires "
1113 "objectValue, but found "
1117 CZString actualKey(key, static_cast<unsigned>(end - key),
1118 CZString::duplicateOnCopy);
1119 auto it = value_.map_->lower_bound(actualKey);
1120 if (it != value_.map_->end() && (*it).first == actualKey)
1121 return (*it).second;
1123 ObjectValues::value_type defaultValue(actualKey, nullSingleton());
1124 it = value_.map_->insert(it, defaultValue);
1125 Value& value = (*it).second;
1130 const Value* value = &((*this)[index]);
1131 return value == &nullSingleton() ? defaultValue : *value;
1134 bool Value::isValidIndex(
ArrayIndex index)
const {
return index < size(); }
1136 Value const* Value::find(
char const* begin,
char const* end)
const {
1138 "in Json::Value::find(begin, end): requires "
1139 "objectValue or nullValue");
1142 CZString actualKey(begin, static_cast<unsigned>(end - begin),
1143 CZString::noDuplication);
1144 ObjectValues::const_iterator it = value_.map_->find(actualKey);
1145 if (it == value_.map_->end())
1147 return &(*it).second;
1150 return find(key.data(), key.data() + key.length());
1154 return findValue<Value, &Value::isNull>(key);
1157 return findValue<Value, &Value::isBool>(key);
1160 return findValue<Value, &Value::isInt>(key);
1163 return findValue<Value, &Value::isInt64>(key);
1166 return findValue<Value, &Value::isUInt>(key);
1169 return findValue<Value, &Value::isUInt64>(key);
1172 return findValue<Value, &Value::isIntegral>(key);
1175 return findValue<Value, &Value::isDouble>(key);
1178 return findValue<Value, &Value::isNumeric>(key);
1181 return findValue<Value, &Value::isString>(key);
1184 return findValue<Value, &Value::isArray>(key);
1187 return findValue<Value, &Value::isObject>(key);
1190 Value* Value::demand(
char const* begin,
char const* end) {
1192 "in Json::Value::demand(begin, end): requires "
1193 "objectValue or nullValue");
1194 return &resolveReference(begin, end);
1196 const Value& Value::operator[](
const char* key)
const {
1197 Value const* found = find(key, key + strlen(key));
1199 return nullSingleton();
1203 Value const* found = find(key);
1205 return nullSingleton();
1209 Value& Value::operator[](
const char* key) {
1210 return resolveReference(key, key + strlen(key));
1214 return resolveReference(key.data(), key.data() + key.length());
1218 return resolveReference(key.
c_str());
1225 "in Json::Value::append: requires arrayValue, but found "
1230 return this->value_.map_->emplace(size(), std::move(value)).first->second;
1234 return insert(index,
Value(newValue));
1239 "in Json::Value::insert: requires arrayValue");
1241 if (index > length) {
1244 for (
ArrayIndex i = length; i > index; i--) {
1245 (*this)[i] = std::move((*
this)[i - 1]);
1247 (*this)[index] = std::move(newValue);
1251 Value Value::get(
char const* begin,
char const* end,
1252 Value const& defaultValue)
const {
1253 Value const* found = find(begin, end);
1254 return !found ? defaultValue : *found;
1256 Value Value::get(
char const* key, Value
const& defaultValue)
const {
1257 return get(key, key + strlen(key), defaultValue);
1259 Value Value::get(
String const& key, Value
const& defaultValue)
const {
1260 return get(key.data(), key.data() + key.length(), defaultValue);
1263 bool Value::removeMember(
const char* begin,
const char* end,
Value* removed) {
1267 CZString actualKey(begin, static_cast<unsigned>(end - begin),
1268 CZString::noDuplication);
1269 auto it = value_.map_->find(actualKey);
1270 if (it == value_.map_->end())
1273 *removed = std::move(it->second);
1274 value_.map_->erase(it);
1277 bool Value::removeMember(
const char* key,
Value* removed) {
1278 return removeMember(key, key + strlen(key), removed);
1281 return removeMember(key.data(), key.data() + key.length(), removed);
1284 void Value::removeMember(
const char* key) {
1287 "in Json::Value::removeMember(): requires objectValue, but found "
1292 CZString actualKey(key,
unsigned(strlen(key)), CZString::noDuplication);
1293 value_.map_->erase(actualKey);
1295 void Value::removeMember(
const String& key) { removeMember(key.c_str()); }
1301 CZString key(index);
1302 auto it = value_.map_->find(key);
1303 if (it == value_.map_->end()) {
1307 *removed = std::move(it->second);
1310 for (
ArrayIndex i = index; i < (oldSize - 1); ++i) {
1312 (*value_.map_)[keey] = (*
this)[i + 1];
1315 CZString keyLast(oldSize - 1);
1316 auto itLast = value_.map_->find(keyLast);
1317 value_.map_->erase(itLast);
1321 bool Value::isMember(
char const* begin,
char const* end)
const {
1322 Value const* value = find(begin, end);
1323 return nullptr != value;
1325 bool Value::isMember(
char const* key)
const {
1326 return isMember(key, key + strlen(key));
1328 bool Value::isMember(
String const& key)
const {
1329 return isMember(key.data(), key.data() + key.length());
1335 "in Json::Value::getMemberNames(), value must be objectValue");
1339 members.reserve(value_.map_->size());
1340 ObjectValues::const_iterator it = value_.map_->begin();
1341 ObjectValues::const_iterator itEnd = value_.map_->end();
1342 for (; it != itEnd; ++it) {
1343 members.push_back(
String((*it).first.data(), (*it).first.length()));
1349 double integral_part;
1350 return modf(d, &integral_part) == 0.0;
1357 bool Value::isInt()
const {
1360 #if defined(JSON_HAS_INT64)
1361 return value_.int_ >= minInt && value_.int_ <= maxInt;
1366 return value_.uint_ <=
UInt(maxInt);
1368 return value_.real_ >= minInt && value_.real_ <= maxInt &&
1376 bool Value::isUInt()
const {
1379 #if defined(JSON_HAS_INT64)
1382 return value_.int_ >= 0;
1385 #if defined(JSON_HAS_INT64)
1386 return value_.uint_ <= maxUInt;
1391 return value_.real_ >= 0 && value_.real_ <= maxUInt &&
1399 bool Value::isInt64()
const {
1400 #if defined(JSON_HAS_INT64)
1405 return value_.uint_ <=
UInt64(maxInt64);
1414 return value_.real_ > double(minInt64) && value_.real_ < double(maxInt64) &&
1419 #endif // JSON_HAS_INT64
1423 bool Value::isUInt64()
const {
1424 #if defined(JSON_HAS_INT64)
1427 return value_.int_ >= 0;
1434 return value_.real_ >= 0 && value_.real_ < maxUInt64AsDouble &&
1439 #endif // JSON_HAS_INT64
1443 bool Value::isIntegral()
const {
1449 #if defined(JSON_HAS_INT64)
1457 return value_.real_ > double(minInt64) &&
1458 value_.real_ < maxUInt64AsDouble &&
IsIntegral(value_.real_);
1460 return value_.real_ >= minInt && value_.real_ <= maxUInt &&
1462 #endif // JSON_HAS_INT64
1469 bool Value::isDouble()
const {
1473 bool Value::isNumeric()
const {
return isDouble(); }
1481 Value::Comments::Comments(
const Comments& that)
1484 Value::Comments::Comments(Comments&& that) noexcept
1485 : ptr_{std::move(that.ptr_)} {}
1487 Value::Comments& Value::Comments::operator=(
const Comments& that) {
1492 Value::Comments& Value::Comments::operator=(Comments&& that) noexcept {
1493 ptr_ = std::move(that.ptr_);
1498 return ptr_ && !(*ptr_)[slot].empty();
1504 return (*ptr_)[slot];
1511 ptr_ = std::unique_ptr<Array>(
new Array());
1512 (*ptr_)[slot] = std::move(comment);
1516 if (!comment.empty() && (comment.back() ==
'\n')) {
1521 comment.empty() || comment[0] ==
'/',
1522 "in Json::Value::setComment(): Comments must start with /");
1523 comments_.set(placement, std::move(comment));
1527 return comments_.has(placement);
1531 return comments_.get(placement);
1583 return iterator(value_.map_->begin());
1596 return iterator(value_.map_->end());
1610 : index_(index), kind_(kindIndex) {}
1632 void Path::makePath(
const String& path,
const InArgs& in) {
1633 const char* current = path.c_str();
1634 const char* end = current + path.length();
1635 auto itInArg = in.begin();
1636 while (current != end) {
1637 if (*current ==
'[') {
1639 if (*current ==
'%')
1640 addPathInArg(path, in, itInArg, PathArgument::kindIndex);
1643 for (; current != end && *current >=
'0' && *current <=
'9'; ++current)
1644 index = index * 10 +
ArrayIndex(*current -
'0');
1645 args_.push_back(index);
1647 if (current == end || *++current !=
']')
1648 invalidPath(path,
int(current - path.c_str()));
1649 }
else if (*current ==
'%') {
1650 addPathInArg(path, in, itInArg, PathArgument::kindKey);
1652 }
else if (*current ==
'.' || *current ==
']') {
1655 const char* beginName = current;
1656 while (current != end && !strchr(
"[.", *current))
1658 args_.push_back(
String(beginName, current));
1663 void Path::addPathInArg(
const String& ,
const InArgs& in,
1664 InArgs::const_iterator& itInArg,
1665 PathArgument::Kind kind) {
1666 if (itInArg == in.end()) {
1668 }
else if ((*itInArg)->kind_ != kind) {
1671 args_.push_back(**itInArg++);
1675 void Path::invalidPath(
const String& ,
int ) {
1680 const Value* node = &root;
1681 for (
const auto& arg : args_) {
1682 if (arg.kind_ == PathArgument::kindIndex) {
1687 node = &((*node)[arg.index_]);
1688 }
else if (arg.kind_ == PathArgument::kindKey) {
1693 node = &((*node)[arg.key_]);
1705 const Value* node = &root;
1706 for (
const auto& arg : args_) {
1707 if (arg.kind_ == PathArgument::kindIndex) {
1709 return defaultValue;
1710 node = &((*node)[arg.index_]);
1711 }
else if (arg.kind_ == PathArgument::kindKey) {
1713 return defaultValue;
1714 node = &((*node)[arg.key_]);
1716 return defaultValue;
1723 Value* node = &root;
1724 for (
const auto& arg : args_) {
1725 if (arg.kind_ == PathArgument::kindIndex) {
1729 node = &((*node)[arg.index_]);
1730 }
else if (arg.kind_ == PathArgument::kindKey) {
1734 node = &((*node)[arg.key_]);
bool hasComment(CommentPlacement placement) const
LogicError(String const &msg)
Value & make(Value &root) const
Creates the "path" to access the specified node and returns a reference on the node.
static bool IsIntegral(double d)
#define JSON_API
If defined, indicates that the source file is amalgamated to prevent private header inclusion...
~Exception() noexcept override
#define JSON_ASSERT_MESSAGE(condition, message)
array value (ordered list)
String valueToString(Int value)
int msvc_pre1900_c99_snprintf(char *outBuf, size_t size, const char *format,...)
static Value const & nullSingleton()
Json::LargestUInt LargestUInt
#define JSON_FAIL_MESSAGE(message)
void setComment(const char *comment, size_t len, CommentPlacement placement)
Comments must be //... or /* ... */.
object value (collection of name/value pairs).
static std::unique_ptr< T > cloneUnique(const std::unique_ptr< T > &p)
static constexpr Int maxInt
Maximum signed int value that can be stored in a Json::Value.
Lightweight wrapper to tag static string.
std::basic_string< char, std::char_traits< char >, Allocator< char >> String
String getComment(CommentPlacement placement) const
Include delimiters and embedded newlines.
static void releaseStringValue(char *value, unsigned)
static const char * valueTypeToString(ValueType type)
const iterator for object and array value.
Experimental and untested: represents an element of the "path" to access a node.
static bool InRange(double d, T min, U max)
static void decodePrefixedString(bool isPrefixed, char const *prefixed, unsigned *length, char const **value)
std::vector< String > Members
void swap(Value &a, Value &b)
String toStyledString() const
String writeString(StreamWriter::Factory const &factory, Value const &root)
Write into stringstream, then return string, for convenience.
JSON (JavaScript Object Notation).
ValueConstIterator const_iterator
bool operator==(const SecureAllocator< T > &, const SecureAllocator< U > &)
void swap(Value &other)
Swap everything.
const char * c_str() const
const Value & resolve(const Value &root) const
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
Json::LargestInt LargestInt
static char * duplicateAndPrefixStringValue(const char *value, unsigned int length)
#define JSON_ASSERT_UNREACHABLE
static const Value & nullRef
void setOffsetStart(ptrdiff_t start)
ptrdiff_t getOffsetStart() const
static char * duplicateStringValue(const char *value, size_t length)
Duplicates the specified string value.
Exceptions which the user cannot easily avoid.
Iterator for object and array value.
static void releasePrefixedStringValue(char *value)
Free the string duplicated by duplicateStringValue()/duplicateAndPrefixStringValue().
ptrdiff_t getOffsetLimit() const
void setOffsetLimit(ptrdiff_t limit)
RuntimeError(String const &msg)
ValueType
Type of the value held by a Value object.
static int msvc_pre1900_c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
Json::ArrayIndex ArrayIndex
Path(const String &path, const PathArgument &a1=PathArgument(), const PathArgument &a2=PathArgument(), const PathArgument &a3=PathArgument(), const PathArgument &a4=PathArgument(), const PathArgument &a5=PathArgument())
static const Value & null
bool operator!=(const SecureAllocator< T > &, const SecureAllocator< U > &)
a comment placed on the line before a value
#define JSON_ASSERT(condition)
It should not be possible for a maliciously designed file to cause an abort() or seg-fault, so these macros are used only for pre-condition violations and internal logic errors.
const_iterator begin() const
Build a StreamWriter implementation.
Base class for all exceptions we throw.
#define JSONCPP_VERSION_STRING
const_iterator end() const