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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // If the current setting object can be converted into the given type, | 91 // If the current setting object can be converted into the given type, |
92 // the value is returned through the |out_value| parameter and true is | 92 // the value is returned through the |out_value| parameter and true is |
93 // returned; otherwise, false is returned and |out_value| is unchanged. | 93 // returned; otherwise, false is returned and |out_value| is unchanged. |
94 virtual bool GetAsBoolean(bool* out_value) const; | 94 virtual bool GetAsBoolean(bool* out_value) const; |
95 virtual bool GetAsInteger(int* out_value) const; | 95 virtual bool GetAsInteger(int* out_value) const; |
96 virtual bool GetAsDouble(double* out_value) const; | 96 virtual bool GetAsDouble(double* out_value) const; |
97 virtual bool GetAsString(std::string* out_value) const; | 97 virtual bool GetAsString(std::string* out_value) const; |
98 virtual bool GetAsString(string16* out_value) const; | 98 virtual bool GetAsString(string16* out_value) const; |
99 virtual bool GetAsList(ListValue** out_value); | 99 virtual bool GetAsList(ListValue** out_value); |
100 virtual bool GetAsList(const ListValue** out_value) const; | 100 virtual bool GetAsList(const ListValue** out_value) const; |
| 101 virtual bool GetAsDictionary(DictionaryValue** out_value); |
| 102 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; |
101 | 103 |
102 // This creates a deep copy of the entire Value tree, and returns a pointer | 104 // This creates a deep copy of the entire Value tree, and returns a pointer |
103 // to the copy. The caller gets ownership of the copy, of course. | 105 // to the copy. The caller gets ownership of the copy, of course. |
104 // | 106 // |
105 // Subclasses return their own type directly in their overrides; | 107 // Subclasses return their own type directly in their overrides; |
106 // this works because C++ supports covariant return types. | 108 // this works because C++ supports covariant return types. |
107 virtual Value* DeepCopy() const; | 109 virtual Value* DeepCopy() const; |
108 | 110 |
109 // Compares if two Value objects have equal contents. | 111 // Compares if two Value objects have equal contents. |
110 virtual bool Equals(const Value* other) const; | 112 virtual bool Equals(const Value* other) const; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 }; | 210 }; |
209 | 211 |
210 // DictionaryValue provides a key-value dictionary with (optional) "path" | 212 // DictionaryValue provides a key-value dictionary with (optional) "path" |
211 // parsing for recursive access; see the comment at the top of the file. Keys | 213 // parsing for recursive access; see the comment at the top of the file. Keys |
212 // are |std::string|s and should be UTF-8 encoded. | 214 // are |std::string|s and should be UTF-8 encoded. |
213 class BASE_EXPORT DictionaryValue : public Value { | 215 class BASE_EXPORT DictionaryValue : public Value { |
214 public: | 216 public: |
215 DictionaryValue(); | 217 DictionaryValue(); |
216 virtual ~DictionaryValue(); | 218 virtual ~DictionaryValue(); |
217 | 219 |
| 220 // Overridden from Value: |
| 221 virtual bool GetAsDictionary(DictionaryValue** out_value) OVERRIDE; |
| 222 virtual bool GetAsDictionary( |
| 223 const DictionaryValue** out_value) const OVERRIDE; |
| 224 |
218 // Returns true if the current dictionary has a value for the given key. | 225 // Returns true if the current dictionary has a value for the given key. |
219 bool HasKey(const std::string& key) const; | 226 bool HasKey(const std::string& key) const; |
220 | 227 |
221 // Returns the number of Values in this dictionary. | 228 // Returns the number of Values in this dictionary. |
222 size_t size() const { return dictionary_.size(); } | 229 size_t size() const { return dictionary_.size(); } |
223 | 230 |
224 // Returns whether the dictionary is empty. | 231 // Returns whether the dictionary is empty. |
225 bool empty() const { return dictionary_.empty(); } | 232 bool empty() const { return dictionary_.empty(); } |
226 | 233 |
227 // Clears any current contents of this dictionary. | 234 // Clears any current contents of this dictionary. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 | 491 |
485 } // namespace base | 492 } // namespace base |
486 | 493 |
487 // http://crbug.com/88666 | 494 // http://crbug.com/88666 |
488 using base::DictionaryValue; | 495 using base::DictionaryValue; |
489 using base::ListValue; | 496 using base::ListValue; |
490 using base::StringValue; | 497 using base::StringValue; |
491 using base::Value; | 498 using base::Value; |
492 | 499 |
493 #endif // BASE_VALUES_H_ | 500 #endif // BASE_VALUES_H_ |
OLD | NEW |