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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 return true; | 490 return true; |
491 } | 491 } |
492 | 492 |
493 ///////////////////// ListValue //////////////////// | 493 ///////////////////// ListValue //////////////////// |
494 | 494 |
495 ListValue::~ListValue() { | 495 ListValue::~ListValue() { |
496 Clear(); | 496 Clear(); |
497 } | 497 } |
498 | 498 |
499 void ListValue::Clear() { | 499 void ListValue::Clear() { |
500 ValueVector::iterator list_iterator = list_.begin(); | 500 for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) |
501 while (list_iterator != list_.end()) { | 501 delete *i; |
502 delete *list_iterator; | |
503 ++list_iterator; | |
504 } | |
505 list_.clear(); | 502 list_.clear(); |
506 } | 503 } |
507 | 504 |
508 bool ListValue::Set(size_t index, Value* in_value) { | 505 bool ListValue::Set(size_t index, Value* in_value) { |
509 if (!in_value) | 506 if (!in_value) |
510 return false; | 507 return false; |
511 | 508 |
512 if (index >= list_.size()) { | 509 if (index >= list_.size()) { |
513 // Pad out any intermediate indexes with null settings | 510 // Pad out any intermediate indexes with null settings |
514 while (index > list_.size()) | 511 while (index > list_.size()) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 | 599 |
603 bool ListValue::Remove(size_t index, Value** out_value) { | 600 bool ListValue::Remove(size_t index, Value** out_value) { |
604 if (index >= list_.size()) | 601 if (index >= list_.size()) |
605 return false; | 602 return false; |
606 | 603 |
607 if (out_value) | 604 if (out_value) |
608 *out_value = list_[index]; | 605 *out_value = list_[index]; |
609 else | 606 else |
610 delete list_[index]; | 607 delete list_[index]; |
611 | 608 |
612 ValueVector::iterator entry = list_.begin(); | 609 list_.erase(list_.begin() + index); |
613 entry += index; | 610 return true; |
| 611 } |
614 | 612 |
615 list_.erase(entry); | 613 void ListValue::Remove(Value* in_value) { |
616 return true; | 614 for (ValueVector::iterator i(list_.begin()); i != list_.end(); ++i) { |
| 615 if ((*i)->Equals(in_value)) { |
| 616 list_.erase(i); |
| 617 break; |
| 618 } |
| 619 } |
617 } | 620 } |
618 | 621 |
619 void ListValue::Append(Value* in_value) { | 622 void ListValue::Append(Value* in_value) { |
620 DCHECK(in_value); | 623 DCHECK(in_value); |
621 list_.push_back(in_value); | 624 list_.push_back(in_value); |
622 } | 625 } |
623 | 626 |
624 Value* ListValue::DeepCopy() const { | 627 Value* ListValue::DeepCopy() const { |
625 ListValue* result = new ListValue; | 628 ListValue* result = new ListValue; |
626 | 629 |
627 ValueVector::const_iterator current_entry = list_.begin(); | 630 for (ValueVector::const_iterator i(list_.begin()); i != list_.end(); ++i) |
628 while (current_entry != list_.end()) { | 631 result->Append((*i)->DeepCopy()); |
629 result->Append((*current_entry)->DeepCopy()); | |
630 ++current_entry; | |
631 } | |
632 | 632 |
633 return result; | 633 return result; |
634 } | 634 } |
635 | 635 |
636 bool ListValue::Equals(const Value* other) const { | 636 bool ListValue::Equals(const Value* other) const { |
637 if (other->GetType() != GetType()) | 637 if (other->GetType() != GetType()) |
638 return false; | 638 return false; |
639 | 639 |
640 const ListValue* other_list = | 640 const ListValue* other_list = |
641 static_cast<const ListValue*>(other); | 641 static_cast<const ListValue*>(other); |
642 const_iterator lhs_it, rhs_it; | 642 const_iterator lhs_it, rhs_it; |
643 for (lhs_it = begin(), rhs_it = other_list->begin(); | 643 for (lhs_it = begin(), rhs_it = other_list->begin(); |
644 lhs_it != end() && rhs_it != other_list->end(); | 644 lhs_it != end() && rhs_it != other_list->end(); |
645 ++lhs_it, ++rhs_it) { | 645 ++lhs_it, ++rhs_it) { |
646 if (!(*lhs_it)->Equals(*rhs_it)) | 646 if (!(*lhs_it)->Equals(*rhs_it)) |
647 return false; | 647 return false; |
648 } | 648 } |
649 if (lhs_it != end() || rhs_it != other_list->end()) | 649 if (lhs_it != end() || rhs_it != other_list->end()) |
650 return false; | 650 return false; |
651 | 651 |
652 return true; | 652 return true; |
653 } | 653 } |
OLD | NEW |