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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 bool GetDictionary(size_t index, DictionaryValue** out_value) const; | 327 bool GetDictionary(size_t index, DictionaryValue** out_value) const; |
328 bool GetList(size_t index, ListValue** out_value) const; | 328 bool GetList(size_t index, ListValue** out_value) const; |
329 | 329 |
330 // Removes the Value with the specified index from this list. | 330 // Removes the Value with the specified index from this list. |
331 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 331 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
332 // passed out via |out_value|. If |out_value| is NULL, the removed value will | 332 // passed out via |out_value|. If |out_value| is NULL, the removed value will |
333 // be deleted. This method returns true if |index| is valid; otherwise | 333 // be deleted. This method returns true if |index| is valid; otherwise |
334 // it will return false and the ListValue object will be unchanged. | 334 // it will return false and the ListValue object will be unchanged. |
335 bool Remove(size_t index, Value** out_value); | 335 bool Remove(size_t index, Value** out_value); |
336 | 336 |
337 // Removes the first instance of |in_value| found in the list, if any. | |
sky
2009/05/09 00:20:41
I think this should take a const Value& as you are
| |
338 void Remove(Value* in_value); | |
339 | |
337 // Appends a Value to the end of the list. | 340 // Appends a Value to the end of the list. |
338 void Append(Value* in_value); | 341 void Append(Value* in_value); |
339 | 342 |
340 // Iteration | 343 // Iteration |
341 typedef ValueVector::iterator iterator; | 344 typedef ValueVector::iterator iterator; |
342 typedef ValueVector::const_iterator const_iterator; | 345 typedef ValueVector::const_iterator const_iterator; |
343 | 346 |
344 ListValue::iterator begin() { return list_.begin(); } | 347 ListValue::iterator begin() { return list_.begin(); } |
345 ListValue::iterator end() { return list_.end(); } | 348 ListValue::iterator end() { return list_.end(); } |
346 | 349 |
347 ListValue::const_iterator begin() const { return list_.begin(); } | 350 ListValue::const_iterator begin() const { return list_.begin(); } |
348 ListValue::const_iterator end() const { return list_.end(); } | 351 ListValue::const_iterator end() const { return list_.end(); } |
349 | 352 |
350 ListValue::iterator Erase(iterator item) { | |
351 return list_.erase(item); | |
352 } | |
353 | |
354 private: | 353 private: |
355 DISALLOW_EVIL_CONSTRUCTORS(ListValue); | 354 DISALLOW_EVIL_CONSTRUCTORS(ListValue); |
356 | 355 |
357 ValueVector list_; | 356 ValueVector list_; |
358 }; | 357 }; |
359 | 358 |
360 // This interface is implemented by classes that know how to serialize and | 359 // This interface is implemented by classes that know how to serialize and |
361 // deserialize Value objects. | 360 // deserialize Value objects. |
362 class ValueSerializer { | 361 class ValueSerializer { |
363 public: | 362 public: |
364 virtual ~ValueSerializer() {} | 363 virtual ~ValueSerializer() {} |
365 | 364 |
366 virtual bool Serialize(const Value& root) = 0; | 365 virtual bool Serialize(const Value& root) = 0; |
367 | 366 |
368 // This method deserializes the subclass-specific format into a Value object. | 367 // This method deserializes the subclass-specific format into a Value object. |
369 // If the return value is non-NULL, the caller takes ownership of returned | 368 // If the return value is non-NULL, the caller takes ownership of returned |
370 // Value. If the return value is NULL, and if error_message is non-NULL, | 369 // Value. If the return value is NULL, and if error_message is non-NULL, |
371 // error_message should be filled with a message describing the error. | 370 // error_message should be filled with a message describing the error. |
372 virtual Value* Deserialize(std::string* error_message) = 0; | 371 virtual Value* Deserialize(std::string* error_message) = 0; |
373 }; | 372 }; |
374 | 373 |
375 #endif // BASE_VALUES_H_ | 374 #endif // BASE_VALUES_H_ |
OLD | NEW |