OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 class DictionaryValue : public Value { | 195 class DictionaryValue : public Value { |
196 public: | 196 public: |
197 DictionaryValue() : Value(TYPE_DICTIONARY) {} | 197 DictionaryValue() : Value(TYPE_DICTIONARY) {} |
198 ~DictionaryValue(); | 198 ~DictionaryValue(); |
199 | 199 |
200 // Subclassed methods | 200 // Subclassed methods |
201 Value* DeepCopy() const; | 201 Value* DeepCopy() const; |
202 virtual bool Equals(const Value* other) const; | 202 virtual bool Equals(const Value* other) const; |
203 | 203 |
204 // Returns true if the current dictionary has a value for the given key. | 204 // Returns true if the current dictionary has a value for the given key. |
205 bool HasKey(const std::wstring& key); | 205 bool HasKey(const std::wstring& key) const; |
206 | 206 |
207 // Clears any current contents of this dictionary. | 207 // Clears any current contents of this dictionary. |
208 void Clear(); | 208 void Clear(); |
209 | 209 |
210 // Sets the Value associated with the given path starting from this object. | 210 // Sets the Value associated with the given path starting from this object. |
211 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 211 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
212 // into the next DictionaryValue down. Obviously, "." can't be used | 212 // into the next DictionaryValue down. Obviously, "." can't be used |
213 // within a key, but there are no other restrictions on keys. | 213 // within a key, but there are no other restrictions on keys. |
214 // If the key at any step of the way doesn't exist, or exists but isn't | 214 // If the key at any step of the way doesn't exist, or exists but isn't |
215 // a DictionaryValue, a new DictionaryValue will be created and attached | 215 // a DictionaryValue, a new DictionaryValue will be created and attached |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 279 |
280 // Associates the value |in_value| with the |key|. This method should be | 280 // Associates the value |in_value| with the |key|. This method should be |
281 // used instead of "dictionary_[key] = foo" so that any previous value can | 281 // used instead of "dictionary_[key] = foo" so that any previous value can |
282 // be properly deleted. | 282 // be properly deleted. |
283 void SetInCurrentNode(const std::wstring& key, Value* in_value); | 283 void SetInCurrentNode(const std::wstring& key, Value* in_value); |
284 | 284 |
285 ValueMap dictionary_; | 285 ValueMap dictionary_; |
286 }; | 286 }; |
287 | 287 |
288 // This type of Value represents a list of other Value values. | 288 // This type of Value represents a list of other Value values. |
289 // TODO(jhughes): Flesh this out. | |
290 class ListValue : public Value { | 289 class ListValue : public Value { |
291 public: | 290 public: |
292 ListValue() : Value(TYPE_LIST) {} | 291 ListValue() : Value(TYPE_LIST) {} |
293 ~ListValue(); | 292 ~ListValue(); |
294 | 293 |
295 // Subclassed methods | 294 // Subclassed methods |
296 Value* DeepCopy() const; | 295 Value* DeepCopy() const; |
297 virtual bool Equals(const Value* other) const; | 296 virtual bool Equals(const Value* other) const; |
298 | 297 |
299 // Clears the contents of this ListValue | 298 // Clears the contents of this ListValue |
(...skipping 10 matching lines...) Expand all Loading... |
310 bool Set(size_t index, Value* in_value); | 309 bool Set(size_t index, Value* in_value); |
311 | 310 |
312 // Gets the Value at the given index. Modifies value (and returns true) | 311 // Gets the Value at the given index. Modifies value (and returns true) |
313 // only if the index falls within the current list range. | 312 // only if the index falls within the current list range. |
314 // Note that the list always owns the Value passed out via out_value. | 313 // Note that the list always owns the Value passed out via out_value. |
315 bool Get(size_t index, Value** out_value) const; | 314 bool Get(size_t index, Value** out_value) const; |
316 | 315 |
317 // Convenience forms of Get(). Modifies value (and returns true) only if | 316 // Convenience forms of Get(). Modifies value (and returns true) only if |
318 // the index is valid and the Value at that index can be returned in | 317 // the index is valid and the Value at that index can be returned in |
319 // the specified form. | 318 // the specified form. |
| 319 bool GetBoolean(size_t index, bool* out_value) const; |
| 320 bool GetInteger(size_t index, int* out_value) const; |
| 321 bool GetReal(size_t index, double* out_value) const; |
| 322 bool GetString(size_t index, std::string* out_value) const; |
| 323 bool GetBinary(size_t index, BinaryValue** out_value) const; |
320 bool GetDictionary(size_t index, DictionaryValue** out_value) const; | 324 bool GetDictionary(size_t index, DictionaryValue** out_value) const; |
| 325 bool GetList(size_t index, ListValue** out_value) const; |
321 | 326 |
322 // Removes the Value with the specified index from this list. | 327 // Removes the Value with the specified index from this list. |
323 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 328 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
324 // passed out via |out_value|. If |out_value| is NULL, the removed value will | 329 // passed out via |out_value|. If |out_value| is NULL, the removed value will |
325 // be deleted. This method returns true if |index| is valid; otherwise | 330 // be deleted. This method returns true if |index| is valid; otherwise |
326 // it will return false and the ListValue object will be unchanged. | 331 // it will return false and the ListValue object will be unchanged. |
327 bool Remove(size_t index, Value** out_value); | 332 bool Remove(size_t index, Value** out_value); |
328 | 333 |
329 // Appends a Value to the end of the list. | 334 // Appends a Value to the end of the list. |
330 void Append(Value* in_value); | 335 void Append(Value* in_value); |
(...skipping 27 matching lines...) Expand all Loading... |
358 virtual bool Serialize(const Value& root) = 0; | 363 virtual bool Serialize(const Value& root) = 0; |
359 | 364 |
360 // This method deserializes the subclass-specific format into a Value object. | 365 // This method deserializes the subclass-specific format into a Value object. |
361 // If the return value is non-NULL, the caller takes ownership of returned | 366 // If the return value is non-NULL, the caller takes ownership of returned |
362 // Value. If the return value is NULL, and if error_message is non-NULL, | 367 // Value. If the return value is NULL, and if error_message is non-NULL, |
363 // error_message should be filled with a message describing the error. | 368 // error_message should be filled with a message describing the error. |
364 virtual Value* Deserialize(std::string* error_message) = 0; | 369 virtual Value* Deserialize(std::string* error_message) = 0; |
365 }; | 370 }; |
366 | 371 |
367 #endif // BASE_VALUES_H_ | 372 #endif // BASE_VALUES_H_ |
OLD | NEW |