Lines Matching refs:Value
31 static_cast<size_t>(Value::Type::LIST) + 1,
34 std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node);
39 std::unique_ptr<Value> CopyListWithoutEmptyChildren(const Value& list) {
40 Value copy(Value::Type::LIST);
42 std::unique_ptr<Value> child_copy = CopyWithoutEmptyChildren(entry);
47 : std::make_unique<Value>(std::move(copy));
54 std::unique_ptr<Value> child_copy = CopyWithoutEmptyChildren(it.value());
64 std::unique_ptr<Value> CopyWithoutEmptyChildren(const Value& node) {
66 case Value::Type::LIST:
69 case Value::Type::DICTIONARY:
74 return std::make_unique<Value>(node.Clone());
81 std::unique_ptr<Value> Value::CreateWithCopiedBuffer(const char* buffer,
83 return std::make_unique<Value>(BlobStorage(buffer, buffer + size));
87 Value Value::FromUniquePtrValue(std::unique_ptr<Value> val) {
92 std::unique_ptr<Value> Value::ToUniquePtrValue(Value val) {
93 return std::make_unique<Value>(std::move(val));
96 Value::Value(Value&& that) noexcept {
100 Value::Value() noexcept : type_(Type::NONE) {}
102 Value::Value(Type type) : type_(type) {
103 // Initialize with the default value.
132 Value::Value(bool in_bool) : type_(Type::BOOLEAN), bool_value_(in_bool) {}
134 Value::Value(int in_int) : type_(Type::INTEGER), int_value_(in_int) {}
136 Value::Value(double in_double) : type_(Type::DOUBLE), double_value_(in_double) {
144 Value::Value(const char* in_string) : Value(std::string(in_string)) {}
146 Value::Value(StringPiece in_string) : Value(std::string(in_string)) {}
148 Value::Value(std::string&& in_string) noexcept
153 Value::Value(const char16* in_string16) : Value(StringPiece16(in_string16)) {}
155 Value::Value(StringPiece16 in_string16) : Value(UTF16ToUTF8(in_string16)) {}
157 Value::Value(const BlobStorage& in_blob)
160 Value::Value(BlobStorage&& in_blob) noexcept
163 Value::Value(const DictStorage& in_dict) : type_(Type::DICTIONARY), dict_() {
167 std::make_unique<Value>(it.second->Clone()));
171 Value::Value(DictStorage&& in_dict) noexcept
174 Value::Value(const ListStorage& in_list) : type_(Type::LIST), list_() {
180 Value::Value(ListStorage&& in_list) noexcept
183 Value& Value::operator=(Value&& that) noexcept {
190 Value Value::Clone() const {
193 return Value();
195 return Value(bool_value_);
197 return Value(int_value_);
199 return Value(double_value_);
201 return Value(string_value_);
203 return Value(binary_value_);
205 return Value(dict_);
207 return Value(list_);
211 return Value();
214 Value::~Value() {
219 const char* Value::GetTypeName(Value::Type type) {
225 bool Value::GetBool() const {
230 int Value::GetInt() const {
235 double Value::GetDouble() const {
244 const std::string& Value::GetString() const {
249 const Value::BlobStorage& Value::GetBlob() const {
254 Value::ListStorage& Value::GetList() {
259 const Value::ListStorage& Value::GetList() const {
264 Value* Value::FindKey(StringPiece key) {
265 return const_cast<Value*>(static_cast<const Value*>(this)->FindKey(key));
268 const Value* Value::FindKey(StringPiece key) const {
276 Value* Value::FindKeyOfType(StringPiece key, Type type) {
277 return const_cast<Value*>(
278 static_cast<const Value*>(this)->FindKeyOfType(key, type));
281 const Value* Value::FindKeyOfType(StringPiece key, Type type) const {
282 const Value* result = FindKey(key);
288 bool Value::RemoveKey(StringPiece key) {
294 Value* Value::SetKey(StringPiece key, Value value) {
298 auto val_ptr = std::make_unique<Value>(std::move(value));
307 Value* Value::SetKey(std::string&& key, Value value) {
311 std::make_unique<Value>(std::move(value)))
315 Value* Value::SetKey(const char* key, Value value) {
316 return SetKey(StringPiece(key), std::move(value));
319 Value* Value::FindPath(std::initializer_list<StringPiece> path) {
320 return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
323 Value* Value::FindPath(span<const StringPiece> path) {
324 return const_cast<Value*>(const_cast<const Value*>(this)->FindPath(path));
327 const Value* Value::FindPath(std::initializer_list<StringPiece> path) const {
332 const Value* Value::FindPath(span<const StringPiece> path) const {
333 const Value* cur = this;
341 Value* Value::FindPathOfType(std::initializer_list<StringPiece> path,
343 return const_cast<Value*>(
344 const_cast<const Value*>(this)->FindPathOfType(path, type));
347 Value* Value::FindPathOfType(span<const StringPiece> path, Type type) {
348 return const_cast<Value*>(
349 const_cast<const Value*>(this)->FindPathOfType(path, type));
352 const Value* Value::FindPathOfType(std::initializer_list<StringPiece> path,
358 const Value* Value::FindPathOfType(span<const StringPiece> path,
360 const Value* result = FindPath(path);
366 Value* Value::SetPath(std::initializer_list<StringPiece> path, Value value) {
368 return SetPath(make_span(path.begin(), path.size()), std::move(value));
371 Value* Value::SetPath(span<const StringPiece> path, Value value) {
376 Value* cur = this;
388 found, path_component, std::make_unique<Value>(Type::DICTIONARY));
398 return cur->SetKey(*cur_path, std::move(value));
401 bool Value::RemovePath(std::initializer_list<StringPiece> path) {
406 bool Value::RemovePath(span<const StringPiece> path) {
424 Value::dict_iterator_proxy Value::DictItems() {
429 Value::const_dict_iterator_proxy Value::DictItems() const {
434 size_t Value::DictSize() const {
439 bool Value::DictEmpty() const {
444 bool Value::GetAsBoolean(bool* out_value) const {
452 bool Value::GetAsInteger(int* out_value) const {
460 bool Value::GetAsDouble(double* out_value) const {
472 bool Value::GetAsString(std::string* out_value) const {
480 bool Value::GetAsString(string16* out_value) const {
488 bool Value::GetAsString(const Value** out_value) const {
490 *out_value = static_cast<const Value*>(this);
496 bool Value::GetAsString(StringPiece* out_value) const {
504 bool Value::GetAsList(ListValue** out_value) {
512 bool Value::GetAsList(const ListValue** out_value) const {
520 bool Value::GetAsDictionary(DictionaryValue** out_value) {
528 bool Value::GetAsDictionary(const DictionaryValue** out_value) const {
536 Value* Value::DeepCopy() const {
537 return new Value(Clone());
540 std::unique_ptr<Value> Value::CreateDeepCopy() const {
541 return std::make_unique<Value>(Clone());
544 bool operator==(const Value& lhs, const Value& rhs) {
549 case Value::Type::NONE:
551 case Value::Type::BOOLEAN:
553 case Value::Type::INTEGER:
555 case Value::Type::DOUBLE:
557 case Value::Type::STRING:
559 case Value::Type::BINARY:
563 case Value::Type::DICTIONARY:
572 case Value::Type::LIST:
580 bool operator!=(const Value& lhs, const Value& rhs) {
584 bool operator<(const Value& lhs, const Value& rhs) {
589 case Value::Type::NONE:
591 case Value::Type::BOOLEAN:
593 case Value::Type::INTEGER:
595 case Value::Type::DOUBLE:
597 case Value::Type::STRING:
599 case Value::Type::BINARY:
603 case Value::Type::DICTIONARY:
607 [](const Value::DictStorage::value_type& u,
608 const Value::DictStorage::value_type& v) {
611 case Value::Type::LIST:
619 bool operator>(const Value& lhs, const Value& rhs) {
623 bool operator<=(const Value& lhs, const Value& rhs) {
627 bool operator>=(const Value& lhs, const Value& rhs) {
631 bool Value::Equals(const Value* other) const {
637 // size_t Value::EstimateMemoryUsage() const {
652 void Value::InternalMoveConstructFrom(Value&& that) {
682 void Value::InternalCleanup() {
710 std::unique_ptr<Value> value) {
712 if (value && value->GetAsDictionary(&out)) {
713 ignore_result(value.release());
719 DictionaryValue::DictionaryValue() : Value(Type::DICTIONARY) {}
720 DictionaryValue::DictionaryValue(const DictStorage& in_dict) : Value(in_dict) {}
722 : Value(std::move(in_dict)) {}
735 Value* DictionaryValue::Set(StringPiece path, std::unique_ptr<Value> in_value) {
740 Value* current_dictionary = this;
746 Value* child_dictionary =
750 current_dictionary->SetKey(key, Value(Type::DICTIONARY));
761 Value* DictionaryValue::SetBoolean(StringPiece path, bool in_value) {
762 return Set(path, std::make_unique<Value>(in_value));
765 Value* DictionaryValue::SetInteger(StringPiece path, int in_value) {
766 return Set(path, std::make_unique<Value>(in_value));
769 Value* DictionaryValue::SetDouble(StringPiece path, double in_value) {
770 return Set(path, std::make_unique<Value>(in_value));
773 Value* DictionaryValue::SetString(StringPiece path, StringPiece in_value) {
774 return Set(path, std::make_unique<Value>(in_value));
777 Value* DictionaryValue::SetString(StringPiece path, const string16& in_value) {
778 return Set(path, std::make_unique<Value>(in_value));
792 Value* DictionaryValue::SetWithoutPathExpansion(
794 std::unique_ptr<Value> in_value) {
806 const Value** out_value) const {
826 bool DictionaryValue::Get(StringPiece path, Value** out_value) {
829 const_cast<const Value**>(out_value));
833 const Value* value;
834 if (!Get(path, &value))
837 return value->GetAsBoolean(bool_value);
841 const Value* value;
842 if (!Get(path, &value))
845 return value->GetAsInteger(out_value);
849 const Value* value;
850 if (!Get(path, &value))
853 return value->GetAsDouble(out_value);
858 const Value* value;
859 if (!Get(path, &value))
862 return value->GetAsString(out_value);
866 const Value* value;
867 if (!Get(path, &value))
870 return value->GetAsString(out_value);
889 const Value** out_value) const {
890 const Value* value;
891 bool result = Get(path, &value);
892 if (!result || !value->is_blob())
896 *out_value = value;
901 bool DictionaryValue::GetBinary(StringPiece path, Value** out_value) {
903 path, const_cast<const Value**>(out_value));
908 const Value* value;
909 bool result = Get(path, &value);
910 if (!result || !value->is_dict())
914 *out_value = static_cast<const DictionaryValue*>(value);
928 const Value* value;
929 bool result = Get(path, &value);
930 if (!result || !value->is_list())
934 *out_value = static_cast<const ListValue*>(value);
946 const Value** out_value) const {
958 Value** out_value) {
961 const_cast<const Value**>(out_value));
966 const Value* value;
967 if (!GetWithoutPathExpansion(key, &value))
970 return value->GetAsBoolean(out_value);
975 const Value* value;
976 if (!GetWithoutPathExpansion(key, &value))
979 return value->GetAsInteger(out_value);
984 const Value* value;
985 if (!GetWithoutPathExpansion(key, &value))
988 return value->GetAsDouble(out_value);
994 const Value* value;
995 if (!GetWithoutPathExpansion(key, &value))
998 return value->GetAsString(out_value);
1003 const Value* value;
1004 if (!GetWithoutPathExpansion(key, &value))
1007 return value->GetAsString(out_value);
1013 const Value* value;
1014 bool result = GetWithoutPathExpansion(key, &value);
1015 if (!result || !value->is_dict())
1019 *out_value = static_cast<const DictionaryValue*>(value);
1037 const Value* value;
1038 bool result = GetWithoutPathExpansion(key, &value);
1039 if (!result || !value->is_list())
1043 *out_value = static_cast<const ListValue*>(value);
1057 std::unique_ptr<Value>* out_value) {
1075 std::unique_ptr<Value>* out_value) {
1088 std::unique_ptr<Value>* out_value) {
1119 const Value* merge_value = &it.value();
1157 std::unique_ptr<ListValue> ListValue::From(std::unique_ptr<Value> value) {
1159 if (value && value->GetAsList(&out)) {
1160 ignore_result(value.release());
1166 ListValue::ListValue() : Value(Type::LIST) {}
1167 ListValue::ListValue(const ListStorage& in_list) : Value(in_list) {}
1169 : Value(std::move(in_list)) {}
1179 bool ListValue::Set(size_t index, std::unique_ptr<Value> in_value) {
1190 bool ListValue::Get(size_t index, const Value** out_value) const {
1200 bool ListValue::Get(size_t index, Value** out_value) {
1203 const_cast<const Value**>(out_value));
1207 const Value* value;
1208 if (!Get(index, &value))
1211 return value->GetAsBoolean(bool_value);
1215 const Value* value;
1216 if (!Get(index, &value))
1219 return value->GetAsInteger(out_value);
1223 const Value* value;
1224 if (!Get(index, &value))
1227 return value->GetAsDouble(out_value);
1231 const Value* value;
1232 if (!Get(index, &value))
1235 return value->GetAsString(out_value);
1239 const Value* value;
1240 if (!Get(index, &value))
1243 return value->GetAsString(out_value);
1248 const Value* value;
1249 bool result = Get(index, &value);
1250 if (!result || !value->is_dict())
1254 *out_value = static_cast<const DictionaryValue*>(value);
1266 const Value* value;
1267 bool result = Get(index, &value);
1268 if (!result || !value->is_list())
1272 *out_value = static_cast<const ListValue*>(value);
1283 bool ListValue::Remove(size_t index, std::unique_ptr<Value>* out_value) {
1288 *out_value = std::make_unique<Value>(std::move(list_[index]));
1294 bool ListValue::Remove(const Value& value, size_t* index) {
1295 auto it = std::find(list_.begin(), list_.end(), value);
1308 std::unique_ptr<Value>* out_value) {
1310 *out_value = std::make_unique<Value>(std::move(*iter));
1315 void ListValue::Append(std::unique_ptr<Value> in_value) {
1351 bool ListValue::AppendIfNotPresent(std::unique_ptr<Value> in_value) {
1360 bool ListValue::Insert(size_t index, std::unique_ptr<Value> in_value) {
1369 ListValue::const_iterator ListValue::Find(const Value& value) const {
1370 return std::find(list_.begin(), list_.end(), value);
1390 std::ostream& operator<<(std::ostream& out, const Value& value) {
1392 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json);
1396 std::ostream& operator<<(std::ostream& out, const Value::Type& type) {
1400 return out << Value::GetTypeName(type);