OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 DictionaryValue** out_value) const; | 296 DictionaryValue** out_value) const; |
297 bool GetListWithoutPathExpansion(const std::string& key, | 297 bool GetListWithoutPathExpansion(const std::string& key, |
298 ListValue** out_value) const; | 298 ListValue** out_value) const; |
299 | 299 |
300 // Removes the Value with the specified path from this dictionary (or one | 300 // Removes the Value with the specified path from this dictionary (or one |
301 // of its child dictionaries, if the path is more than just a local key). | 301 // of its child dictionaries, if the path is more than just a local key). |
302 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 302 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
303 // passed out via out_value. If |out_value| is NULL, the removed value will | 303 // passed out via out_value. If |out_value| is NULL, the removed value will |
304 // be deleted. This method returns true if |path| is a valid path; otherwise | 304 // be deleted. This method returns true if |path| is a valid path; otherwise |
305 // it will return false and the DictionaryValue object will be unchanged. | 305 // it will return false and the DictionaryValue object will be unchanged. |
306 bool Remove(const std::string& path, Value** out_value); | 306 virtual bool Remove(const std::string& path, Value** out_value); |
307 | 307 |
308 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs | 308 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs |
309 // to be used as paths. | 309 // to be used as paths. |
310 bool RemoveWithoutPathExpansion(const std::string& key, Value** out_value); | 310 virtual bool RemoveWithoutPathExpansion(const std::string& key, |
| 311 Value** out_value); |
311 | 312 |
312 // Makes a copy of |this| but doesn't include empty dictionaries and lists in | 313 // Makes a copy of |this| but doesn't include empty dictionaries and lists in |
313 // the copy. This never returns NULL, even if |this| itself is empty. | 314 // the copy. This never returns NULL, even if |this| itself is empty. |
314 DictionaryValue* DeepCopyWithoutEmptyChildren(); | 315 DictionaryValue* DeepCopyWithoutEmptyChildren(); |
315 | 316 |
316 // Merge a given dictionary into this dictionary. This is done recursively, | 317 // Merge a given dictionary into this dictionary. This is done recursively, |
317 // i.e. any subdictionaries will be merged as well. In case of key collisions, | 318 // i.e. any subdictionaries will be merged as well. In case of key collisions, |
318 // the passed in dictionary takes precedence and data already present will be | 319 // the passed in dictionary takes precedence and data already present will be |
319 // replaced. | 320 // replaced. |
320 void MergeDictionary(const DictionaryValue* dictionary); | 321 void MergeDictionary(const DictionaryValue* dictionary); |
321 | 322 |
322 // Swaps contents with the |other| dictionary. | 323 // Swaps contents with the |other| dictionary. |
323 void Swap(DictionaryValue* other) { | 324 virtual void Swap(DictionaryValue* other); |
324 dictionary_.swap(other->dictionary_); | |
325 } | |
326 | 325 |
327 // This class provides an iterator for the keys in the dictionary. | 326 // This class provides an iterator for the keys in the dictionary. |
328 // It can't be used to modify the dictionary. | 327 // It can't be used to modify the dictionary. |
329 // | 328 // |
330 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT | 329 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT |
331 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any | 330 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any |
332 // keys have '.'s in them. | 331 // keys have '.'s in them. |
333 class key_iterator | 332 class key_iterator |
334 : private std::iterator<std::input_iterator_tag, const std::string> { | 333 : private std::iterator<std::input_iterator_tag, const std::string> { |
335 public: | 334 public: |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 bool GetString(size_t index, string16* out_value) const; | 416 bool GetString(size_t index, string16* out_value) const; |
418 bool GetBinary(size_t index, BinaryValue** out_value) const; | 417 bool GetBinary(size_t index, BinaryValue** out_value) const; |
419 bool GetDictionary(size_t index, DictionaryValue** out_value) const; | 418 bool GetDictionary(size_t index, DictionaryValue** out_value) const; |
420 bool GetList(size_t index, ListValue** out_value) const; | 419 bool GetList(size_t index, ListValue** out_value) const; |
421 | 420 |
422 // Removes the Value with the specified index from this list. | 421 // Removes the Value with the specified index from this list. |
423 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 422 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
424 // passed out via |out_value|. If |out_value| is NULL, the removed value will | 423 // passed out via |out_value|. If |out_value| is NULL, the removed value will |
425 // be deleted. This method returns true if |index| is valid; otherwise | 424 // be deleted. This method returns true if |index| is valid; otherwise |
426 // it will return false and the ListValue object will be unchanged. | 425 // it will return false and the ListValue object will be unchanged. |
427 bool Remove(size_t index, Value** out_value); | 426 virtual bool Remove(size_t index, Value** out_value); |
428 | 427 |
429 // Removes the first instance of |value| found in the list, if any, and | 428 // Removes the first instance of |value| found in the list, if any, and |
430 // deletes it. |index| is the location where |value| was found. Returns false | 429 // deletes it. |index| is the location where |value| was found. Returns false |
431 // if not found. | 430 // if not found. |
432 bool Remove(const Value& value, size_t* index); | 431 bool Remove(const Value& value, size_t* index); |
433 | 432 |
434 // Appends a Value to the end of the list. | 433 // Appends a Value to the end of the list. |
435 void Append(Value* in_value); | 434 void Append(Value* in_value); |
436 | 435 |
437 // Appends a Value if it's not already present. Takes ownership of the | 436 // Appends a Value if it's not already present. Takes ownership of the |
438 // |in_value|. Returns true if successful, or false if the value was already | 437 // |in_value|. Returns true if successful, or false if the value was already |
439 // present. If the value was already present the |in_value| is deleted. | 438 // present. If the value was already present the |in_value| is deleted. |
440 bool AppendIfNotPresent(Value* in_value); | 439 bool AppendIfNotPresent(Value* in_value); |
441 | 440 |
442 // Insert a Value at index. | 441 // Insert a Value at index. |
443 // Returns true if successful, or false if the index was out of range. | 442 // Returns true if successful, or false if the index was out of range. |
444 bool Insert(size_t index, Value* in_value); | 443 bool Insert(size_t index, Value* in_value); |
445 | 444 |
446 // Searches for the first instance of |value| in the list using the Equals | 445 // Searches for the first instance of |value| in the list using the Equals |
447 // method of the Value type. | 446 // method of the Value type. |
448 // Returns a const_iterator to the found item or to end() if none exists. | 447 // Returns a const_iterator to the found item or to end() if none exists. |
449 const_iterator Find(const Value& value) const; | 448 const_iterator Find(const Value& value) const; |
450 | 449 |
451 // Swaps contents with the |other| list. | 450 // Swaps contents with the |other| list. |
452 void Swap(ListValue* other) { | 451 virtual void Swap(ListValue* other); |
453 list_.swap(other->list_); | |
454 } | |
455 | 452 |
456 // Iteration. | 453 // Iteration. |
457 iterator begin() { return list_.begin(); } | 454 iterator begin() { return list_.begin(); } |
458 iterator end() { return list_.end(); } | 455 iterator end() { return list_.end(); } |
459 | 456 |
460 const_iterator begin() const { return list_.begin(); } | 457 const_iterator begin() const { return list_.begin(); } |
461 const_iterator end() const { return list_.end(); } | 458 const_iterator end() const { return list_.end(); } |
462 | 459 |
463 // Overridden from Value: | 460 // Overridden from Value: |
464 virtual bool GetAsList(ListValue** out_value) OVERRIDE; | 461 virtual bool GetAsList(ListValue** out_value) OVERRIDE; |
(...skipping 26 matching lines...) Expand all Loading... |
491 | 488 |
492 } // namespace base | 489 } // namespace base |
493 | 490 |
494 // http://crbug.com/88666 | 491 // http://crbug.com/88666 |
495 using base::DictionaryValue; | 492 using base::DictionaryValue; |
496 using base::ListValue; | 493 using base::ListValue; |
497 using base::StringValue; | 494 using base::StringValue; |
498 using base::Value; | 495 using base::Value; |
499 | 496 |
500 #endif // BASE_VALUES_H_ | 497 #endif // BASE_VALUES_H_ |
OLD | NEW |