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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 439 } |
438 | 440 |
439 // Iteration. | 441 // Iteration. |
440 iterator begin() { return list_.begin(); } | 442 iterator begin() { return list_.begin(); } |
441 iterator end() { return list_.end(); } | 443 iterator end() { return list_.end(); } |
442 | 444 |
443 const_iterator begin() const { return list_.begin(); } | 445 const_iterator begin() const { return list_.begin(); } |
444 const_iterator end() const { return list_.end(); } | 446 const_iterator end() const { return list_.end(); } |
445 | 447 |
446 // Overridden from Value: | 448 // Overridden from Value: |
| 449 virtual ListValue* AsList() OVERRIDE; |
447 virtual bool GetAsList(ListValue** out_value) OVERRIDE; | 450 virtual bool GetAsList(ListValue** out_value) OVERRIDE; |
448 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; | 451 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; |
449 virtual ListValue* DeepCopy() const OVERRIDE; | 452 virtual ListValue* DeepCopy() const OVERRIDE; |
450 virtual bool Equals(const Value* other) const OVERRIDE; | 453 virtual bool Equals(const Value* other) const OVERRIDE; |
451 | 454 |
452 private: | 455 private: |
453 ValueVector list_; | 456 ValueVector list_; |
454 | 457 |
455 DISALLOW_COPY_AND_ASSIGN(ListValue); | 458 DISALLOW_COPY_AND_ASSIGN(ListValue); |
456 }; | 459 }; |
(...skipping 17 matching lines...) Expand all Loading... |
474 | 477 |
475 } // namespace base | 478 } // namespace base |
476 | 479 |
477 // http://crbug.com/88666 | 480 // http://crbug.com/88666 |
478 using base::DictionaryValue; | 481 using base::DictionaryValue; |
479 using base::ListValue; | 482 using base::ListValue; |
480 using base::StringValue; | 483 using base::StringValue; |
481 using base::Value; | 484 using base::Value; |
482 | 485 |
483 #endif // BASE_VALUES_H_ | 486 #endif // BASE_VALUES_H_ |
OLD | NEW |