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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 key_iterator |
343 : private std::iterator<std::input_iterator_tag, const std::string> { | 343 : private std::iterator<std::input_iterator_tag, const std::string> { |
jar (doing other things)
2012/08/09 16:30:27
Any idea why this is using private inheritance (vi
hans
2012/08/09 18:28:48
No idea, I haven't really looked at the file itsel
| |
344 public: | 344 public: |
345 explicit key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } | 345 explicit key_iterator(ValueMap::const_iterator itr); |
346 key_iterator(const key_iterator& rhs); | |
jar (doing other things)
2012/08/09 16:30:27
a) Why did you need to add this, if this CL is all
hans
2012/08/09 18:28:48
Because the plugin warns that this class needs an
jar (doing other things)
2012/08/09 19:27:16
You are correct about explicit. Thanks!
I think t
hans
2012/08/09 19:31:05
Comment added.
| |
346 key_iterator operator++() { | 347 key_iterator operator++() { |
347 ++itr_; | 348 ++itr_; |
348 return *this; | 349 return *this; |
349 } | 350 } |
350 const std::string& operator*() { return itr_->first; } | 351 const std::string& operator*() { return itr_->first; } |
351 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } | 352 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } |
352 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } | 353 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } |
353 | 354 |
354 private: | 355 private: |
355 ValueMap::const_iterator itr_; | 356 ValueMap::const_iterator itr_; |
356 }; | 357 }; |
357 | 358 |
358 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } | 359 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } |
359 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } | 360 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } |
360 | 361 |
361 // This class provides an iterator over both keys and values in the | 362 // This class provides an iterator over both keys and values in the |
362 // dictionary. It can't be used to modify the dictionary. | 363 // dictionary. It can't be used to modify the dictionary. |
363 class Iterator { | 364 class Iterator { |
364 public: | 365 public: |
365 explicit Iterator(const DictionaryValue& target) | 366 explicit Iterator(const DictionaryValue& target); |
366 : target_(target), it_(target.dictionary_.begin()) {} | |
367 | 367 |
368 bool HasNext() const { return it_ != target_.dictionary_.end(); } | 368 bool HasNext() const { return it_ != target_.dictionary_.end(); } |
369 void Advance() { ++it_; } | 369 void Advance() { ++it_; } |
370 | 370 |
371 const std::string& key() const { return it_->first; } | 371 const std::string& key() const { return it_->first; } |
372 const Value& value() const { return *it_->second; } | 372 const Value& value() const { return *it_->second; } |
373 | 373 |
374 private: | 374 private: |
375 const DictionaryValue& target_; | 375 const DictionaryValue& target_; |
376 ValueMap::const_iterator it_; | 376 ValueMap::const_iterator it_; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 | 506 |
507 } // namespace base | 507 } // namespace base |
508 | 508 |
509 // http://crbug.com/88666 | 509 // http://crbug.com/88666 |
510 using base::DictionaryValue; | 510 using base::DictionaryValue; |
511 using base::ListValue; | 511 using base::ListValue; |
512 using base::StringValue; | 512 using base::StringValue; |
513 using base::Value; | 513 using base::Value; |
514 | 514 |
515 #endif // BASE_VALUES_H_ | 515 #endif // BASE_VALUES_H_ |
OLD | NEW |