| 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 NOTREACHED(); | 386 NOTREACHED(); |
| 387 return nullptr; | 387 return nullptr; |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 std::unique_ptr<Value> Value::CreateDeepCopy() const { | 391 std::unique_ptr<Value> Value::CreateDeepCopy() const { |
| 392 return WrapUnique(DeepCopy()); | 392 return WrapUnique(DeepCopy()); |
| 393 } | 393 } |
| 394 | 394 |
| 395 bool Value::Equals(const Value* other) const { | 395 bool Value::Equals(const Value* other) const { |
| 396 if (other->type() != type()) | 396 DCHECK(other); |
| 397 return false; | 397 return *this == *other; |
| 398 | |
| 399 switch (type()) { | |
| 400 case Type::NONE: | |
| 401 return true; | |
| 402 case Type::BOOLEAN: | |
| 403 return bool_value_ == other->bool_value_; | |
| 404 case Type::INTEGER: | |
| 405 return int_value_ == other->int_value_; | |
| 406 case Type::DOUBLE: | |
| 407 return double_value_ == other->double_value_; | |
| 408 case Type::STRING: | |
| 409 return *string_value_ == *(other->string_value_); | |
| 410 case Type::BINARY: | |
| 411 return *binary_value_ == *(other->binary_value_); | |
| 412 // TODO(crbug.com/646113): Clean this up when DictionaryValue and ListValue | |
| 413 // are completely inlined. | |
| 414 case Type::DICTIONARY: { | |
| 415 if ((*dict_ptr_)->size() != (*other->dict_ptr_)->size()) | |
| 416 return false; | |
| 417 | |
| 418 return std::equal(std::begin(**dict_ptr_), std::end(**dict_ptr_), | |
| 419 std::begin(**(other->dict_ptr_)), | |
| 420 [](const DictStorage::value_type& lhs, | |
| 421 const DictStorage::value_type& rhs) { | |
| 422 if (lhs.first != rhs.first) | |
| 423 return false; | |
| 424 | |
| 425 return lhs.second->Equals(rhs.second.get()); | |
| 426 }); | |
| 427 } | |
| 428 case Type::LIST: { | |
| 429 if (list_->size() != other->list_->size()) | |
| 430 return false; | |
| 431 | |
| 432 return std::equal(std::begin(*list_), std::end(*list_), | |
| 433 std::begin(*(other->list_)), | |
| 434 [](const ListStorage::value_type& lhs, | |
| 435 const ListStorage::value_type& rhs) { | |
| 436 return lhs->Equals(rhs.get()); | |
| 437 }); | |
| 438 } | |
| 439 } | |
| 440 | |
| 441 NOTREACHED(); | |
| 442 return false; | |
| 443 } | 398 } |
| 444 | 399 |
| 445 // static | 400 // static |
| 446 bool Value::Equals(const Value* a, const Value* b) { | 401 bool Value::Equals(const Value* a, const Value* b) { |
| 447 if ((a == NULL) && (b == NULL)) return true; | 402 if ((a == NULL) && (b == NULL)) |
| 448 if ((a == NULL) ^ (b == NULL)) return false; | 403 return true; |
| 449 return a->Equals(b); | 404 if ((a == NULL) ^ (b == NULL)) |
| 405 return false; |
| 406 return *a == *b; |
| 450 } | 407 } |
| 451 | 408 |
| 452 void Value::InternalCopyFundamentalValue(const Value& that) { | 409 void Value::InternalCopyFundamentalValue(const Value& that) { |
| 453 switch (type_) { | 410 switch (type_) { |
| 454 case Type::NONE: | 411 case Type::NONE: |
| 455 // Nothing to do. | 412 // Nothing to do. |
| 456 return; | 413 return; |
| 457 | 414 |
| 458 case Type::BOOLEAN: | 415 case Type::BOOLEAN: |
| 459 bool_value_ = that.bool_value_; | 416 bool_value_ = that.bool_value_; |
| (...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 } | 1282 } |
| 1326 | 1283 |
| 1327 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { | 1284 std::ostream& operator<<(std::ostream& out, const Value::Type& type) { |
| 1328 if (static_cast<int>(type) < 0 || | 1285 if (static_cast<int>(type) < 0 || |
| 1329 static_cast<size_t>(type) >= arraysize(kTypeNames)) | 1286 static_cast<size_t>(type) >= arraysize(kTypeNames)) |
| 1330 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; | 1287 return out << "Invalid Type (index = " << static_cast<int>(type) << ")"; |
| 1331 return out << Value::GetTypeName(type); | 1288 return out << Value::GetTypeName(type); |
| 1332 } | 1289 } |
| 1333 | 1290 |
| 1334 } // namespace base | 1291 } // namespace base |
| OLD | NEW |