| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // be used as paths. | 256 // be used as paths. |
| 257 void SetWithoutPathExpansion(const std::string& key, Value* in_value); | 257 void SetWithoutPathExpansion(const std::string& key, Value* in_value); |
| 258 | 258 |
| 259 // Gets the Value associated with the given path starting from this object. | 259 // Gets the Value associated with the given path starting from this object. |
| 260 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 260 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
| 261 // into the next DictionaryValue down. If the path can be resolved | 261 // into the next DictionaryValue down. If the path can be resolved |
| 262 // successfully, the value for the last key in the path will be returned | 262 // successfully, the value for the last key in the path will be returned |
| 263 // through the |out_value| parameter, and the function will return true. | 263 // through the |out_value| parameter, and the function will return true. |
| 264 // Otherwise, it will return false and |out_value| will be untouched. | 264 // Otherwise, it will return false and |out_value| will be untouched. |
| 265 // Note that the dictionary always owns the value that's returned. | 265 // Note that the dictionary always owns the value that's returned. |
| 266 bool Get(const std::string& path, Value** out_value) const; | 266 bool Get(const std::string& path, const Value** out_value) const; |
| 267 bool Get(const std::string& path, Value** out_value); |
| 267 | 268 |
| 268 // These are convenience forms of Get(). The value will be retrieved | 269 // These are convenience forms of Get(). The value will be retrieved |
| 269 // and the return value will be true if the path is valid and the value at | 270 // and the return value will be true if the path is valid and the value at |
| 270 // the end of the path can be returned in the form specified. | 271 // the end of the path can be returned in the form specified. |
| 271 bool GetBoolean(const std::string& path, bool* out_value) const; | 272 bool GetBoolean(const std::string& path, bool* out_value) const; |
| 272 bool GetInteger(const std::string& path, int* out_value) const; | 273 bool GetInteger(const std::string& path, int* out_value) const; |
| 273 bool GetDouble(const std::string& path, double* out_value) const; | 274 bool GetDouble(const std::string& path, double* out_value) const; |
| 274 bool GetString(const std::string& path, std::string* out_value) const; | 275 bool GetString(const std::string& path, std::string* out_value) const; |
| 275 bool GetString(const std::string& path, string16* out_value) const; | 276 bool GetString(const std::string& path, string16* out_value) const; |
| 276 bool GetStringASCII(const std::string& path, std::string* out_value) const; | 277 bool GetStringASCII(const std::string& path, std::string* out_value) const; |
| 277 bool GetBinary(const std::string& path, BinaryValue** out_value) const; | 278 bool GetBinary(const std::string& path, const BinaryValue** out_value) const; |
| 279 bool GetBinary(const std::string& path, BinaryValue** out_value); |
| 278 bool GetDictionary(const std::string& path, | 280 bool GetDictionary(const std::string& path, |
| 279 DictionaryValue** out_value) const; | 281 const DictionaryValue** out_value) const; |
| 280 bool GetList(const std::string& path, ListValue** out_value) const; | 282 bool GetDictionary(const std::string& path, DictionaryValue** out_value); |
| 283 bool GetList(const std::string& path, const ListValue** out_value) const; |
| 284 bool GetList(const std::string& path, ListValue** out_value); |
| 281 | 285 |
| 282 // Like Get(), but without special treatment of '.'. This allows e.g. URLs to | 286 // Like Get(), but without special treatment of '.'. This allows e.g. URLs to |
| 283 // be used as paths. | 287 // be used as paths. |
| 284 bool GetWithoutPathExpansion(const std::string& key, | 288 bool GetWithoutPathExpansion(const std::string& key, |
| 285 Value** out_value) const; | 289 const Value** out_value) const; |
| 290 bool GetWithoutPathExpansion(const std::string& key, Value** out_value); |
| 286 bool GetIntegerWithoutPathExpansion(const std::string& key, | 291 bool GetIntegerWithoutPathExpansion(const std::string& key, |
| 287 int* out_value) const; | 292 int* out_value) const; |
| 288 bool GetDoubleWithoutPathExpansion(const std::string& key, | 293 bool GetDoubleWithoutPathExpansion(const std::string& key, |
| 289 double* out_value) const; | 294 double* out_value) const; |
| 290 bool GetStringWithoutPathExpansion(const std::string& key, | 295 bool GetStringWithoutPathExpansion(const std::string& key, |
| 291 std::string* out_value) const; | 296 std::string* out_value) const; |
| 292 bool GetStringWithoutPathExpansion(const std::string& key, | 297 bool GetStringWithoutPathExpansion(const std::string& key, |
| 293 string16* out_value) const; | 298 string16* out_value) const; |
| 299 bool GetDictionaryWithoutPathExpansion( |
| 300 const std::string& key, |
| 301 const DictionaryValue** out_value) const; |
| 294 bool GetDictionaryWithoutPathExpansion(const std::string& key, | 302 bool GetDictionaryWithoutPathExpansion(const std::string& key, |
| 295 DictionaryValue** out_value) const; | 303 DictionaryValue** out_value); |
| 296 bool GetListWithoutPathExpansion(const std::string& key, | 304 bool GetListWithoutPathExpansion(const std::string& key, |
| 297 ListValue** out_value) const; | 305 const ListValue** out_value) const; |
| 306 bool GetListWithoutPathExpansion(const std::string& key, |
| 307 ListValue** out_value); |
| 298 | 308 |
| 299 // Removes the Value with the specified path from this dictionary (or one | 309 // Removes the Value with the specified path from this dictionary (or one |
| 300 // of its child dictionaries, if the path is more than just a local key). | 310 // of its child dictionaries, if the path is more than just a local key). |
| 301 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 311 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
| 302 // passed out via out_value. If |out_value| is NULL, the removed value will | 312 // passed out via out_value. If |out_value| is NULL, the removed value will |
| 303 // be deleted. This method returns true if |path| is a valid path; otherwise | 313 // be deleted. This method returns true if |path| is a valid path; otherwise |
| 304 // it will return false and the DictionaryValue object will be unchanged. | 314 // it will return false and the DictionaryValue object will be unchanged. |
| 305 virtual bool Remove(const std::string& path, Value** out_value); | 315 virtual bool Remove(const std::string& path, Value** out_value); |
| 306 | 316 |
| 307 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs | 317 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 | 502 |
| 493 } // namespace base | 503 } // namespace base |
| 494 | 504 |
| 495 // http://crbug.com/88666 | 505 // http://crbug.com/88666 |
| 496 using base::DictionaryValue; | 506 using base::DictionaryValue; |
| 497 using base::ListValue; | 507 using base::ListValue; |
| 498 using base::StringValue; | 508 using base::StringValue; |
| 499 using base::Value; | 509 using base::Value; |
| 500 | 510 |
| 501 #endif // BASE_VALUES_H_ | 511 #endif // BASE_VALUES_H_ |
| OLD | NEW |