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...) Expand 10 before | Expand all | Expand 10 after 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 protected: | 104 protected: |
104 // This isn't safe for end-users (they should use the Create*Value() | 105 // This isn't safe for end-users (they should use the Create*Value() |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); | 356 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); |
356 }; | 357 }; |
357 | 358 |
358 // This type of Value represents a list of other Value values. | 359 // This type of Value represents a list of other Value values. |
359 class ListValue : public Value { | 360 class ListValue : public Value { |
360 public: | 361 public: |
361 ListValue(); | 362 ListValue(); |
362 ~ListValue(); | 363 ~ListValue(); |
363 | 364 |
364 // Subclassed methods | 365 // Subclassed methods |
| 366 virtual bool GetAsList(ListValue** out_value); |
365 Value* DeepCopy() const; | 367 Value* DeepCopy() const; |
366 virtual bool Equals(const Value* other) const; | 368 virtual bool Equals(const Value* other) const; |
367 | 369 |
368 // Clears the contents of this ListValue | 370 // Clears the contents of this ListValue |
369 void Clear(); | 371 void Clear(); |
370 | 372 |
371 // Returns the number of Values in this list. | 373 // Returns the number of Values in this list. |
372 size_t GetSize() const { return list_.size(); } | 374 size_t GetSize() const { return list_.size(); } |
373 | 375 |
374 // Returns whether the list is empty. | 376 // Returns whether the list is empty. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 // This method deserializes the subclass-specific format into a Value object. | 454 // This method deserializes the subclass-specific format into a Value object. |
453 // If the return value is non-NULL, the caller takes ownership of returned | 455 // If the return value is non-NULL, the caller takes ownership of returned |
454 // Value. If the return value is NULL, and if error_code is non-NULL, | 456 // Value. If the return value is NULL, and if error_code is non-NULL, |
455 // error_code will be set with the underlying error. | 457 // error_code will be set with the underlying error. |
456 // If |error_message| is non-null, it will be filled in with a formatted | 458 // If |error_message| is non-null, it will be filled in with a formatted |
457 // error message including the location of the error if appropriate. | 459 // error message including the location of the error if appropriate. |
458 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; | 460 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; |
459 }; | 461 }; |
460 | 462 |
461 #endif // BASE_VALUES_H_ | 463 #endif // BASE_VALUES_H_ |
OLD | NEW |