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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 void SetBoolean(const std::string& path, bool in_value); | 249 void SetBoolean(const std::string& path, bool in_value); |
250 void SetInteger(const std::string& path, int in_value); | 250 void SetInteger(const std::string& path, int in_value); |
251 void SetDouble(const std::string& path, double in_value); | 251 void SetDouble(const std::string& path, double in_value); |
252 void SetString(const std::string& path, const std::string& in_value); | 252 void SetString(const std::string& path, const std::string& in_value); |
253 void SetString(const std::string& path, const string16& in_value); | 253 void SetString(const std::string& path, const string16& in_value); |
254 | 254 |
255 // Like Set(), but without special treatment of '.'. This allows e.g. URLs to | 255 // Like Set(), but without special treatment of '.'. This allows e.g. URLs to |
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 // Convenience forms of SetWithoutPathExpansion(). |
| 260 void SetBooleanWithoutPathExpansion(const std::string& path, bool in_value); |
| 261 void SetIntegerWithoutPathExpansion(const std::string& path, int in_value); |
| 262 void SetDoubleWithoutPathExpansion(const std::string& path, double in_value); |
| 263 void SetStringWithoutPathExpansion(const std::string& path, |
| 264 const std::string& in_value); |
| 265 void SetStringWithoutPathExpansion(const std::string& path, |
| 266 const string16& in_value); |
| 267 |
259 // Gets the Value associated with the given path starting from this object. | 268 // Gets the Value associated with the given path starting from this object. |
260 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 269 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
261 // into the next DictionaryValue down. If the path can be resolved | 270 // 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 | 271 // 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. | 272 // through the |out_value| parameter, and the function will return true. |
264 // Otherwise, it will return false and |out_value| will be untouched. | 273 // Otherwise, it will return false and |out_value| will be untouched. |
265 // Note that the dictionary always owns the value that's returned. | 274 // Note that the dictionary always owns the value that's returned. |
266 bool Get(const std::string& path, const Value** out_value) const; | 275 bool Get(const std::string& path, const Value** out_value) const; |
267 bool Get(const std::string& path, Value** out_value); | 276 bool Get(const std::string& path, Value** out_value); |
268 | 277 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // if not found. | 454 // if not found. |
446 bool Remove(const Value& value, size_t* index); | 455 bool Remove(const Value& value, size_t* index); |
447 | 456 |
448 // Removes the element at |iter|. If |out_value| is NULL, the value will be | 457 // Removes the element at |iter|. If |out_value| is NULL, the value will be |
449 // deleted, otherwise ownership of the value is passed back to the caller. | 458 // deleted, otherwise ownership of the value is passed back to the caller. |
450 void Erase(iterator iter, Value** out_value); | 459 void Erase(iterator iter, Value** out_value); |
451 | 460 |
452 // Appends a Value to the end of the list. | 461 // Appends a Value to the end of the list. |
453 void Append(Value* in_value); | 462 void Append(Value* in_value); |
454 | 463 |
| 464 // Convenience forms of Append. |
| 465 void AppendBoolean(bool in_value); |
| 466 void AppendInteger(int in_value); |
| 467 void AppendDouble(double in_value); |
| 468 void AppendString(const std::string& in_value); |
| 469 void AppendString(const string16& in_value); |
| 470 void AppendStrings(const std::vector<std::string>& in_values); |
| 471 void AppendStrings(const std::vector<string16>& in_values); |
| 472 |
455 // Appends a Value if it's not already present. Takes ownership of the | 473 // Appends a Value if it's not already present. Takes ownership of the |
456 // |in_value|. Returns true if successful, or false if the value was already | 474 // |in_value|. Returns true if successful, or false if the value was already |
457 // present. If the value was already present the |in_value| is deleted. | 475 // present. If the value was already present the |in_value| is deleted. |
458 bool AppendIfNotPresent(Value* in_value); | 476 bool AppendIfNotPresent(Value* in_value); |
459 | 477 |
460 // Insert a Value at index. | 478 // Insert a Value at index. |
461 // Returns true if successful, or false if the index was out of range. | 479 // Returns true if successful, or false if the index was out of range. |
462 bool Insert(size_t index, Value* in_value); | 480 bool Insert(size_t index, Value* in_value); |
463 | 481 |
464 // Searches for the first instance of |value| in the list using the Equals | 482 // Searches for the first instance of |value| in the list using the Equals |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 528 |
511 } // namespace base | 529 } // namespace base |
512 | 530 |
513 // http://crbug.com/88666 | 531 // http://crbug.com/88666 |
514 using base::DictionaryValue; | 532 using base::DictionaryValue; |
515 using base::ListValue; | 533 using base::ListValue; |
516 using base::StringValue; | 534 using base::StringValue; |
517 using base::Value; | 535 using base::Value; |
518 | 536 |
519 #endif // BASE_VALUES_H_ | 537 #endif // BASE_VALUES_H_ |
OLD | NEW |