| 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 | 8 |
| 9 #include "base/float_util.h" | 9 #include "base/float_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 Append(CreateNullValue()); | 813 Append(CreateNullValue()); |
| 814 Append(in_value); | 814 Append(in_value); |
| 815 } else { | 815 } else { |
| 816 DCHECK(list_[index] != in_value); | 816 DCHECK(list_[index] != in_value); |
| 817 delete list_[index]; | 817 delete list_[index]; |
| 818 list_[index] = in_value; | 818 list_[index] = in_value; |
| 819 } | 819 } |
| 820 return true; | 820 return true; |
| 821 } | 821 } |
| 822 | 822 |
| 823 bool ListValue::Get(size_t index, Value** out_value) const { | 823 bool ListValue::Get(size_t index, const Value** out_value) const { |
| 824 if (index >= list_.size()) | 824 if (index >= list_.size()) |
| 825 return false; | 825 return false; |
| 826 | 826 |
| 827 if (out_value) | 827 if (out_value) |
| 828 *out_value = list_[index]; | 828 *out_value = list_[index]; |
| 829 | 829 |
| 830 return true; | 830 return true; |
| 831 } | 831 } |
| 832 | 832 |
| 833 bool ListValue::Get(size_t index, Value** out_value) { |
| 834 return static_cast<const ListValue&>(*this).Get( |
| 835 index, |
| 836 const_cast<const Value**>(out_value)); |
| 837 } |
| 838 |
| 833 bool ListValue::GetBoolean(size_t index, bool* bool_value) const { | 839 bool ListValue::GetBoolean(size_t index, bool* bool_value) const { |
| 834 Value* value; | 840 const Value* value; |
| 835 if (!Get(index, &value)) | 841 if (!Get(index, &value)) |
| 836 return false; | 842 return false; |
| 837 | 843 |
| 838 return value->GetAsBoolean(bool_value); | 844 return value->GetAsBoolean(bool_value); |
| 839 } | 845 } |
| 840 | 846 |
| 841 bool ListValue::GetInteger(size_t index, int* out_value) const { | 847 bool ListValue::GetInteger(size_t index, int* out_value) const { |
| 842 Value* value; | 848 const Value* value; |
| 843 if (!Get(index, &value)) | 849 if (!Get(index, &value)) |
| 844 return false; | 850 return false; |
| 845 | 851 |
| 846 return value->GetAsInteger(out_value); | 852 return value->GetAsInteger(out_value); |
| 847 } | 853 } |
| 848 | 854 |
| 849 bool ListValue::GetDouble(size_t index, double* out_value) const { | 855 bool ListValue::GetDouble(size_t index, double* out_value) const { |
| 850 Value* value; | 856 const Value* value; |
| 851 if (!Get(index, &value)) | 857 if (!Get(index, &value)) |
| 852 return false; | 858 return false; |
| 853 | 859 |
| 854 return value->GetAsDouble(out_value); | 860 return value->GetAsDouble(out_value); |
| 855 } | 861 } |
| 856 | 862 |
| 857 bool ListValue::GetString(size_t index, std::string* out_value) const { | 863 bool ListValue::GetString(size_t index, std::string* out_value) const { |
| 858 Value* value; | 864 const Value* value; |
| 859 if (!Get(index, &value)) | 865 if (!Get(index, &value)) |
| 860 return false; | 866 return false; |
| 861 | 867 |
| 862 return value->GetAsString(out_value); | 868 return value->GetAsString(out_value); |
| 863 } | 869 } |
| 864 | 870 |
| 865 bool ListValue::GetString(size_t index, string16* out_value) const { | 871 bool ListValue::GetString(size_t index, string16* out_value) const { |
| 866 Value* value; | 872 const Value* value; |
| 867 if (!Get(index, &value)) | 873 if (!Get(index, &value)) |
| 868 return false; | 874 return false; |
| 869 | 875 |
| 870 return value->GetAsString(out_value); | 876 return value->GetAsString(out_value); |
| 871 } | 877 } |
| 872 | 878 |
| 873 bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { | 879 bool ListValue::GetBinary(size_t index, const BinaryValue** out_value) const { |
| 874 Value* value; | 880 const Value* value; |
| 875 bool result = Get(index, &value); | 881 bool result = Get(index, &value); |
| 876 if (!result || !value->IsType(TYPE_BINARY)) | 882 if (!result || !value->IsType(TYPE_BINARY)) |
| 877 return false; | 883 return false; |
| 878 | 884 |
| 879 if (out_value) | 885 if (out_value) |
| 880 *out_value = static_cast<BinaryValue*>(value); | 886 *out_value = static_cast<const BinaryValue*>(value); |
| 881 | 887 |
| 882 return true; | 888 return true; |
| 883 } | 889 } |
| 884 | 890 |
| 885 bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) const { | 891 bool ListValue::GetBinary(size_t index, BinaryValue** out_value) { |
| 886 Value* value; | 892 return static_cast<const ListValue&>(*this).GetBinary( |
| 893 index, |
| 894 const_cast<const BinaryValue**>(out_value)); |
| 895 } |
| 896 |
| 897 bool ListValue::GetDictionary(size_t index, |
| 898 const DictionaryValue** out_value) const { |
| 899 const Value* value; |
| 887 bool result = Get(index, &value); | 900 bool result = Get(index, &value); |
| 888 if (!result || !value->IsType(TYPE_DICTIONARY)) | 901 if (!result || !value->IsType(TYPE_DICTIONARY)) |
| 889 return false; | 902 return false; |
| 890 | 903 |
| 891 if (out_value) | 904 if (out_value) |
| 892 *out_value = static_cast<DictionaryValue*>(value); | 905 *out_value = static_cast<const DictionaryValue*>(value); |
| 893 | 906 |
| 894 return true; | 907 return true; |
| 895 } | 908 } |
| 896 | 909 |
| 897 bool ListValue::GetList(size_t index, ListValue** out_value) const { | 910 bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) { |
| 898 Value* value; | 911 return static_cast<const ListValue&>(*this).GetDictionary( |
| 912 index, |
| 913 const_cast<const DictionaryValue**>(out_value)); |
| 914 } |
| 915 |
| 916 bool ListValue::GetList(size_t index, const ListValue** out_value) const { |
| 917 const Value* value; |
| 899 bool result = Get(index, &value); | 918 bool result = Get(index, &value); |
| 900 if (!result || !value->IsType(TYPE_LIST)) | 919 if (!result || !value->IsType(TYPE_LIST)) |
| 901 return false; | 920 return false; |
| 902 | 921 |
| 903 if (out_value) | 922 if (out_value) |
| 904 *out_value = static_cast<ListValue*>(value); | 923 *out_value = static_cast<const ListValue*>(value); |
| 905 | 924 |
| 906 return true; | 925 return true; |
| 907 } | 926 } |
| 908 | 927 |
| 928 bool ListValue::GetList(size_t index, ListValue** out_value) { |
| 929 return static_cast<const ListValue&>(*this).GetList( |
| 930 index, |
| 931 const_cast<const ListValue**>(out_value)); |
| 932 } |
| 933 |
| 909 bool ListValue::Remove(size_t index, Value** out_value) { | 934 bool ListValue::Remove(size_t index, Value** out_value) { |
| 910 if (index >= list_.size()) | 935 if (index >= list_.size()) |
| 911 return false; | 936 return false; |
| 912 | 937 |
| 913 if (out_value) | 938 if (out_value) |
| 914 *out_value = list_[index]; | 939 *out_value = list_[index]; |
| 915 else | 940 else |
| 916 delete list_[index]; | 941 delete list_[index]; |
| 917 | 942 |
| 918 list_.erase(list_.begin() + index); | 943 list_.erase(list_.begin() + index); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 if (lhs_it != end() || rhs_it != other_list->end()) | 1039 if (lhs_it != end() || rhs_it != other_list->end()) |
| 1015 return false; | 1040 return false; |
| 1016 | 1041 |
| 1017 return true; | 1042 return true; |
| 1018 } | 1043 } |
| 1019 | 1044 |
| 1020 ValueSerializer::~ValueSerializer() { | 1045 ValueSerializer::~ValueSerializer() { |
| 1021 } | 1046 } |
| 1022 | 1047 |
| 1023 } // namespace base | 1048 } // namespace base |
| OLD | NEW |