| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool Value::GetAsString(std::string* out_value) const { | 114 bool Value::GetAsString(std::string* out_value) const { |
| 115 return false; | 115 return false; |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool Value::GetAsString(string16* out_value) const { | 118 bool Value::GetAsString(string16* out_value) const { |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool Value::GetAsFilePath(FilePath* out_value) const { |
| 123 return false; |
| 124 } |
| 125 |
| 122 bool Value::GetAsList(ListValue** out_value) { | 126 bool Value::GetAsList(ListValue** out_value) { |
| 123 return false; | 127 return false; |
| 124 } | 128 } |
| 125 | 129 |
| 126 Value* Value::DeepCopy() const { | 130 Value* Value::DeepCopy() const { |
| 127 // This method should only be getting called for null Values--all subclasses | 131 // This method should only be getting called for null Values--all subclasses |
| 128 // need to provide their own implementation;. | 132 // need to provide their own implementation;. |
| 129 DCHECK(IsType(TYPE_NULL)); | 133 DCHECK(IsType(TYPE_NULL)); |
| 130 return CreateNullValue(); | 134 return CreateNullValue(); |
| 131 } | 135 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 return CreateStringValue(value_); | 258 return CreateStringValue(value_); |
| 255 } | 259 } |
| 256 | 260 |
| 257 bool StringValue::Equals(const Value* other) const { | 261 bool StringValue::Equals(const Value* other) const { |
| 258 if (other->GetType() != GetType()) | 262 if (other->GetType() != GetType()) |
| 259 return false; | 263 return false; |
| 260 std::string lhs, rhs; | 264 std::string lhs, rhs; |
| 261 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; | 265 return GetAsString(&lhs) && other->GetAsString(&rhs) && lhs == rhs; |
| 262 } | 266 } |
| 263 | 267 |
| 268 ///////////////////// FilePathValue //////////////////////////////////////////// |
| 269 |
| 270 FilePathValue::FilePathValue(const FilePath& in_value) |
| 271 : Value(TYPE_PATH), |
| 272 value_(in_value) { |
| 273 } |
| 274 |
| 275 FilePathValue::~FilePathValue() { |
| 276 } |
| 277 |
| 278 bool FilePathValue::GetAsFilePath(FilePath* out_value) const { |
| 279 if (out_value) |
| 280 *out_value = value_; |
| 281 return true; |
| 282 } |
| 283 |
| 284 bool FilePathValue::Equals(const Value* other) const { |
| 285 if (other->GetType() != GetType()) |
| 286 return false; |
| 287 FilePath lhs, rhs; |
| 288 return GetAsFilePath(&lhs) && other->GetAsFilePath(&rhs) && lhs == rhs; |
| 289 } |
| 290 |
| 264 ///////////////////// BinaryValue //////////////////// | 291 ///////////////////// BinaryValue //////////////////// |
| 265 | 292 |
| 266 BinaryValue::~BinaryValue() { | 293 BinaryValue::~BinaryValue() { |
| 267 DCHECK(buffer_); | 294 DCHECK(buffer_); |
| 268 if (buffer_) | 295 if (buffer_) |
| 269 delete[] buffer_; | 296 delete[] buffer_; |
| 270 } | 297 } |
| 271 | 298 |
| 272 // static | 299 // static |
| 273 BinaryValue* BinaryValue::Create(char* buffer, size_t size) { | 300 BinaryValue* BinaryValue::Create(char* buffer, size_t size) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 bool result = Get(path, &value); | 531 bool result = Get(path, &value); |
| 505 if (!result || !value->IsType(TYPE_LIST)) | 532 if (!result || !value->IsType(TYPE_LIST)) |
| 506 return false; | 533 return false; |
| 507 | 534 |
| 508 if (out_value) | 535 if (out_value) |
| 509 *out_value = static_cast<ListValue*>(value); | 536 *out_value = static_cast<ListValue*>(value); |
| 510 | 537 |
| 511 return true; | 538 return true; |
| 512 } | 539 } |
| 513 | 540 |
| 541 bool DictionaryValue::GetFilePath(const std::string& path, |
| 542 FilePath* out_value) const { |
| 543 Value* value; |
| 544 if (!Get(path, &value)) |
| 545 return false; |
| 546 |
| 547 return value->GetAsFilePath(out_value); |
| 548 } |
| 549 |
| 514 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, | 550 bool DictionaryValue::GetWithoutPathExpansion(const std::string& key, |
| 515 Value** out_value) const { | 551 Value** out_value) const { |
| 516 DCHECK(IsStringUTF8(key)); | 552 DCHECK(IsStringUTF8(key)); |
| 517 ValueMap::const_iterator entry_iterator = dictionary_.find(key); | 553 ValueMap::const_iterator entry_iterator = dictionary_.find(key); |
| 518 if (entry_iterator == dictionary_.end()) | 554 if (entry_iterator == dictionary_.end()) |
| 519 return false; | 555 return false; |
| 520 | 556 |
| 521 Value* entry = entry_iterator->second; | 557 Value* entry = entry_iterator->second; |
| 522 if (out_value) | 558 if (out_value) |
| 523 *out_value = entry; | 559 *out_value = entry; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 bool result = Get(index, &value); | 831 bool result = Get(index, &value); |
| 796 if (!result || !value->IsType(TYPE_LIST)) | 832 if (!result || !value->IsType(TYPE_LIST)) |
| 797 return false; | 833 return false; |
| 798 | 834 |
| 799 if (out_value) | 835 if (out_value) |
| 800 *out_value = static_cast<ListValue*>(value); | 836 *out_value = static_cast<ListValue*>(value); |
| 801 | 837 |
| 802 return true; | 838 return true; |
| 803 } | 839 } |
| 804 | 840 |
| 841 bool ListValue::GetFilePath(size_t index, FilePath* out_value) const { |
| 842 Value* value; |
| 843 if (!Get(index, &value)) |
| 844 return false; |
| 845 |
| 846 return value->GetAsFilePath(out_value); |
| 847 } |
| 848 |
| 805 bool ListValue::Remove(size_t index, Value** out_value) { | 849 bool ListValue::Remove(size_t index, Value** out_value) { |
| 806 if (index >= list_.size()) | 850 if (index >= list_.size()) |
| 807 return false; | 851 return false; |
| 808 | 852 |
| 809 if (out_value) | 853 if (out_value) |
| 810 *out_value = list_[index]; | 854 *out_value = list_[index]; |
| 811 else | 855 else |
| 812 delete list_[index]; | 856 delete list_[index]; |
| 813 | 857 |
| 814 list_.erase(list_.begin() + index); | 858 list_.erase(list_.begin() + index); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 return false; | 929 return false; |
| 886 } | 930 } |
| 887 if (lhs_it != end() || rhs_it != other_list->end()) | 931 if (lhs_it != end() || rhs_it != other_list->end()) |
| 888 return false; | 932 return false; |
| 889 | 933 |
| 890 return true; | 934 return true; |
| 891 } | 935 } |
| 892 | 936 |
| 893 ValueSerializer::~ValueSerializer() { | 937 ValueSerializer::~ValueSerializer() { |
| 894 } | 938 } |
| OLD | NEW |