OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/values.h" | 5 #include "base/values.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "base/float_util.h" | 10 #include "base/float_util.h" |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 // we own all our children. | 436 // we own all our children. |
437 std::pair<ValueMap::iterator, bool> ins_res = | 437 std::pair<ValueMap::iterator, bool> ins_res = |
438 dictionary_.insert(std::make_pair(key, in_value)); | 438 dictionary_.insert(std::make_pair(key, in_value)); |
439 if (!ins_res.second) { | 439 if (!ins_res.second) { |
440 DCHECK_NE(ins_res.first->second, in_value); // This would be bogus | 440 DCHECK_NE(ins_res.first->second, in_value); // This would be bogus |
441 delete ins_res.first->second; | 441 delete ins_res.first->second; |
442 ins_res.first->second = in_value; | 442 ins_res.first->second = in_value; |
443 } | 443 } |
444 } | 444 } |
445 | 445 |
| 446 void DictionaryValue::SetBooleanWithoutPathExpansion( |
| 447 const std::string& path, bool in_value) { |
| 448 SetWithoutPathExpansion(path, CreateBooleanValue(in_value)); |
| 449 } |
| 450 |
| 451 void DictionaryValue::SetIntegerWithoutPathExpansion( |
| 452 const std::string& path, int in_value) { |
| 453 SetWithoutPathExpansion(path, CreateIntegerValue(in_value)); |
| 454 } |
| 455 |
| 456 void DictionaryValue::SetDoubleWithoutPathExpansion( |
| 457 const std::string& path, double in_value) { |
| 458 SetWithoutPathExpansion(path, CreateDoubleValue(in_value)); |
| 459 } |
| 460 |
| 461 void DictionaryValue::SetStringWithoutPathExpansion( |
| 462 const std::string& path, const std::string& in_value) { |
| 463 SetWithoutPathExpansion(path, CreateStringValue(in_value)); |
| 464 } |
| 465 |
| 466 void DictionaryValue::SetStringWithoutPathExpansion( |
| 467 const std::string& path, const string16& in_value) { |
| 468 SetWithoutPathExpansion(path, CreateStringValue(in_value)); |
| 469 } |
| 470 |
446 bool DictionaryValue::Get( | 471 bool DictionaryValue::Get( |
447 const std::string& path, const Value** out_value) const { | 472 const std::string& path, const Value** out_value) const { |
448 DCHECK(IsStringUTF8(path)); | 473 DCHECK(IsStringUTF8(path)); |
449 std::string current_path(path); | 474 std::string current_path(path); |
450 const DictionaryValue* current_dictionary = this; | 475 const DictionaryValue* current_dictionary = this; |
451 for (size_t delimiter_position = current_path.find('.'); | 476 for (size_t delimiter_position = current_path.find('.'); |
452 delimiter_position != std::string::npos; | 477 delimiter_position != std::string::npos; |
453 delimiter_position = current_path.find('.')) { | 478 delimiter_position = current_path.find('.')) { |
454 const DictionaryValue* child_dictionary = NULL; | 479 const DictionaryValue* child_dictionary = NULL; |
455 if (!current_dictionary->GetDictionary( | 480 if (!current_dictionary->GetDictionary( |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 delete *iter; | 1005 delete *iter; |
981 | 1006 |
982 list_.erase(iter); | 1007 list_.erase(iter); |
983 } | 1008 } |
984 | 1009 |
985 void ListValue::Append(Value* in_value) { | 1010 void ListValue::Append(Value* in_value) { |
986 DCHECK(in_value); | 1011 DCHECK(in_value); |
987 list_.push_back(in_value); | 1012 list_.push_back(in_value); |
988 } | 1013 } |
989 | 1014 |
| 1015 void ListValue::AppendBoolean(bool in_value) { |
| 1016 Append(CreateBooleanValue(in_value)); |
| 1017 } |
| 1018 |
| 1019 void ListValue::AppendInteger(int in_value) { |
| 1020 Append(CreateIntegerValue(in_value)); |
| 1021 } |
| 1022 |
| 1023 void ListValue::AppendDouble(double in_value) { |
| 1024 Append(CreateDoubleValue(in_value)); |
| 1025 } |
| 1026 |
| 1027 void ListValue::AppendString(const std::string& in_value) { |
| 1028 Append(CreateStringValue(in_value)); |
| 1029 } |
| 1030 |
| 1031 void ListValue::AppendString(const string16& in_value) { |
| 1032 Append(CreateStringValue(in_value)); |
| 1033 } |
| 1034 |
| 1035 void ListValue::AppendStrings(const std::vector<std::string>& in_values) { |
| 1036 for (std::vector<std::string>::const_iterator it = in_values.begin(); |
| 1037 it != in_values.end(); ++it) { |
| 1038 AppendString(*it); |
| 1039 } |
| 1040 } |
| 1041 |
| 1042 void ListValue::AppendStrings(const std::vector<string16>& in_values) { |
| 1043 for (std::vector<string16>::const_iterator it = in_values.begin(); |
| 1044 it != in_values.end(); ++it) { |
| 1045 AppendString(*it); |
| 1046 } |
| 1047 } |
| 1048 |
990 bool ListValue::AppendIfNotPresent(Value* in_value) { | 1049 bool ListValue::AppendIfNotPresent(Value* in_value) { |
991 DCHECK(in_value); | 1050 DCHECK(in_value); |
992 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) { | 1051 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) { |
993 if ((*i)->Equals(in_value)) { | 1052 if ((*i)->Equals(in_value)) { |
994 delete in_value; | 1053 delete in_value; |
995 return false; | 1054 return false; |
996 } | 1055 } |
997 } | 1056 } |
998 list_.push_back(in_value); | 1057 list_.push_back(in_value); |
999 return true; | 1058 return true; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 | 1120 |
1062 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1121 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1063 std::string json; | 1122 std::string json; |
1064 JSONWriter::WriteWithOptions(&value, | 1123 JSONWriter::WriteWithOptions(&value, |
1065 JSONWriter::OPTIONS_PRETTY_PRINT, | 1124 JSONWriter::OPTIONS_PRETTY_PRINT, |
1066 &json); | 1125 &json); |
1067 return out << json; | 1126 return out << json; |
1068 } | 1127 } |
1069 | 1128 |
1070 } // namespace base | 1129 } // namespace base |
OLD | NEW |