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 #if !defined(WCHAR_T_IS_UTF16) | |
96 /*DEPRECATED*/virtual bool GetAsString(std::wstring* out_value) const; | |
97 #endif | |
98 | 95 |
99 // This creates a deep copy of the entire Value tree, and returns a pointer | 96 // This creates a deep copy of the entire Value tree, and returns a pointer |
100 // to the copy. The caller gets ownership of the copy, of course. | 97 // to the copy. The caller gets ownership of the copy, of course. |
101 virtual Value* DeepCopy() const; | 98 virtual Value* DeepCopy() const; |
102 | 99 |
103 // Compares if two Value objects have equal contents. | 100 // Compares if two Value objects have equal contents. |
104 virtual bool Equals(const Value* other) const; | 101 virtual bool Equals(const Value* other) const; |
105 | 102 |
106 protected: | 103 protected: |
107 // This isn't safe for end-users (they should use the Create*Value() | 104 // This isn't safe for end-users (they should use the Create*Value() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 #if !defined(WCHAR_T_IS_UTF16) | 149 #if !defined(WCHAR_T_IS_UTF16) |
153 // Initializes a StringValue with a wide character string. | 150 // Initializes a StringValue with a wide character string. |
154 /*DEPRECATED*/explicit StringValue(const std::wstring& in_value); | 151 /*DEPRECATED*/explicit StringValue(const std::wstring& in_value); |
155 #endif | 152 #endif |
156 | 153 |
157 ~StringValue(); | 154 ~StringValue(); |
158 | 155 |
159 // Subclassed methods | 156 // Subclassed methods |
160 bool GetAsString(std::string* out_value) const; | 157 bool GetAsString(std::string* out_value) const; |
161 bool GetAsString(string16* out_value) const; | 158 bool GetAsString(string16* out_value) const; |
162 #if !defined(WCHAR_T_IS_UTF16) | |
163 /*DEPRECATED*/bool GetAsString(std::wstring* out_value) const; | |
164 #endif | |
165 Value* DeepCopy() const; | 159 Value* DeepCopy() const; |
166 virtual bool Equals(const Value* other) const; | 160 virtual bool Equals(const Value* other) const; |
167 | 161 |
168 private: | 162 private: |
169 std::string value_; | 163 std::string value_; |
170 | 164 |
171 DISALLOW_COPY_AND_ASSIGN(StringValue); | 165 DISALLOW_COPY_AND_ASSIGN(StringValue); |
172 }; | 166 }; |
173 | 167 |
174 class BinaryValue: public Value { | 168 class BinaryValue: public Value { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 bool GetString(const std::string& path, string16* out_value) const; | 280 bool GetString(const std::string& path, string16* out_value) const; |
287 bool GetStringASCII(const std::string& path, std::string* out_value) const; | 281 bool GetStringASCII(const std::string& path, std::string* out_value) const; |
288 bool GetBinary(const std::string& path, BinaryValue** out_value) const; | 282 bool GetBinary(const std::string& path, BinaryValue** out_value) const; |
289 bool GetDictionary(const std::string& path, | 283 bool GetDictionary(const std::string& path, |
290 DictionaryValue** out_value) const; | 284 DictionaryValue** out_value) const; |
291 bool GetList(const std::string& path, ListValue** out_value) const; | 285 bool GetList(const std::string& path, ListValue** out_value) const; |
292 /*DEPRECATED*/bool GetBoolean(const std::wstring& path, | 286 /*DEPRECATED*/bool GetBoolean(const std::wstring& path, |
293 bool* out_value) const; | 287 bool* out_value) const; |
294 /*DEPRECATED*/bool GetInteger(const std::wstring& path, int* out_value) const; | 288 /*DEPRECATED*/bool GetInteger(const std::wstring& path, int* out_value) const; |
295 /*DEPRECATED*/bool GetReal(const std::wstring& path, double* out_value) const; | 289 /*DEPRECATED*/bool GetReal(const std::wstring& path, double* out_value) const; |
296 /*DEPRECATED*/bool GetString(const std::wstring& path, | |
297 std::string* out_value) const; | |
298 /*DEPRECATED*/bool GetString(const std::wstring& path, | |
299 std::wstring* out_value) const; | |
300 /*DEPRECATED*/bool GetBinary(const std::wstring& path, | 290 /*DEPRECATED*/bool GetBinary(const std::wstring& path, |
301 BinaryValue** out_value) const; | 291 BinaryValue** out_value) const; |
302 /*DEPRECATED*/bool GetDictionary(const std::wstring& path, | 292 /*DEPRECATED*/bool GetDictionary(const std::wstring& path, |
303 DictionaryValue** out_value) const; | 293 DictionaryValue** out_value) const; |
304 /*DEPRECATED*/bool GetList(const std::wstring& path, | 294 /*DEPRECATED*/bool GetList(const std::wstring& path, |
305 ListValue** out_value) const; | 295 ListValue** out_value) const; |
306 | 296 |
307 // Like Get(), but without special treatment of '.'. This allows e.g. URLs to | 297 // Like Get(), but without special treatment of '.'. This allows e.g. URLs to |
308 // be used as paths. | 298 // be used as paths. |
309 bool GetWithoutPathExpansion(const std::string& key, | 299 bool GetWithoutPathExpansion(const std::string& key, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 bool Get(size_t index, Value** out_value) const; | 416 bool Get(size_t index, Value** out_value) const; |
427 | 417 |
428 // Convenience forms of Get(). Modifies |out_value| (and returns true) | 418 // Convenience forms of Get(). Modifies |out_value| (and returns true) |
429 // only if the index is valid and the Value at that index can be returned | 419 // only if the index is valid and the Value at that index can be returned |
430 // in the specified form. | 420 // in the specified form. |
431 bool GetBoolean(size_t index, bool* out_value) const; | 421 bool GetBoolean(size_t index, bool* out_value) const; |
432 bool GetInteger(size_t index, int* out_value) const; | 422 bool GetInteger(size_t index, int* out_value) const; |
433 bool GetReal(size_t index, double* out_value) const; | 423 bool GetReal(size_t index, double* out_value) const; |
434 bool GetString(size_t index, std::string* out_value) const; | 424 bool GetString(size_t index, std::string* out_value) const; |
435 bool GetString(size_t index, string16* out_value) const; | 425 bool GetString(size_t index, string16* out_value) const; |
436 #if !defined(WCHAR_T_IS_UTF16) | |
437 /*DEPRECATED*/bool GetString(size_t index, std::wstring* out_value) const; | |
438 #endif | |
439 bool GetBinary(size_t index, BinaryValue** out_value) const; | 426 bool GetBinary(size_t index, BinaryValue** out_value) const; |
440 bool GetDictionary(size_t index, DictionaryValue** out_value) const; | 427 bool GetDictionary(size_t index, DictionaryValue** out_value) const; |
441 bool GetList(size_t index, ListValue** out_value) const; | 428 bool GetList(size_t index, ListValue** out_value) const; |
442 | 429 |
443 // Removes the Value with the specified index from this list. | 430 // Removes the Value with the specified index from this list. |
444 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 431 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
445 // passed out via |out_value|. If |out_value| is NULL, the removed value will | 432 // passed out via |out_value|. If |out_value| is NULL, the removed value will |
446 // be deleted. This method returns true if |index| is valid; otherwise | 433 // be deleted. This method returns true if |index| is valid; otherwise |
447 // it will return false and the ListValue object will be unchanged. | 434 // it will return false and the ListValue object will be unchanged. |
448 bool Remove(size_t index, Value** out_value); | 435 bool Remove(size_t index, Value** out_value); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 // This method deserializes the subclass-specific format into a Value object. | 476 // This method deserializes the subclass-specific format into a Value object. |
490 // If the return value is non-NULL, the caller takes ownership of returned | 477 // If the return value is non-NULL, the caller takes ownership of returned |
491 // Value. If the return value is NULL, and if error_code is non-NULL, | 478 // Value. If the return value is NULL, and if error_code is non-NULL, |
492 // error_code will be set with the underlying error. | 479 // error_code will be set with the underlying error. |
493 // If |error_message| is non-null, it will be filled in with a formatted | 480 // If |error_message| is non-null, it will be filled in with a formatted |
494 // error message including the location of the error if appropriate. | 481 // error message including the location of the error if appropriate. |
495 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; | 482 virtual Value* Deserialize(int* error_code, std::string* error_str) = 0; |
496 }; | 483 }; |
497 | 484 |
498 #endif // BASE_VALUES_H_ | 485 #endif // BASE_VALUES_H_ |
OLD | NEW |