| 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 // This file specifies a recursive data storage class called Value intended for | 5 // This file specifies a recursive data storage class called Value intended for |
| 6 // storing settings and other persistable data. | 6 // storing settings and other persistable data. |
| 7 // | 7 // |
| 8 // A Value represents something that can be stored in JSON or passed to/from | 8 // A Value represents something that can be stored in JSON or passed to/from |
| 9 // JavaScript. As such, it is NOT a generalized variant type, since only the | 9 // JavaScript. As such, it is NOT a generalized variant type, since only the |
| 10 // types supported by JavaScript/JSON are supported. | 10 // types supported by JavaScript/JSON are supported. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 bool GetAsList(const ListValue** out_value) const; | 150 bool GetAsList(const ListValue** out_value) const; |
| 151 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. | 151 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. |
| 152 bool GetAsDictionary(DictionaryValue** out_value); | 152 bool GetAsDictionary(DictionaryValue** out_value); |
| 153 bool GetAsDictionary(const DictionaryValue** out_value) const; | 153 bool GetAsDictionary(const DictionaryValue** out_value) const; |
| 154 // Note: Do not add more types. See the file-level comment above for why. | 154 // Note: Do not add more types. See the file-level comment above for why. |
| 155 | 155 |
| 156 // This creates a deep copy of the entire Value tree, and returns a pointer | 156 // This creates a deep copy of the entire Value tree, and returns a pointer |
| 157 // to the copy. The caller gets ownership of the copy, of course. | 157 // to the copy. The caller gets ownership of the copy, of course. |
| 158 // Subclasses return their own type directly in their overrides; | 158 // Subclasses return their own type directly in their overrides; |
| 159 // this works because C++ supports covariant return types. | 159 // this works because C++ supports covariant return types. |
| 160 // DEPRECATED, use Value's copy constructor instead. |
| 161 // TODO(crbug.com/646113): Delete this and migrate callsites. |
| 160 Value* DeepCopy() const; | 162 Value* DeepCopy() const; |
| 161 // Preferred version of DeepCopy. TODO(estade): remove the above. | 163 // Preferred version of DeepCopy. TODO(estade): remove the above. |
| 162 std::unique_ptr<Value> CreateDeepCopy() const; | 164 std::unique_ptr<Value> CreateDeepCopy() const; |
| 163 | 165 |
| 164 // Comparison operators so that Values can easily be used with standard | 166 // Comparison operators so that Values can easily be used with standard |
| 165 // library algorithms and associative containers. | 167 // library algorithms and associative containers. |
| 166 BASE_EXPORT friend bool operator==(const Value& lhs, const Value& rhs); | 168 BASE_EXPORT friend bool operator==(const Value& lhs, const Value& rhs); |
| 167 BASE_EXPORT friend bool operator!=(const Value& lhs, const Value& rhs); | 169 BASE_EXPORT friend bool operator!=(const Value& lhs, const Value& rhs); |
| 168 BASE_EXPORT friend bool operator<(const Value& lhs, const Value& rhs); | 170 BASE_EXPORT friend bool operator<(const Value& lhs, const Value& rhs); |
| 169 BASE_EXPORT friend bool operator>(const Value& lhs, const Value& rhs); | 171 BASE_EXPORT friend bool operator>(const Value& lhs, const Value& rhs); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 void Advance() { ++it_; } | 359 void Advance() { ++it_; } |
| 358 | 360 |
| 359 const std::string& key() const { return it_->first; } | 361 const std::string& key() const { return it_->first; } |
| 360 const Value& value() const { return *it_->second; } | 362 const Value& value() const { return *it_->second; } |
| 361 | 363 |
| 362 private: | 364 private: |
| 363 const DictionaryValue& target_; | 365 const DictionaryValue& target_; |
| 364 DictStorage::const_iterator it_; | 366 DictStorage::const_iterator it_; |
| 365 }; | 367 }; |
| 366 | 368 |
| 369 // DEPRECATED, use DictionaryValue's copy constructor instead. |
| 370 // TODO(crbug.com/646113): Delete this and migrate callsites. |
| 367 DictionaryValue* DeepCopy() const; | 371 DictionaryValue* DeepCopy() const; |
| 368 // Preferred version of DeepCopy. TODO(estade): remove the above. | 372 // Preferred version of DeepCopy. TODO(estade): remove the above. |
| 369 std::unique_ptr<DictionaryValue> CreateDeepCopy() const; | 373 std::unique_ptr<DictionaryValue> CreateDeepCopy() const; |
| 370 }; | 374 }; |
| 371 | 375 |
| 372 // This type of Value represents a list of other Value values. | 376 // This type of Value represents a list of other Value values. |
| 373 class BASE_EXPORT ListValue : public Value { | 377 class BASE_EXPORT ListValue : public Value { |
| 374 public: | 378 public: |
| 375 using const_iterator = ListStorage::const_iterator; | 379 using const_iterator = ListStorage::const_iterator; |
| 376 using iterator = ListStorage::iterator; | 380 using iterator = ListStorage::iterator; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 // Swaps contents with the |other| list. | 477 // Swaps contents with the |other| list. |
| 474 void Swap(ListValue* other); | 478 void Swap(ListValue* other); |
| 475 | 479 |
| 476 // Iteration. | 480 // Iteration. |
| 477 iterator begin() { return list_->begin(); } | 481 iterator begin() { return list_->begin(); } |
| 478 iterator end() { return list_->end(); } | 482 iterator end() { return list_->end(); } |
| 479 | 483 |
| 480 const_iterator begin() const { return list_->begin(); } | 484 const_iterator begin() const { return list_->begin(); } |
| 481 const_iterator end() const { return list_->end(); } | 485 const_iterator end() const { return list_->end(); } |
| 482 | 486 |
| 487 // DEPRECATED, use ListValue's copy constructor instead. |
| 488 // TODO(crbug.com/646113): Delete this and migrate callsites. |
| 483 ListValue* DeepCopy() const; | 489 ListValue* DeepCopy() const; |
| 484 // Preferred version of DeepCopy. TODO(estade): remove DeepCopy. | 490 // Preferred version of DeepCopy. TODO(estade): remove DeepCopy. |
| 485 std::unique_ptr<ListValue> CreateDeepCopy() const; | 491 std::unique_ptr<ListValue> CreateDeepCopy() const; |
| 486 }; | 492 }; |
| 487 | 493 |
| 488 // This interface is implemented by classes that know how to serialize | 494 // This interface is implemented by classes that know how to serialize |
| 489 // Value objects. | 495 // Value objects. |
| 490 class BASE_EXPORT ValueSerializer { | 496 class BASE_EXPORT ValueSerializer { |
| 491 public: | 497 public: |
| 492 virtual ~ValueSerializer(); | 498 virtual ~ValueSerializer(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return out << static_cast<const Value&>(value); | 532 return out << static_cast<const Value&>(value); |
| 527 } | 533 } |
| 528 | 534 |
| 529 // Stream operator so that enum class Types can be used in log statements. | 535 // Stream operator so that enum class Types can be used in log statements. |
| 530 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 536 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
| 531 const Value::Type& type); | 537 const Value::Type& type); |
| 532 | 538 |
| 533 } // namespace base | 539 } // namespace base |
| 534 | 540 |
| 535 #endif // BASE_VALUES_H_ | 541 #endif // BASE_VALUES_H_ |
| OLD | NEW |