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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Returns the type of the value stored by the current Value object. | 80 // Returns the type of the value stored by the current Value object. |
81 // Each type will be implemented by only one subclass of Value, so it's | 81 // Each type will be implemented by only one subclass of Value, so it's |
82 // safe to use the Type to determine whether you can cast from | 82 // safe to use the Type to determine whether you can cast from |
83 // Value* to (Implementing Class)*. Also, a Value object never changes | 83 // Value* to (Implementing Class)*. Also, a Value object never changes |
84 // its type after construction. | 84 // its type after construction. |
85 Type GetType() const { return type_; } | 85 Type GetType() const { return type_; } |
86 | 86 |
87 // Returns true if the current object represents a given type. | 87 // Returns true if the current object represents a given type. |
88 bool IsType(Type type) const { return type == type_; } | 88 bool IsType(Type type) const { return type == type_; } |
89 | 89 |
| 90 virtual ListValue* AsList(); |
| 91 |
90 // These methods allow the convenient retrieval of settings. | 92 // These methods allow the convenient retrieval of settings. |
91 // If the current setting object can be converted into the given type, | 93 // 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 | 94 // the value is returned through the |out_value| parameter and true is |
93 // returned; otherwise, false is returned and |out_value| is unchanged. | 95 // returned; otherwise, false is returned and |out_value| is unchanged. |
94 virtual bool GetAsBoolean(bool* out_value) const; | 96 virtual bool GetAsBoolean(bool* out_value) const; |
95 virtual bool GetAsInteger(int* out_value) const; | 97 virtual bool GetAsInteger(int* out_value) const; |
96 virtual bool GetAsDouble(double* out_value) const; | 98 virtual bool GetAsDouble(double* out_value) const; |
97 virtual bool GetAsString(std::string* out_value) const; | 99 virtual bool GetAsString(std::string* out_value) const; |
98 virtual bool GetAsString(string16* out_value) const; | 100 virtual bool GetAsString(string16* out_value) const; |
99 virtual bool GetAsList(ListValue** out_value); | 101 virtual bool GetAsList(ListValue** out_value); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 426 } |
425 | 427 |
426 // Iteration. | 428 // Iteration. |
427 iterator begin() { return list_.begin(); } | 429 iterator begin() { return list_.begin(); } |
428 iterator end() { return list_.end(); } | 430 iterator end() { return list_.end(); } |
429 | 431 |
430 const_iterator begin() const { return list_.begin(); } | 432 const_iterator begin() const { return list_.begin(); } |
431 const_iterator end() const { return list_.end(); } | 433 const_iterator end() const { return list_.end(); } |
432 | 434 |
433 // Overridden from Value: | 435 // Overridden from Value: |
| 436 virtual ListValue* AsList() OVERRIDE; |
434 virtual bool GetAsList(ListValue** out_value) OVERRIDE; | 437 virtual bool GetAsList(ListValue** out_value) OVERRIDE; |
435 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; | 438 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; |
436 virtual ListValue* DeepCopy() const OVERRIDE; | 439 virtual ListValue* DeepCopy() const OVERRIDE; |
437 virtual bool Equals(const Value* other) const OVERRIDE; | 440 virtual bool Equals(const Value* other) const OVERRIDE; |
438 | 441 |
439 private: | 442 private: |
440 ValueVector list_; | 443 ValueVector list_; |
441 | 444 |
442 DISALLOW_COPY_AND_ASSIGN(ListValue); | 445 DISALLOW_COPY_AND_ASSIGN(ListValue); |
443 }; | 446 }; |
(...skipping 17 matching lines...) Expand all Loading... |
461 | 464 |
462 } // namespace base | 465 } // namespace base |
463 | 466 |
464 // http://crbug.com/88666 | 467 // http://crbug.com/88666 |
465 using base::DictionaryValue; | 468 using base::DictionaryValue; |
466 using base::ListValue; | 469 using base::ListValue; |
467 using base::StringValue; | 470 using base::StringValue; |
468 using base::Value; | 471 using base::Value; |
469 | 472 |
470 #endif // BASE_VALUES_H_ | 473 #endif // BASE_VALUES_H_ |
OLD | NEW |