| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 5 // This file specifies a recursive data storage class called Value |
| 6 // intended for storing setting and other persistable data. | 6 // intended for storing setting and other persistable data. |
| 7 // It includes the ability to specify (recursive) lists and dictionaries, so | 7 // It includes the ability to specify (recursive) lists and dictionaries, so |
| 8 // it's fairly expressive. However, the API is optimized for the common case, | 8 // it's fairly expressive. However, the API is optimized for the common case, |
| 9 // namely storing a hierarchical tree of simple values. Given a | 9 // namely storing a hierarchical tree of simple values. Given a |
| 10 // DictionaryValue root, you can easily do things like: | 10 // DictionaryValue root, you can easily do things like: |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // This class provides an iterator for the keys in the dictionary. | 294 // This class provides an iterator for the keys in the dictionary. |
| 295 // It can't be used to modify the dictionary. | 295 // It can't be used to modify the dictionary. |
| 296 // | 296 // |
| 297 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT | 297 // YOU SHOULD ALWAYS USE THE XXXWithoutPathExpansion() APIs WITH THESE, NOT |
| 298 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any | 298 // THE NORMAL XXX() APIs. This makes sure things will work correctly if any |
| 299 // keys have '.'s in them. | 299 // keys have '.'s in them. |
| 300 class key_iterator | 300 class key_iterator |
| 301 : private std::iterator<std::input_iterator_tag, const std::wstring> { | 301 : private std::iterator<std::input_iterator_tag, const std::wstring> { |
| 302 public: | 302 public: |
| 303 explicit key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } | 303 explicit key_iterator(ValueMap::const_iterator itr) { itr_ = itr; } |
| 304 key_iterator operator++() { ++itr_; return *this; } | 304 key_iterator operator++() { |
| 305 ++itr_; |
| 306 return *this; |
| 307 } |
| 305 const std::wstring& operator*() { return itr_->first; } | 308 const std::wstring& operator*() { return itr_->first; } |
| 306 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } | 309 bool operator!=(const key_iterator& other) { return itr_ != other.itr_; } |
| 307 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } | 310 bool operator==(const key_iterator& other) { return itr_ == other.itr_; } |
| 308 | 311 |
| 309 private: | 312 private: |
| 310 ValueMap::const_iterator itr_; | 313 ValueMap::const_iterator itr_; |
| 311 }; | 314 }; |
| 312 | 315 |
| 313 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } | 316 key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } |
| 314 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } | 317 key_iterator end_keys() const { return key_iterator(dictionary_.end()); } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 virtual bool Serialize(const Value& root) = 0; | 408 virtual bool Serialize(const Value& root) = 0; |
| 406 | 409 |
| 407 // This method deserializes the subclass-specific format into a Value object. | 410 // This method deserializes the subclass-specific format into a Value object. |
| 408 // If the return value is non-NULL, the caller takes ownership of returned | 411 // If the return value is non-NULL, the caller takes ownership of returned |
| 409 // Value. If the return value is NULL, and if error_message is non-NULL, | 412 // Value. If the return value is NULL, and if error_message is non-NULL, |
| 410 // error_message should be filled with a message describing the error. | 413 // error_message should be filled with a message describing the error. |
| 411 virtual Value* Deserialize(std::string* error_message) = 0; | 414 virtual Value* Deserialize(std::string* error_message) = 0; |
| 412 }; | 415 }; |
| 413 | 416 |
| 414 #endif // BASE_VALUES_H_ | 417 #endif // BASE_VALUES_H_ |
| OLD | NEW |