Lines Matching refs:Value
8 #include <json/value.h>
28 // This is a walkaround to avoid the static initialization of Value::null.
36 static const unsigned char ALIGNAS(8) kNull[sizeof(Value)] = { 0 };
38 const Value& Value::null = reinterpret_cast<const Value&>(kNullRef);
40 const Int Value::minInt = Int(~(UInt(-1) / 2));
41 const Int Value::maxInt = Int(UInt(-1) / 2);
42 const UInt Value::maxUInt = UInt(-1);
44 const Int64 Value::minInt64 = Int64(~(UInt64(-1) / 2));
45 const Int64 Value::maxInt64 = Int64(UInt64(-1) / 2);
46 const UInt64 Value::maxUInt64 = UInt64(-1);
48 // converting Value::maxUInt64 to a double correctly (AIX/xlC).
52 const LargestInt Value::minLargestInt = LargestInt(~(LargestUInt(-1) / 2));
53 const LargestInt Value::maxLargestInt = LargestInt(LargestUInt(-1) / 2);
54 const LargestUInt Value::maxLargestUInt = LargestUInt(-1);
65 static inline double integerToDouble(Json::UInt64 value) {
66 return static_cast<double>(Int64(value / 2)) * 2.0 + Int64(value & 1);
69 template <typename T> static inline double integerToDouble(T value) {
70 return static_cast<double>(value);
79 /** Duplicates the specified string value.
80 * @param value Pointer to the string to duplicate. Must be zero-terminated if
82 * @param length Length of the value. if equals to unknown, then it will be
83 * computed using strlen(value).
86 static inline char* duplicateStringValue(const char* value,
89 length = (unsigned int)strlen(value);
92 // to a sane value.
93 if (length >= (unsigned)Value::maxInt)
94 length = Value::maxInt - 1;
98 "in Json::Value::duplicateStringValue(): "
99 "Failed to allocate string value buffer");
100 memcpy(newString, value, length);
107 static inline void releaseStringValue(char* value) { free(value); }
132 // class Value::CommentInfo
137 Value::CommentInfo::CommentInfo() : comment_(0) {}
139 Value::CommentInfo::~CommentInfo() {
144 void Value::CommentInfo::setComment(const char* text) {
150 "in Json::Value::setComment(): Comments must start with /");
158 // class Value::CZString
167 Value::CZString::CZString(ArrayIndex index) : cstr_(0), index_(index) {}
169 Value::CZString::CZString(const char* cstr, DuplicationPolicy allocate)
173 Value::CZString::CZString(const CZString& other)
182 Value::CZString::~CZString() {
187 void Value::CZString::swap(CZString& other) {
192 Value::CZString& Value::CZString::operator=(CZString other) {
197 bool Value::CZString::operator<(const CZString& other) const {
203 bool Value::CZString::operator==(const CZString& other) const {
209 ArrayIndex Value::CZString::index() const { return index_; }
211 const char* Value::CZString::c_str() const { return cstr_; }
213 bool Value::CZString::isStaticString() const { return index_ == noDuplication; }
220 // class Value::Value
226 * memset( this, 0, sizeof(Value) )
229 Value::Value(ValueType type) {
265 Value::Value(Int value) {
267 value_.int_ = value;
270 Value::Value(UInt value) {
272 value_.uint_ = value;
275 Value::Value(Int64 value) {
277 value_.int_ = value;
279 Value::Value(UInt64 value) {
281 value_.uint_ = value;
285 Value::Value(double value) {
287 value_.real_ = value;
290 Value::Value(const char* value) {
292 value_.string_ = duplicateStringValue(value);
295 Value::Value(const char* beginValue, const char* endValue) {
301 Value::Value(const std::string& value) {
304 duplicateStringValue(value.c_str(), (unsigned int)value.length());
307 Value::Value(const StaticString& value) {
309 value_.string_ = const_cast<char*>(value.c_str());
313 Value::Value(const CppTL::ConstString& value) {
315 value_.string_ = duplicateStringValue(value, value.length());
319 Value::Value(bool value) {
321 value_.bool_ = value;
324 Value::Value(const Value& other)
375 Value::~Value() {
408 Value& Value::operator=(Value other) {
413 void Value::swap(Value& other) {
425 ValueType Value::type() const { return type_; }
427 int Value::compare(const Value& other) const {
435 bool Value::operator<(const Value& other) const {
474 bool Value::operator<=(const Value& other) const { return !(other < *this); }
476 bool Value::operator>=(const Value& other) const { return !(*this < other); }
478 bool Value::operator>(const Value& other) const { return other < *this; }
480 bool Value::operator==(const Value& other) const {
483 // attempt to take address of bit-field structure member `Json::Value::type_'
520 bool Value::operator!=(const Value& other) const { return !(*this == other); }
522 const char* Value::asCString() const {
524 "in Json::Value::asCString(): requires stringValue");
528 std::string Value::asString() const {
548 CppTL::ConstString Value::asConstString() const {
553 Value::Int Value
572 JSON_FAIL_MESSAGE("Value is not convertible to Int.");
575 Value::UInt Value::asUInt() const {
594 JSON_FAIL_MESSAGE("Value is not convertible to UInt.");
599 Value::Int64 Value::asInt64() const {
617 JSON_FAIL_MESSAGE("Value is not convertible to Int64.");
620 Value::UInt64 Value::asUInt64() const {
638 JSON_FAIL_MESSAGE("Value is not convertible to UInt64.");
642 LargestInt Value::asLargestInt() const {
650 LargestUInt Value::asLargestUInt() const {
658 double Value::asDouble() const {
677 JSON_FAIL_MESSAGE("Value is not convertible to double.");
680 float Value::asFloat() const {
699 JSON_FAIL_MESSAGE("Value is not convertible to float.");
702 bool Value::asBool() const {
717 JSON_FAIL_MESSAGE("Value is not convertible to bool.");
720 bool Value::isConvertibleTo(ValueType other) const {
754 ArrayIndex Value::size() const {
784 bool Value::empty() const {
791 bool Value::operator!() const { return isNull(); }
793 void Value::clear() {
796 "in Json::Value::clear(): requires complex value");
818 void Value::resize(ArrayIndex newSize) {
820 "in Json::Value::resize(): requires arrayValue");
822 *this = Value(arrayValue);
840 Value& Value::operator[](ArrayIndex index) {
843 "in Json::Value::operator[](ArrayIndex): requires arrayValue");
845 *this = Value(arrayValue);
860 Value& Value::operator[](int index) {
863 "in Json::Value::operator[](int index): index cannot be negative");
867 const Value& Value::operator[](ArrayIndex index) const {
870 "in Json::Value::operator[](ArrayIndex)const: requires arrayValue");
880 Value* value = value_.array_->find(index);
881 return value ? *value : null;
885 const Value& Value::operator[](int index) const {
888 "in Json::Value::operator[](int index) const: index cannot be negative");
892 Value& Value::operator[](const char* key) {
896 void Value::initBasic(ValueType type, bool allocated) {
907 Value& Value::resolveReference(const char* key, bool isStatic) {
910 "in Json::Value::resolveReference(): requires objectValue");
912 *this = Value(objectValue);
922 Value& value = (*it).second;
923 return value;
929 Value Value::get(ArrayIndex index, const Value& defaultValue) const {
930 const Value* value = &((*this)[index]);
931 return value == &null ? defaultValue : *value;
934 bool Value::isValidIndex(ArrayIndex index) const { return index < size(); }
936 const Value& Value::operator[](const char* key) const {
939 "in Json::Value::operator[](char const*)const: requires objectValue");
949 const Value* value = value_.map_->find(key);
950 return value ? *value : null;
954 Value& Value::operator[](const std::string& key) {
958 const Value& Value::operator[](const std::string& key) const {
962 Value& Value::operator[](const StaticString& key) {
967 Value& Value::operator[](const CppTL::ConstString& key) {
971 const Value& Value::operator[](const CppTL::ConstString& key) const {
976 Value& Value::append(const Value& value) { return (*this)[size()] = value; }
978 Value Value::get(const char* key, const Value& defaultValue) const {
979 const Value* value = &((*this)[key]);
980 return value == &null ? defaultValue : *value;
983 Value Value::get(const std::string& key, const Value& defaultValue) const {
987 Value Value::removeMember(const char* key) {
989 "in Json::Value::removeMember(): requires objectValue");
997 Value old(it->second);
1001 Value* value = value_.map_->find(key);
1002 if (value) {
1003 Value old(*value);
1012 Value Value::removeMember(const std::string& key) {
1017 Value Value::get(const CppTL::ConstString& key,
1018 const Value& defaultValue) const {
1023 bool Value::isMember(const char* key) const {
1024 const Value* value = &((*this)[key]);
1025 return value != &null;
1028 bool Value::isMember(const std::string& key) const {
1033 bool Value::isMember(const CppTL::ConstString& key) const {
1038 Value::Members Value::getMemberNames() const {
1041 "in Json::Value::getMemberNames(), value must be objectValue");
1043 return Value::Members();
1064 // Value::enumMemberNames() const
1077 // Value::enumValues() const
1081 // CppTL::Type<const Value &>() );
1092 bool Value::isNull() const { return type_ == nullValue; }
1094 bool Value::isBool() const { return type_ == booleanValue; }
1096 bool Value::isInt() const {
1111 bool Value::isUInt() const {
1126 bool Value::isInt64() const {
1136 // require the value to be strictly less than the limit.
1146 bool Value::isUInt64() const {
1156 // require the value to be strictly less than the limit.
1166 bool Value::isIntegral() const {
1174 bool Value::isDouble() const { return type_ == realValue || isIntegral(); }
1176 bool Value::isNumeric() const { return isIntegral() || isDouble(); }
1178 bool Value::isString() const { return type_ == stringValue; }
1180 bool Value::isArray() const { return type_ == arrayValue; }
1182 bool Value::isObject() const { return type_ == objectValue; }
1184 void Value::setComment(const char* comment, CommentPlacement placement) {
1190 void Value::setComment(const std::string& comment, CommentPlacement placement) {
1194 bool Value::hasComment(CommentPlacement placement) const {
1198 std::string Value::getComment(CommentPlacement placement) const {
1204 void Value::setOffsetStart(size_t start) { start_ = start; }
1206 void Value::setOffsetLimit(size_t limit) { limit_ = limit; }
1208 size_t Value::getOffsetStart() const { return start_; }
1210 size_t Value::getOffsetLimit() const { return limit_; }
1212 std::string Value::toStyledString() const {
1217 Value::const_iterator Value::begin() const {
1247 Value::const_iterator Value::end() const {
1277 Value::iterator Value::begin() {
1307 Value::iterator Value::end() {
1417 const Value& Path::resolve(const Value& root) const {
1418 const Value* node = &root;
1423 // Error: unable to resolve path (array value expected at position...
1428 // Error: unable to resolve path (object value expected at position...)
1431 if (node == &Value::null) {
1440 Value Path::resolve(const Value& root, const Value& defaultValue) const {
1441 const Value* node = &root;
1452 if (node == &Value::null)
1459 Value& Path::make(Value& root) const {
1460 Value* node = &root;