| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 class Value; | 42 class Value; |
| 43 | 43 |
| 44 // The Value class is the base class for Values. A Value can be instantiated | 44 // The Value class is the base class for Values. A Value can be instantiated |
| 45 // via the Create*Value() factory methods, or by directly creating instances of | 45 // via the Create*Value() factory methods, or by directly creating instances of |
| 46 // the subclasses. | 46 // the subclasses. |
| 47 // | 47 // |
| 48 // See the file-level comment above for more information. | 48 // See the file-level comment above for more information. |
| 49 class BASE_EXPORT Value { | 49 class BASE_EXPORT Value { |
| 50 public: | 50 public: |
| 51 using DictStorage = base::flat_map<std::string, std::unique_ptr<Value>>; | 51 using DictStorage = base::flat_map<std::string, std::unique_ptr<Value>>; |
| 52 using ListStorage = std::vector<std::unique_ptr<Value>>; | 52 using ListStorage = std::vector<Value>; |
| 53 | 53 |
| 54 enum class Type { | 54 enum class Type { |
| 55 NONE = 0, | 55 NONE = 0, |
| 56 BOOLEAN, | 56 BOOLEAN, |
| 57 INTEGER, | 57 INTEGER, |
| 58 DOUBLE, | 58 DOUBLE, |
| 59 STRING, | 59 STRING, |
| 60 BINARY, | 60 BINARY, |
| 61 DICTIONARY, | 61 DICTIONARY, |
| 62 LIST | 62 LIST |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); | 383 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); |
| 384 | 384 |
| 385 ListValue(); | 385 ListValue(); |
| 386 | 386 |
| 387 // Clears the contents of this ListValue | 387 // Clears the contents of this ListValue |
| 388 void Clear(); | 388 void Clear(); |
| 389 | 389 |
| 390 // Returns the number of Values in this list. | 390 // Returns the number of Values in this list. |
| 391 size_t GetSize() const { return list_->size(); } | 391 size_t GetSize() const { return list_->size(); } |
| 392 | 392 |
| 393 // Returns the capacity of storage for Values in this list. |
| 394 size_t capacity() const { return list_->capacity(); } |
| 395 |
| 393 // Returns whether the list is empty. | 396 // Returns whether the list is empty. |
| 394 bool empty() const { return list_->empty(); } | 397 bool empty() const { return list_->empty(); } |
| 395 | 398 |
| 399 // Reserves storage for at least |n| values. |
| 400 void Reserve(size_t n); |
| 401 |
| 396 // Sets the list item at the given index to be the Value specified by | 402 // Sets the list item at the given index to be the Value specified by |
| 397 // the value given. If the index beyond the current end of the list, null | 403 // the value given. If the index beyond the current end of the list, null |
| 398 // Values will be used to pad out the list. | 404 // Values will be used to pad out the list. |
| 399 // Returns true if successful, or false if the index was negative or | 405 // Returns true if successful, or false if the index was negative or |
| 400 // the value is a null pointer. | 406 // the value is a null pointer. |
| 401 bool Set(size_t index, Value* in_value); | 407 bool Set(size_t index, Value* in_value); |
| 402 // Preferred version of the above. TODO(estade): remove the above. | 408 // Preferred version of the above. TODO(estade): remove the above. |
| 403 bool Set(size_t index, std::unique_ptr<Value> in_value); | 409 bool Set(size_t index, std::unique_ptr<Value> in_value); |
| 404 | 410 |
| 405 // Gets the Value at the given index. Modifies |out_value| (and returns true) | 411 // Gets the Value at the given index. Modifies |out_value| (and returns true) |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 return out << static_cast<const Value&>(value); | 538 return out << static_cast<const Value&>(value); |
| 533 } | 539 } |
| 534 | 540 |
| 535 // Stream operator so that enum class Types can be used in log statements. | 541 // Stream operator so that enum class Types can be used in log statements. |
| 536 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 542 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
| 537 const Value::Type& type); | 543 const Value::Type& type); |
| 538 | 544 |
| 539 } // namespace base | 545 } // namespace base |
| 540 | 546 |
| 541 #endif // BASE_VALUES_H_ | 547 #endif // BASE_VALUES_H_ |
| OLD | NEW |