| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 5 // This file specifies a recursive data storage class called Value |
| 6 // intended for storing setting and other persistable data. | 6 // intended for storing setting and other persistable data. |
| 7 // It includes the ability to specify (recursive) lists and dictionaries, so | 7 // It includes the ability to specify (recursive) lists and dictionaries, so |
| 8 // it's fairly expressive. However, the API is optimized for the common case, | 8 // it's fairly expressive. However, the API is optimized for the common case, |
| 9 // namely storing a hierarchical tree of simple values. Given a | 9 // namely storing a hierarchical tree of simple values. Given a |
| 10 // DictionaryValue root, you can easily do things like: | 10 // DictionaryValue root, you can easily do things like: |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 class DictionaryValue : public Value { | 207 class DictionaryValue : public Value { |
| 208 public: | 208 public: |
| 209 DictionaryValue() : Value(TYPE_DICTIONARY) {} | 209 DictionaryValue() : Value(TYPE_DICTIONARY) {} |
| 210 ~DictionaryValue(); | 210 ~DictionaryValue(); |
| 211 | 211 |
| 212 // Subclassed methods | 212 // Subclassed methods |
| 213 Value* DeepCopy() const; | 213 Value* DeepCopy() const; |
| 214 virtual bool Equals(const Value* other) const; | 214 virtual bool Equals(const Value* other) const; |
| 215 | 215 |
| 216 // Returns true if the current dictionary has a value for the given key. | 216 // Returns true if the current dictionary has a value for the given key. |
| 217 bool HasKeyASCII(const std::string& key) const; |
| 218 // Deprecated version of the above. TODO: add a string16 version for Unicode. |
| 219 // http://code.google.com/p/chromium/issues/detail?id=23581 |
| 217 bool HasKey(const std::wstring& key) const; | 220 bool HasKey(const std::wstring& key) const; |
| 218 | 221 |
| 219 // Returns the number of Values in this dictionary. | 222 // Returns the number of Values in this dictionary. |
| 220 size_t size() const { return dictionary_.size(); } | 223 size_t size() const { return dictionary_.size(); } |
| 221 | 224 |
| 222 // Returns whether the dictionary is empty. | 225 // Returns whether the dictionary is empty. |
| 223 bool empty() const { return dictionary_.empty(); } | 226 bool empty() const { return dictionary_.empty(); } |
| 224 | 227 |
| 225 // Clears any current contents of this dictionary. | 228 // Clears any current contents of this dictionary. |
| 226 void Clear(); | 229 void Clear(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 257 // Otherwise, it will return false and "value" will be untouched. | 260 // Otherwise, it will return false and "value" will be untouched. |
| 258 // Note that the dictionary always owns the value that's returned. | 261 // Note that the dictionary always owns the value that's returned. |
| 259 bool Get(const std::wstring& path, Value** out_value) const; | 262 bool Get(const std::wstring& path, Value** out_value) const; |
| 260 | 263 |
| 261 // These are convenience forms of Get(). The value will be retrieved | 264 // These are convenience forms of Get(). The value will be retrieved |
| 262 // and the return value will be true if the path is valid and the value at | 265 // and the return value will be true if the path is valid and the value at |
| 263 // the end of the path can be returned in the form specified. | 266 // the end of the path can be returned in the form specified. |
| 264 bool GetBoolean(const std::wstring& path, bool* out_value) const; | 267 bool GetBoolean(const std::wstring& path, bool* out_value) const; |
| 265 bool GetInteger(const std::wstring& path, int* out_value) const; | 268 bool GetInteger(const std::wstring& path, int* out_value) const; |
| 266 bool GetReal(const std::wstring& path, double* out_value) const; | 269 bool GetReal(const std::wstring& path, double* out_value) const; |
| 270 bool GetString(const std::string& path, string16* out_value) const; |
| 271 bool GetStringASCII(const std::string& path, std::string* out_value) const; |
| 272 // TODO: deprecate wstring accessors. |
| 273 // http://code.google.com/p/chromium/issues/detail?id=23581 |
| 267 bool GetString(const std::wstring& path, std::string* out_value) const; | 274 bool GetString(const std::wstring& path, std::string* out_value) const; |
| 268 bool GetString(const std::wstring& path, std::wstring* out_value) const; | 275 bool GetString(const std::wstring& path, std::wstring* out_value) const; |
| 269 bool GetStringAsUTF16(const std::wstring& path, string16* out_value) const; | 276 bool GetStringAsUTF16(const std::wstring& path, string16* out_value) const; |
| 270 bool GetBinary(const std::wstring& path, BinaryValue** out_value) const; | 277 bool GetBinary(const std::wstring& path, BinaryValue** out_value) const; |
| 271 bool GetDictionary(const std::wstring& path, | 278 bool GetDictionary(const std::wstring& path, |
| 272 DictionaryValue** out_value) const; | 279 DictionaryValue** out_value) const; |
| 273 bool GetList(const std::wstring& path, ListValue** out_value) const; | 280 bool GetList(const std::wstring& path, ListValue** out_value) const; |
| 274 | 281 |
| 275 // Like Get(), but without special treatment of '.'. This allows e.g. URLs to | 282 // Like Get(), but without special treatment of '.'. This allows e.g. URLs to |
| 276 // be used as paths. | 283 // be used as paths. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 virtual bool Serialize(const Value& root) = 0; | 430 virtual bool Serialize(const Value& root) = 0; |
| 424 | 431 |
| 425 // This method deserializes the subclass-specific format into a Value object. | 432 // This method deserializes the subclass-specific format into a Value object. |
| 426 // If the return value is non-NULL, the caller takes ownership of returned | 433 // If the return value is non-NULL, the caller takes ownership of returned |
| 427 // Value. If the return value is NULL, and if error_message is non-NULL, | 434 // Value. If the return value is NULL, and if error_message is non-NULL, |
| 428 // error_message should be filled with a message describing the error. | 435 // error_message should be filled with a message describing the error. |
| 429 virtual Value* Deserialize(std::string* error_message) = 0; | 436 virtual Value* Deserialize(std::string* error_message) = 0; |
| 430 }; | 437 }; |
| 431 | 438 |
| 432 #endif // BASE_VALUES_H_ | 439 #endif // BASE_VALUES_H_ |
| OLD | NEW |