OLD | NEW |
1 // Copyright (c) 2011 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 // 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 setting and other persistable data. It includes the ability to | 6 // storing setting and other persistable data. It includes the ability to |
7 // specify (recursive) lists and dictionaries, so it's fairly expressive. | 7 // specify (recursive) lists and dictionaries, so it's fairly expressive. |
8 // However, the API is optimized for the common case, namely storing a | 8 // However, the API is optimized for the common case, namely storing a |
9 // hierarchical tree of simple values. Given a DictionaryValue root, you can | 9 // hierarchical tree of simple values. Given a DictionaryValue root, you can |
10 // easily do things like: | 10 // easily do things like: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // These methods allow the convenient retrieval of settings. | 87 // These methods allow the convenient retrieval of settings. |
88 // If the current setting object can be converted into the given type, | 88 // If the current setting object can be converted into the given type, |
89 // the value is returned through the |out_value| parameter and true is | 89 // the value is returned through the |out_value| parameter and true is |
90 // returned; otherwise, false is returned and |out_value| is unchanged. | 90 // returned; otherwise, false is returned and |out_value| is unchanged. |
91 virtual bool GetAsBoolean(bool* out_value) const; | 91 virtual bool GetAsBoolean(bool* out_value) const; |
92 virtual bool GetAsInteger(int* out_value) const; | 92 virtual bool GetAsInteger(int* out_value) const; |
93 virtual bool GetAsDouble(double* out_value) const; | 93 virtual bool GetAsDouble(double* out_value) const; |
94 virtual bool GetAsString(std::string* out_value) const; | 94 virtual bool GetAsString(std::string* out_value) const; |
95 virtual bool GetAsString(string16* out_value) const; | 95 virtual bool GetAsString(string16* out_value) const; |
96 virtual bool GetAsList(ListValue** out_value); | 96 virtual bool GetAsList(ListValue** out_value); |
| 97 virtual bool GetAsList(const ListValue** out_value) const; |
97 | 98 |
98 // This creates a deep copy of the entire Value tree, and returns a pointer | 99 // This creates a deep copy of the entire Value tree, and returns a pointer |
99 // to the copy. The caller gets ownership of the copy, of course. | 100 // to the copy. The caller gets ownership of the copy, of course. |
100 // | 101 // |
101 // Subclasses return their own type directly in their overrides; | 102 // Subclasses return their own type directly in their overrides; |
102 // this works because C++ supports covariant return types. | 103 // this works because C++ supports covariant return types. |
103 virtual Value* DeepCopy() const; | 104 virtual Value* DeepCopy() const; |
104 | 105 |
105 // Compares if two Value objects have equal contents. | 106 // Compares if two Value objects have equal contents. |
106 virtual bool Equals(const Value* other) const; | 107 virtual bool Equals(const Value* other) const; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 421 |
421 // Iteration | 422 // Iteration |
422 ListValue::iterator begin() { return list_.begin(); } | 423 ListValue::iterator begin() { return list_.begin(); } |
423 ListValue::iterator end() { return list_.end(); } | 424 ListValue::iterator end() { return list_.end(); } |
424 | 425 |
425 ListValue::const_iterator begin() const { return list_.begin(); } | 426 ListValue::const_iterator begin() const { return list_.begin(); } |
426 ListValue::const_iterator end() const { return list_.end(); } | 427 ListValue::const_iterator end() const { return list_.end(); } |
427 | 428 |
428 // Overridden from Value: | 429 // Overridden from Value: |
429 virtual bool GetAsList(ListValue** out_value); | 430 virtual bool GetAsList(ListValue** out_value); |
| 431 virtual bool GetAsList(const ListValue** out_value) const; |
430 virtual ListValue* DeepCopy() const; | 432 virtual ListValue* DeepCopy() const; |
431 virtual bool Equals(const Value* other) const; | 433 virtual bool Equals(const Value* other) const; |
432 | 434 |
433 private: | 435 private: |
434 ValueVector list_; | 436 ValueVector list_; |
435 | 437 |
436 DISALLOW_COPY_AND_ASSIGN(ListValue); | 438 DISALLOW_COPY_AND_ASSIGN(ListValue); |
437 }; | 439 }; |
438 | 440 |
439 // This interface is implemented by classes that know how to serialize and | 441 // This interface is implemented by classes that know how to serialize and |
440 // deserialize Value objects. | 442 // deserialize Value objects. |
441 class BASE_API ValueSerializer { | 443 class BASE_API ValueSerializer { |
442 public: | 444 public: |
443 virtual ~ValueSerializer(); | 445 virtual ~ValueSerializer(); |
444 | 446 |
445 virtual bool Serialize(const Value& root) = 0; | 447 virtual bool Serialize(const Value& root) = 0; |
446 | 448 |
447 // This method deserializes the subclass-specific format into a Value object. | 449 // This method deserializes the subclass-specific format into a Value object. |
448 // If the return value is non-NULL, the caller takes ownership of returned | 450 // If the return value is non-NULL, the caller takes ownership of returned |
449 // Value. If the return value is NULL, and if error_code is non-NULL, | 451 // Value. If the return value is NULL, and if error_code is non-NULL, |
450 // error_code will be set with the underlying error. | 452 // error_code will be set with the underlying error. |
451 // If |error_message| is non-null, it will be filled in with a formatted | 453 // If |error_message| is non-null, it will be filled in with a formatted |
452 // error message including the location of the error if appropriate. | 454 // error message including the location of the error if appropriate. |
453 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; | 455 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; |
454 }; | 456 }; |
455 | 457 |
456 #endif // BASE_VALUES_H_ | 458 #endif // BASE_VALUES_H_ |
OLD | NEW |