| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // static | 90 // static |
| 91 StringValue* Value::CreateStringValue(const std::string& in_value) { | 91 StringValue* Value::CreateStringValue(const std::string& in_value) { |
| 92 return new StringValue(in_value); | 92 return new StringValue(in_value); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // static | 95 // static |
| 96 StringValue* Value::CreateStringValue(const string16& in_value) { | 96 StringValue* Value::CreateStringValue(const string16& in_value) { |
| 97 return new StringValue(in_value); | 97 return new StringValue(in_value); |
| 98 } | 98 } |
| 99 | 99 |
| 100 ListValue* Value::AsList() { |
| 101 return NULL; |
| 102 } |
| 103 |
| 100 bool Value::GetAsBoolean(bool* out_value) const { | 104 bool Value::GetAsBoolean(bool* out_value) const { |
| 101 return false; | 105 return false; |
| 102 } | 106 } |
| 103 | 107 |
| 104 bool Value::GetAsInteger(int* out_value) const { | 108 bool Value::GetAsInteger(int* out_value) const { |
| 105 return false; | 109 return false; |
| 106 } | 110 } |
| 107 | 111 |
| 108 bool Value::GetAsDouble(double* out_value) const { | 112 bool Value::GetAsDouble(double* out_value) const { |
| 109 return false; | 113 return false; |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 if (out_value) | 505 if (out_value) |
| 502 *out_value = static_cast<DictionaryValue*>(value); | 506 *out_value = static_cast<DictionaryValue*>(value); |
| 503 | 507 |
| 504 return true; | 508 return true; |
| 505 } | 509 } |
| 506 | 510 |
| 507 bool DictionaryValue::GetList(const std::string& path, | 511 bool DictionaryValue::GetList(const std::string& path, |
| 508 ListValue** out_value) const { | 512 ListValue** out_value) const { |
| 509 Value* value; | 513 Value* value; |
| 510 bool result = Get(path, &value); | 514 bool result = Get(path, &value); |
| 511 if (!result || !value->IsType(TYPE_LIST)) | 515 if (!result || !value->AsList()) |
| 512 return false; | 516 return false; |
| 513 | 517 |
| 514 if (out_value) | 518 if (out_value) |
| 515 *out_value = static_cast<ListValue*>(value); | 519 *out_value = static_cast<ListValue*>(value); |
| 516 | 520 |
| 517 return true; | 521 return true; |
| 518 } | 522 } |
| 519 | 523 |
| 520 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, | 524 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, |
| 521 Value** out_value) const { | 525 Value** out_value) const { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 if (out_value) | 583 if (out_value) |
| 580 *out_value = static_cast<DictionaryValue*>(value); | 584 *out_value = static_cast<DictionaryValue*>(value); |
| 581 | 585 |
| 582 return true; | 586 return true; |
| 583 } | 587 } |
| 584 | 588 |
| 585 bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, | 589 bool DictionaryValue::GetListWithoutPathExpansion(const std::string& key, |
| 586 ListValue** out_value) const { | 590 ListValue** out_value) const { |
| 587 Value* value; | 591 Value* value; |
| 588 bool result = GetWithoutPathExpansion(key, &value); | 592 bool result = GetWithoutPathExpansion(key, &value); |
| 589 if (!result || !value->IsType(TYPE_LIST)) | 593 if (!result || !value->AsList()) |
| 590 return false; | 594 return false; |
| 591 | 595 |
| 592 if (out_value) | 596 if (out_value) |
| 593 *out_value = static_cast<ListValue*>(value); | 597 *out_value = static_cast<ListValue*>(value); |
| 594 | 598 |
| 595 return true; | 599 return true; |
| 596 } | 600 } |
| 597 | 601 |
| 598 bool DictionaryValue::Remove(const std::string& path, Value** out_value) { | 602 bool DictionaryValue::Remove(const std::string& path, Value** out_value) { |
| 599 DCHECK(IsStringUTF8(path)); | 603 DCHECK(IsStringUTF8(path)); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 | 796 |
| 793 if (out_value) | 797 if (out_value) |
| 794 *out_value = static_cast<DictionaryValue*>(value); | 798 *out_value = static_cast<DictionaryValue*>(value); |
| 795 | 799 |
| 796 return true; | 800 return true; |
| 797 } | 801 } |
| 798 | 802 |
| 799 bool ListValue::GetList(size_t index, ListValue** out_value) const { | 803 bool ListValue::GetList(size_t index, ListValue** out_value) const { |
| 800 Value* value; | 804 Value* value; |
| 801 bool result = Get(index, &value); | 805 bool result = Get(index, &value); |
| 802 if (!result || !value->IsType(TYPE_LIST)) | 806 if (!result || !value->AsList()) |
| 803 return false; | 807 return false; |
| 804 | 808 |
| 805 if (out_value) | 809 if (out_value) |
| 806 *out_value = static_cast<ListValue*>(value); | 810 *out_value = static_cast<ListValue*>(value); |
| 807 | 811 |
| 808 return true; | 812 return true; |
| 809 } | 813 } |
| 810 | 814 |
| 811 bool ListValue::Remove(size_t index, Value** out_value) { | 815 bool ListValue::Remove(size_t index, Value** out_value) { |
| 812 if (index >= list_.size()) | 816 if (index >= list_.size()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 | 859 |
| 856 bool ListValue::Insert(size_t index, Value* in_value) { | 860 bool ListValue::Insert(size_t index, Value* in_value) { |
| 857 DCHECK(in_value); | 861 DCHECK(in_value); |
| 858 if (index > list_.size()) | 862 if (index > list_.size()) |
| 859 return false; | 863 return false; |
| 860 | 864 |
| 861 list_.insert(list_.begin() + index, in_value); | 865 list_.insert(list_.begin() + index, in_value); |
| 862 return true; | 866 return true; |
| 863 } | 867 } |
| 864 | 868 |
| 869 ListValue* ListValue::AsList() { |
| 870 return this; |
| 871 } |
| 872 |
| 865 bool ListValue::GetAsList(ListValue** out_value) { | 873 bool ListValue::GetAsList(ListValue** out_value) { |
| 866 if (out_value) | 874 if (out_value) |
| 867 *out_value = this; | 875 *out_value = this; |
| 868 return true; | 876 return true; |
| 869 } | 877 } |
| 870 | 878 |
| 871 bool ListValue::GetAsList(const ListValue** out_value) const { | 879 bool ListValue::GetAsList(const ListValue** out_value) const { |
| 872 if (out_value) | 880 if (out_value) |
| 873 *out_value = this; | 881 *out_value = this; |
| 874 return true; | 882 return true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 899 if (lhs_it != end() || rhs_it != other_list->end()) | 907 if (lhs_it != end() || rhs_it != other_list->end()) |
| 900 return false; | 908 return false; |
| 901 | 909 |
| 902 return true; | 910 return true; |
| 903 } | 911 } |
| 904 | 912 |
| 905 ValueSerializer::~ValueSerializer() { | 913 ValueSerializer::~ValueSerializer() { |
| 906 } | 914 } |
| 907 | 915 |
| 908 } // namespace base | 916 } // namespace base |
| OLD | NEW |