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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 private: | 78 private: |
79 const Value* first_; | 79 const Value* first_; |
80 }; | 80 }; |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 Value::~Value() { | 84 Value::~Value() { |
85 } | 85 } |
86 | 86 |
87 // static | 87 // static |
88 Value* Value::CreateNullValue() { | 88 scoped_ptr<Value> Value::CreateNullValue() { |
89 return new Value(TYPE_NULL); | 89 return make_scoped_ptr(new Value(TYPE_NULL)); |
90 } | 90 } |
91 | 91 |
92 bool Value::GetAsBinary(const BinaryValue** out_value) const { | 92 bool Value::GetAsBinary(const BinaryValue** out_value) const { |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
96 bool Value::GetAsBoolean(bool* out_value) const { | 96 bool Value::GetAsBoolean(bool* out_value) const { |
97 return false; | 97 return false; |
98 } | 98 } |
99 | 99 |
(...skipping 30 matching lines...) Expand all Loading... |
130 } | 130 } |
131 | 131 |
132 bool Value::GetAsDictionary(const DictionaryValue** out_value) const { | 132 bool Value::GetAsDictionary(const DictionaryValue** out_value) const { |
133 return false; | 133 return false; |
134 } | 134 } |
135 | 135 |
136 Value* Value::DeepCopy() const { | 136 Value* Value::DeepCopy() const { |
137 // This method should only be getting called for null Values--all subclasses | 137 // This method should only be getting called for null Values--all subclasses |
138 // need to provide their own implementation;. | 138 // need to provide their own implementation;. |
139 DCHECK(IsType(TYPE_NULL)); | 139 DCHECK(IsType(TYPE_NULL)); |
140 return CreateNullValue(); | 140 return CreateNullValue().release(); |
141 } | 141 } |
142 | 142 |
143 scoped_ptr<Value> Value::CreateDeepCopy() const { | 143 scoped_ptr<Value> Value::CreateDeepCopy() const { |
144 return make_scoped_ptr(DeepCopy()); | 144 return make_scoped_ptr(DeepCopy()); |
145 } | 145 } |
146 | 146 |
147 bool Value::Equals(const Value* other) const { | 147 bool Value::Equals(const Value* other) const { |
148 // This method should only be getting called for null Values--all subclasses | 148 // This method should only be getting called for null Values--all subclasses |
149 // need to provide their own implementation;. | 149 // need to provide their own implementation;. |
150 DCHECK(IsType(TYPE_NULL)); | 150 DCHECK(IsType(TYPE_NULL)); |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 | 1130 |
1131 ListValue* ListValue::DeepCopy() const { | 1131 ListValue* ListValue::DeepCopy() const { |
1132 ListValue* result = new ListValue; | 1132 ListValue* result = new ListValue; |
1133 | 1133 |
1134 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) | 1134 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) |
1135 result->Append((*i)->DeepCopy()); | 1135 result->Append((*i)->DeepCopy()); |
1136 | 1136 |
1137 return result; | 1137 return result; |
1138 } | 1138 } |
1139 | 1139 |
| 1140 scoped_ptr<ListValue> ListValue::CreateDeepCopy() const { |
| 1141 return make_scoped_ptr(DeepCopy()); |
| 1142 } |
| 1143 |
1140 bool ListValue::Equals(const Value* other) const { | 1144 bool ListValue::Equals(const Value* other) const { |
1141 if (other->GetType() != GetType()) | 1145 if (other->GetType() != GetType()) |
1142 return false; | 1146 return false; |
1143 | 1147 |
1144 const ListValue* other_list = | 1148 const ListValue* other_list = |
1145 static_cast<const ListValue*>(other); | 1149 static_cast<const ListValue*>(other); |
1146 const_iterator lhs_it, rhs_it; | 1150 const_iterator lhs_it, rhs_it; |
1147 for (lhs_it = begin(), rhs_it = other_list->begin(); | 1151 for (lhs_it = begin(), rhs_it = other_list->begin(); |
1148 lhs_it != end() && rhs_it != other_list->end(); | 1152 lhs_it != end() && rhs_it != other_list->end(); |
1149 ++lhs_it, ++rhs_it) { | 1153 ++lhs_it, ++rhs_it) { |
(...skipping 14 matching lines...) Expand all Loading... |
1164 | 1168 |
1165 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1169 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1166 std::string json; | 1170 std::string json; |
1167 JSONWriter::WriteWithOptions(&value, | 1171 JSONWriter::WriteWithOptions(&value, |
1168 JSONWriter::OPTIONS_PRETTY_PRINT, | 1172 JSONWriter::OPTIONS_PRETTY_PRINT, |
1169 &json); | 1173 &json); |
1170 return out << json; | 1174 return out << json; |
1171 } | 1175 } |
1172 | 1176 |
1173 } // namespace base | 1177 } // namespace base |
OLD | NEW |