OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/float_util.h" | 7 #include "base/float_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // static | 93 // static |
94 StringValue* Value::CreateStringValue(const std::string& in_value) { | 94 StringValue* Value::CreateStringValue(const std::string& in_value) { |
95 return new StringValue(in_value); | 95 return new StringValue(in_value); |
96 } | 96 } |
97 | 97 |
98 // static | 98 // static |
99 StringValue* Value::CreateStringValue(const string16& in_value) { | 99 StringValue* Value::CreateStringValue(const string16& in_value) { |
100 return new StringValue(in_value); | 100 return new StringValue(in_value); |
101 } | 101 } |
102 | 102 |
| 103 ListValue* Value::AsList() { |
| 104 return NULL; |
| 105 } |
| 106 |
103 bool Value::GetAsBoolean(bool* out_value) const { | 107 bool Value::GetAsBoolean(bool* out_value) const { |
104 return false; | 108 return false; |
105 } | 109 } |
106 | 110 |
107 bool Value::GetAsInteger(int* out_value) const { | 111 bool Value::GetAsInteger(int* out_value) const { |
108 return false; | 112 return false; |
109 } | 113 } |
110 | 114 |
111 bool Value::GetAsDouble(double* out_value) const { | 115 bool Value::GetAsDouble(double* out_value) const { |
112 return false; | 116 return false; |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 if (out_value) | 516 if (out_value) |
513 *out_value = static_cast<DictionaryValue*>(value); | 517 *out_value = static_cast<DictionaryValue*>(value); |
514 | 518 |
515 return true; | 519 return true; |
516 } | 520 } |
517 | 521 |
518 bool DictionaryValue::GetList(const std::string& path, | 522 bool DictionaryValue::GetList(const std::string& path, |
519 ListValue** out_value) const { | 523 ListValue** out_value) const { |
520 Value* value; | 524 Value* value; |
521 bool result = Get(path, &value); | 525 bool result = Get(path, &value); |
522 if (!result || !value->IsType(TYPE_LIST)) | 526 if (!result || !value->AsList()) |
523 return false; | 527 return false; |
524 | 528 |
525 if (out_value) | 529 if (out_value) |
526 *out_value = static_cast<ListValue*>(value); | 530 *out_value = static_cast<ListValue*>(value); |
527 | 531 |
528 return true; | 532 return true; |
529 } | 533 } |
530 | 534 |
531 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, | 535 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, |
532 Value** out_value) const { | 536 Value** out_value) const { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 if (out_value) | 594 if (out_value) |
591 *out_value = static_cast<DictionaryValue*>(value); | 595 *out_value = static_cast<DictionaryValue*>(value); |
592 | 596 |
593 return true; | 597 return true; |
594 } | 598 } |
595 | 599 |
596 bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, | 600 bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, |
597 ListValue** out_value) const { | 601 ListValue** out_value) const { |
598 Value* value; | 602 Value* value; |
599 bool result = GetWithoutPathExpansion(key, &value); | 603 bool result = GetWithoutPathExpansion(key, &value); |
600 if (!result || !value->IsType(TYPE_LIST)) | 604 if (!result || !value->AsList()) |
601 return false; | 605 return false; |
602 | 606 |
603 if (out_value) | 607 if (out_value) |
604 *out_value = static_cast<ListValue*>(value); | 608 *out_value = static_cast<ListValue*>(value); |
605 | 609 |
606 return true; | 610 return true; |
607 } | 611 } |
608 | 612 |
609 bool DictionaryValue::Remove(const std::string& path, Value** out_value) { | 613 bool DictionaryValue::Remove(const std::string& path, Value** out_value) { |
610 DCHECK(IsStringUTF8(path)); | 614 DCHECK(IsStringUTF8(path)); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 | 807 |
804 if (out_value) | 808 if (out_value) |
805 *out_value = static_cast<DictionaryValue*>(value); | 809 *out_value = static_cast<DictionaryValue*>(value); |
806 | 810 |
807 return true; | 811 return true; |
808 } | 812 } |
809 | 813 |
810 bool ListValue::GetList(size_t index, ListValue** out_value) const { | 814 bool ListValue::GetList(size_t index, ListValue** out_value) const { |
811 Value* value; | 815 Value* value; |
812 bool result = Get(index, &value); | 816 bool result = Get(index, &value); |
813 if (!result || !value->IsType(TYPE_LIST)) | 817 if (!result || !value->AsList()) |
814 return false; | 818 return false; |
815 | 819 |
816 if (out_value) | 820 if (out_value) |
817 *out_value = static_cast<ListValue*>(value); | 821 *out_value = static_cast<ListValue*>(value); |
818 | 822 |
819 return true; | 823 return true; |
820 } | 824 } |
821 | 825 |
822 bool ListValue::Remove(size_t index, Value** out_value) { | 826 bool ListValue::Remove(size_t index, Value** out_value) { |
823 if (index >= list_.size()) | 827 if (index >= list_.size()) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 | 870 |
867 bool ListValue::Insert(size_t index, Value* in_value) { | 871 bool ListValue::Insert(size_t index, Value* in_value) { |
868 DCHECK(in_value); | 872 DCHECK(in_value); |
869 if (index > list_.size()) | 873 if (index > list_.size()) |
870 return false; | 874 return false; |
871 | 875 |
872 list_.insert(list_.begin() + index, in_value); | 876 list_.insert(list_.begin() + index, in_value); |
873 return true; | 877 return true; |
874 } | 878 } |
875 | 879 |
| 880 ListValue* ListValue::AsList() { |
| 881 return this; |
| 882 } |
| 883 |
876 bool ListValue::GetAsList(ListValue** out_value) { | 884 bool ListValue::GetAsList(ListValue** out_value) { |
877 if (out_value) | 885 if (out_value) |
878 *out_value = this; | 886 *out_value = this; |
879 return true; | 887 return true; |
880 } | 888 } |
881 | 889 |
882 bool ListValue::GetAsList(const ListValue** out_value) const { | 890 bool ListValue::GetAsList(const ListValue** out_value) const { |
883 if (out_value) | 891 if (out_value) |
884 *out_value = this; | 892 *out_value = this; |
885 return true; | 893 return true; |
(...skipping 24 matching lines...) Expand all Loading... |
910 if (lhs_it != end() || rhs_it != other_list->end()) | 918 if (lhs_it != end() || rhs_it != other_list->end()) |
911 return false; | 919 return false; |
912 | 920 |
913 return true; | 921 return true; |
914 } | 922 } |
915 | 923 |
916 ValueSerializer::~ValueSerializer() { | 924 ValueSerializer::~ValueSerializer() { |
917 } | 925 } |
918 | 926 |
919 } // namespace base | 927 } // namespace base |
OLD | NEW |