| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 | 8 |
| 9 ///////////////////// Value //////////////////// | 9 ///////////////////// Value //////////////////// |
| 10 | 10 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void DictionaryValue::Clear() { | 238 void DictionaryValue::Clear() { |
| 239 ValueMap::iterator dict_iterator = dictionary_.begin(); | 239 ValueMap::iterator dict_iterator = dictionary_.begin(); |
| 240 while (dict_iterator != dictionary_.end()) { | 240 while (dict_iterator != dictionary_.end()) { |
| 241 delete dict_iterator->second; | 241 delete dict_iterator->second; |
| 242 ++dict_iterator; | 242 ++dict_iterator; |
| 243 } | 243 } |
| 244 | 244 |
| 245 dictionary_.clear(); | 245 dictionary_.clear(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 bool DictionaryValue::HasKey(const std::wstring& key) { | 248 bool DictionaryValue::HasKey(const std::wstring& key) const { |
| 249 ValueMap::const_iterator current_entry = dictionary_.find(key); | 249 ValueMap::const_iterator current_entry = dictionary_.find(key); |
| 250 DCHECK((current_entry == dictionary_.end()) || current_entry->second); | 250 DCHECK((current_entry == dictionary_.end()) || current_entry->second); |
| 251 return current_entry != dictionary_.end(); | 251 return current_entry != dictionary_.end(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void DictionaryValue::SetInCurrentNode(const std::wstring& key, | 254 void DictionaryValue::SetInCurrentNode(const std::wstring& key, |
| 255 Value* in_value) { | 255 Value* in_value) { |
| 256 // If there's an existing value here, we need to delete it, because | 256 // If there's an existing value here, we need to delete it, because |
| 257 // we own all our children. | 257 // we own all our children. |
| 258 if (HasKey(key)) { | 258 if (HasKey(key)) { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 bool ListValue::Get(size_t index, Value** out_value) const { | 525 bool ListValue::Get(size_t index, Value** out_value) const { |
| 526 if (index >= list_.size()) | 526 if (index >= list_.size()) |
| 527 return false; | 527 return false; |
| 528 | 528 |
| 529 if (out_value) | 529 if (out_value) |
| 530 *out_value = list_[index]; | 530 *out_value = list_[index]; |
| 531 | 531 |
| 532 return true; | 532 return true; |
| 533 } | 533 } |
| 534 | 534 |
| 535 bool ListValue::GetDictionary(size_t index, | 535 bool ListValue::GetBoolean(size_t index, bool* bool_value) const { |
| 536 DictionaryValue** out_value) const { | 536 Value* value; |
| 537 if (!Get(index, &value)) |
| 538 return false; |
| 539 |
| 540 return value->GetAsBoolean(bool_value); |
| 541 } |
| 542 |
| 543 bool ListValue::GetInteger(size_t index, int* out_value) const { |
| 544 Value* value; |
| 545 if (!Get(index, &value)) |
| 546 return false; |
| 547 |
| 548 return value->GetAsInteger(out_value); |
| 549 } |
| 550 |
| 551 bool ListValue::GetReal(size_t index, double* out_value) const { |
| 552 Value* value; |
| 553 if (!Get(index, &value)) |
| 554 return false; |
| 555 |
| 556 return value->GetAsReal(out_value); |
| 557 } |
| 558 |
| 559 bool ListValue::GetString(size_t index, std::string* out_value) const { |
| 560 Value* value; |
| 561 if (!Get(index, &value)) |
| 562 return false; |
| 563 |
| 564 return value->GetAsString(out_value); |
| 565 } |
| 566 |
| 567 bool ListValue::GetBinary(size_t index, BinaryValue** out_value) const { |
| 568 Value* value; |
| 569 bool result = Get(index, &value); |
| 570 if (!result || !value->IsType(TYPE_BINARY)) |
| 571 return false; |
| 572 |
| 573 if (out_value) |
| 574 *out_value = static_cast<BinaryValue*>(value); |
| 575 |
| 576 return true; |
| 577 } |
| 578 |
| 579 bool ListValue::GetDictionary(size_t index, DictionaryValue** out_value) const { |
| 537 Value* value; | 580 Value* value; |
| 538 bool result = Get(index, &value); | 581 bool result = Get(index, &value); |
| 539 if (!result || !value->IsType(TYPE_DICTIONARY)) | 582 if (!result || !value->IsType(TYPE_DICTIONARY)) |
| 540 return false; | 583 return false; |
| 541 | 584 |
| 542 if (out_value) | 585 if (out_value) |
| 543 *out_value = static_cast<DictionaryValue*>(value); | 586 *out_value = static_cast<DictionaryValue*>(value); |
| 544 | 587 |
| 545 return true; | 588 return true; |
| 546 } | 589 } |
| 547 | 590 |
| 591 bool ListValue::GetList(size_t index, ListValue** out_value) const { |
| 592 Value* value; |
| 593 bool result = Get(index, &value); |
| 594 if (!result || !value->IsType(TYPE_LIST)) |
| 595 return false; |
| 596 |
| 597 if (out_value) |
| 598 *out_value = static_cast<ListValue*>(value); |
| 599 |
| 600 return true; |
| 601 } |
| 602 |
| 548 bool ListValue::Remove(size_t index, Value** out_value) { | 603 bool ListValue::Remove(size_t index, Value** out_value) { |
| 549 if (index >= list_.size()) | 604 if (index >= list_.size()) |
| 550 return false; | 605 return false; |
| 551 | 606 |
| 552 if (out_value) | 607 if (out_value) |
| 553 *out_value = list_[index]; | 608 *out_value = list_[index]; |
| 554 else | 609 else |
| 555 delete list_[index]; | 610 delete list_[index]; |
| 556 | 611 |
| 557 ValueVector::iterator entry = list_.begin(); | 612 ValueVector::iterator entry = list_.begin(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 ++lhs_it, ++rhs_it) { | 645 ++lhs_it, ++rhs_it) { |
| 591 if (!(*lhs_it)->Equals(*rhs_it)) | 646 if (!(*lhs_it)->Equals(*rhs_it)) |
| 592 return false; | 647 return false; |
| 593 } | 648 } |
| 594 if (lhs_it != end() || rhs_it != other_list->end()) | 649 if (lhs_it != end() || rhs_it != other_list->end()) |
| 595 return false; | 650 return false; |
| 596 | 651 |
| 597 return true; | 652 return true; |
| 598 } | 653 } |
| 599 | 654 |
| OLD | NEW |