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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Merge |dictionary| into this dictionary. This is done recursively, i.e. any | 329 // Merge |dictionary| into this dictionary. This is done recursively, i.e. any |
330 // sub-dictionaries will be merged as well. In case of key collisions, the | 330 // sub-dictionaries will be merged as well. In case of key collisions, the |
331 // passed in dictionary takes precedence and data already present will be | 331 // passed in dictionary takes precedence and data already present will be |
332 // replaced. Values within |dictionary| are deep-copied, so |dictionary| may | 332 // replaced. Values within |dictionary| are deep-copied, so |dictionary| may |
333 // be freed any time after this call. | 333 // be freed any time after this call. |
334 void MergeDictionary(const DictionaryValue* dictionary); | 334 void MergeDictionary(const DictionaryValue* dictionary); |
335 | 335 |
336 // Swaps contents with the |other| dictionary. | 336 // Swaps contents with the |other| dictionary. |
337 virtual void Swap(DictionaryValue* other); | 337 virtual void Swap(DictionaryValue* other); |
338 | 338 |
339 // This class provides an iterator for the keys in the dictionary. | |
340 // It can't be used to modify the dictionary. | |
341 // | |
342 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT | |
343 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any | |
344 // keys have '.'s in them. | |
345 class BASE_EXPORT key_iterator | |
346 : private std::iterator<std::input_iterator_tag, const std::string> { | |
347 public: | |
348 explicit key_iterator(ValueMap::const_iterator itr); | |
349 // Not explicit, because this is a copy constructor. | |
350 key_iterator(const key_iterator& rhs); | |
351 key_iterator operator++() { | |
352 ++itr_; | |
353 return *this; | |
354 } | |
355 const std::string& operator*() { return itr_->first; } | |
356 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } | |
357 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } | |
358 | |
359 private: | |
360 ValueMap::const_iterator itr_; | |
361 }; | |
362 | |
363 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } | |
364 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } | |
365 | |
366 // This class provides an iterator over both keys and values in the | 339 // This class provides an iterator over both keys and values in the |
367 // dictionary. It can't be used to modify the dictionary. | 340 // dictionary. It can't be used to modify the dictionary. |
368 class BASE_EXPORT Iterator { | 341 class BASE_EXPORT Iterator { |
369 public: | 342 public: |
370 explicit Iterator(const DictionaryValue& target); | 343 explicit Iterator(const DictionaryValue& target); |
371 | 344 |
372 // DEPRECATED: use !IsAtEnd() instead. | 345 // DEPRECATED: use !IsAtEnd() instead. |
373 bool HasNext() const { return it_ != target_.dictionary_.end(); } | 346 bool HasNext() const { return it_ != target_.dictionary_.end(); } |
374 | 347 |
375 bool IsAtEnd() const { return it_ == target_.dictionary_.end(); } | 348 bool IsAtEnd() const { return it_ == target_.dictionary_.end(); } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 | 500 |
528 } // namespace base | 501 } // namespace base |
529 | 502 |
530 // http://crbug.com/88666 | 503 // http://crbug.com/88666 |
531 using base::DictionaryValue; | 504 using base::DictionaryValue; |
532 using base::ListValue; | 505 using base::ListValue; |
533 using base::StringValue; | 506 using base::StringValue; |
534 using base::Value; | 507 using base::Value; |
535 | 508 |
536 #endif // BASE_VALUES_H_ | 509 #endif // BASE_VALUES_H_ |
OLD | NEW |