OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 74 matching lines...) Loading... |
85 | 85 |
86 // These methods allow the convenient retrieval of settings. | 86 // These methods allow the convenient retrieval of settings. |
87 // If the current setting object can be converted into the given type, | 87 // If the current setting object can be converted into the given type, |
88 // the value is returned through the |out_value| parameter and true is | 88 // the value is returned through the |out_value| parameter and true is |
89 // returned; otherwise, false is returned and |out_value| is unchanged. | 89 // returned; otherwise, false is returned and |out_value| is unchanged. |
90 virtual bool GetAsBoolean(bool* out_value) const; | 90 virtual bool GetAsBoolean(bool* out_value) const; |
91 virtual bool GetAsInteger(int* out_value) const; | 91 virtual bool GetAsInteger(int* out_value) const; |
92 virtual bool GetAsReal(double* out_value) const; | 92 virtual bool GetAsReal(double* out_value) const; |
93 virtual bool GetAsString(std::string* out_value) const; | 93 virtual bool GetAsString(std::string* out_value) const; |
94 virtual bool GetAsString(string16* out_value) const; | 94 virtual bool GetAsString(string16* out_value) const; |
| 95 virtual bool GetAsList(ListValue** out_value); |
95 | 96 |
96 // This creates a deep copy of the entire Value tree, and returns a pointer | 97 // This creates a deep copy of the entire Value tree, and returns a pointer |
97 // to the copy. The caller gets ownership of the copy, of course. | 98 // to the copy. The caller gets ownership of the copy, of course. |
98 virtual Value* DeepCopy() const; | 99 virtual Value* DeepCopy() const; |
99 | 100 |
100 // Compares if two Value objects have equal contents. | 101 // Compares if two Value objects have equal contents. |
101 virtual bool Equals(const Value* other) const; | 102 virtual bool Equals(const Value* other) const; |
102 | 103 |
103 // Compares if two Value objects have equal contents. Can handle NULLs. | 104 // Compares if two Value objects have equal contents. Can handle NULLs. |
104 // NULLs are considered equal but different from Value::CreateNullValue(). | 105 // NULLs are considered equal but different from Value::CreateNullValue(). |
(...skipping 254 matching lines...) Loading... |
359 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); | 360 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); |
360 }; | 361 }; |
361 | 362 |
362 // This type of Value represents a list of other Value values. | 363 // This type of Value represents a list of other Value values. |
363 class ListValue : public Value { | 364 class ListValue : public Value { |
364 public: | 365 public: |
365 ListValue(); | 366 ListValue(); |
366 ~ListValue(); | 367 ~ListValue(); |
367 | 368 |
368 // Subclassed methods | 369 // Subclassed methods |
| 370 virtual bool GetAsList(ListValue** out_value); |
369 Value* DeepCopy() const; | 371 Value* DeepCopy() const; |
370 virtual bool Equals(const Value* other) const; | 372 virtual bool Equals(const Value* other) const; |
371 | 373 |
372 // Clears the contents of this ListValue | 374 // Clears the contents of this ListValue |
373 void Clear(); | 375 void Clear(); |
374 | 376 |
375 // Returns the number of Values in this list. | 377 // Returns the number of Values in this list. |
376 size_t GetSize() const { return list_.size(); } | 378 size_t GetSize() const { return list_.size(); } |
377 | 379 |
378 // Returns whether the list is empty. | 380 // Returns whether the list is empty. |
(...skipping 77 matching lines...) Loading... |
456 // This method deserializes the subclass-specific format into a Value object. | 458 // This method deserializes the subclass-specific format into a Value object. |
457 // If the return value is non-NULL, the caller takes ownership of returned | 459 // If the return value is non-NULL, the caller takes ownership of returned |
458 // Value. If the return value is NULL, and if error_code is non-NULL, | 460 // Value. If the return value is NULL, and if error_code is non-NULL, |
459 // error_code will be set with the underlying error. | 461 // error_code will be set with the underlying error. |
460 // If |error_message| is non-null, it will be filled in with a formatted | 462 // If |error_message| is non-null, it will be filled in with a formatted |
461 // error message including the location of the error if appropriate. | 463 // error message including the location of the error if appropriate. |
462 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; | 464 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; |
463 }; | 465 }; |
464 | 466 |
465 #endif // BASE_VALUES_H_ | 467 #endif // BASE_VALUES_H_ |
OLD | NEW |