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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 if (other->GetType() != GetType()) | 344 if (other->GetType() != GetType()) |
345 return false; | 345 return false; |
346 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); | 346 const BinaryValue* other_binary = static_cast<const BinaryValue*>(other); |
347 if (other_binary->size_ != size_) | 347 if (other_binary->size_ != size_) |
348 return false; | 348 return false; |
349 return !memcmp(GetBuffer(), other_binary->GetBuffer(), size_); | 349 return !memcmp(GetBuffer(), other_binary->GetBuffer(), size_); |
350 } | 350 } |
351 | 351 |
352 ///////////////////// DictionaryValue //////////////////// | 352 ///////////////////// DictionaryValue //////////////////// |
353 | 353 |
| 354 // static |
| 355 scoped_ptr<DictionaryValue> DictionaryValue::From(scoped_ptr<Value> value) { |
| 356 DictionaryValue* out; |
| 357 if (value && value->GetAsDictionary(&out)) { |
| 358 ignore_result(value.release()); |
| 359 return make_scoped_ptr(out); |
| 360 } |
| 361 return nullptr; |
| 362 } |
| 363 |
354 DictionaryValue::DictionaryValue() | 364 DictionaryValue::DictionaryValue() |
355 : Value(TYPE_DICTIONARY) { | 365 : Value(TYPE_DICTIONARY) { |
356 } | 366 } |
357 | 367 |
358 DictionaryValue::~DictionaryValue() { | 368 DictionaryValue::~DictionaryValue() { |
359 Clear(); | 369 Clear(); |
360 } | 370 } |
361 | 371 |
362 bool DictionaryValue::GetAsDictionary(DictionaryValue** out_value) { | 372 bool DictionaryValue::GetAsDictionary(DictionaryValue** out_value) { |
363 if (out_value) | 373 if (out_value) |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 rhs_it.Advance(); | 873 rhs_it.Advance(); |
864 } | 874 } |
865 if (!lhs_it.IsAtEnd() || !rhs_it.IsAtEnd()) | 875 if (!lhs_it.IsAtEnd() || !rhs_it.IsAtEnd()) |
866 return false; | 876 return false; |
867 | 877 |
868 return true; | 878 return true; |
869 } | 879 } |
870 | 880 |
871 ///////////////////// ListValue //////////////////// | 881 ///////////////////// ListValue //////////////////// |
872 | 882 |
| 883 // static |
| 884 scoped_ptr<ListValue> ListValue::From(scoped_ptr<Value> value) { |
| 885 ListValue* out; |
| 886 if (value && value->GetAsList(&out)) { |
| 887 ignore_result(value.release()); |
| 888 return make_scoped_ptr(out); |
| 889 } |
| 890 return nullptr; |
| 891 } |
| 892 |
873 ListValue::ListValue() : Value(TYPE_LIST) { | 893 ListValue::ListValue() : Value(TYPE_LIST) { |
874 } | 894 } |
875 | 895 |
876 ListValue::~ListValue() { | 896 ListValue::~ListValue() { |
877 Clear(); | 897 Clear(); |
878 } | 898 } |
879 | 899 |
880 void ListValue::Clear() { | 900 void ListValue::Clear() { |
881 for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) | 901 for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) |
882 delete *i; | 902 delete *i; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 ValueDeserializer::~ValueDeserializer() { | 1195 ValueDeserializer::~ValueDeserializer() { |
1176 } | 1196 } |
1177 | 1197 |
1178 std::ostream& operator<<(std::ostream& out, const Value& value) { | 1198 std::ostream& operator<<(std::ostream& out, const Value& value) { |
1179 std::string json; | 1199 std::string json; |
1180 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); | 1200 JSONWriter::WriteWithOptions(value, JSONWriter::OPTIONS_PRETTY_PRINT, &json); |
1181 return out << json; | 1201 return out << json; |
1182 } | 1202 } |
1183 | 1203 |
1184 } // namespace base | 1204 } // namespace base |
OLD | NEW |