| 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 332 |
| 333 // Swaps contents with the |other| dictionary. | 333 // Swaps contents with the |other| dictionary. |
| 334 virtual void Swap(DictionaryValue* other); | 334 virtual void Swap(DictionaryValue* other); |
| 335 | 335 |
| 336 // This class provides an iterator for the keys in the dictionary. | 336 // This class provides an iterator for the keys in the dictionary. |
| 337 // It can't be used to modify the dictionary. | 337 // It can't be used to modify the dictionary. |
| 338 // | 338 // |
| 339 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT | 339 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT |
| 340 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any | 340 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any |
| 341 // keys have '.'s in them. | 341 // keys have '.'s in them. |
| 342 class key_iterator | 342 class BASE_EXPORT key_iterator |
| 343 : private std::iterator<std::input_iterator_tag, const std::string> { | 343 : private std::iterator<std::input_iterator_tag, const std::string> { |
| 344 public: | 344 public: |
| 345 explicit key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } | 345 explicit key_iterator(ValueMap::const_iterator itr); |
| 346 // Not explicit, because this is a copy constructor. |
| 347 key_iterator(const key_iterator& rhs); |
| 346 key_iterator operator++() { | 348 key_iterator operator++() { |
| 347 ++itr_; | 349 ++itr_; |
| 348 return *this; | 350 return *this; |
| 349 } | 351 } |
| 350 const std::string& operator*() { return itr_->first; } | 352 const std::string& operator*() { return itr_->first; } |
| 351 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } | 353 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } |
| 352 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } | 354 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } |
| 353 | 355 |
| 354 private: | 356 private: |
| 355 ValueMap::const_iterator itr_; | 357 ValueMap::const_iterator itr_; |
| 356 }; | 358 }; |
| 357 | 359 |
| 358 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } | 360 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } |
| 359 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } | 361 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } |
| 360 | 362 |
| 361 // This class provides an iterator over both keys and values in the | 363 // This class provides an iterator over both keys and values in the |
| 362 // dictionary. It can't be used to modify the dictionary. | 364 // dictionary. It can't be used to modify the dictionary. |
| 363 class Iterator { | 365 class BASE_EXPORT Iterator { |
| 364 public: | 366 public: |
| 365 explicit Iterator(const DictionaryValue& target) | 367 explicit Iterator(const DictionaryValue& target); |
| 366 : target_(target), it_(target.dictionary_.begin()) {} | |
| 367 | 368 |
| 368 bool HasNext() const { return it_ != target_.dictionary_.end(); } | 369 bool HasNext() const { return it_ != target_.dictionary_.end(); } |
| 369 void Advance() { ++it_; } | 370 void Advance() { ++it_; } |
| 370 | 371 |
| 371 const std::string& key() const { return it_->first; } | 372 const std::string& key() const { return it_->first; } |
| 372 const Value& value() const { return *it_->second; } | 373 const Value& value() const { return *it_->second; } |
| 373 | 374 |
| 374 private: | 375 private: |
| 375 const DictionaryValue& target_; | 376 const DictionaryValue& target_; |
| 376 ValueMap::const_iterator it_; | 377 ValueMap::const_iterator it_; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 | 507 |
| 507 } // namespace base | 508 } // namespace base |
| 508 | 509 |
| 509 // http://crbug.com/88666 | 510 // http://crbug.com/88666 |
| 510 using base::DictionaryValue; | 511 using base::DictionaryValue; |
| 511 using base::ListValue; | 512 using base::ListValue; |
| 512 using base::StringValue; | 513 using base::StringValue; |
| 513 using base::Value; | 514 using base::Value; |
| 514 | 515 |
| 515 #endif // BASE_VALUES_H_ | 516 #endif // BASE_VALUES_H_ |
| OLD | NEW |