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 BinaryValue* AsBinary(); |
90 virtual ListValue* AsList(); | 91 virtual ListValue* AsList(); |
91 | 92 |
92 // These methods allow the convenient retrieval of settings. | 93 // These methods allow the convenient retrieval of settings. |
93 // If the current setting object can be converted into the given type, | 94 // If the current setting object can be converted into the given type, |
94 // the value is returned through the |out_value| parameter and true is | 95 // the value is returned through the |out_value| parameter and true is |
95 // returned; otherwise, false is returned and |out_value| is unchanged. | 96 // returned; otherwise, false is returned and |out_value| is unchanged. |
96 virtual bool GetAsBoolean(bool* out_value) const; | 97 virtual bool GetAsBoolean(bool* out_value) const; |
97 virtual bool GetAsInteger(int* out_value) const; | 98 virtual bool GetAsInteger(int* out_value) const; |
98 virtual bool GetAsDouble(double* out_value) const; | 99 virtual bool GetAsDouble(double* out_value) const; |
99 virtual bool GetAsString(std::string* out_value) const; | 100 virtual bool GetAsString(std::string* out_value) const; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // factory method creates a new BinaryValue by copying the contents of the | 189 // factory method creates a new BinaryValue by copying the contents of the |
189 // buffer that's passed in. | 190 // buffer that's passed in. |
190 // Returns NULL if buffer is NULL. | 191 // Returns NULL if buffer is NULL. |
191 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 192 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
192 | 193 |
193 size_t GetSize() const { return size_; } | 194 size_t GetSize() const { return size_; } |
194 char* GetBuffer() { return buffer_; } | 195 char* GetBuffer() { return buffer_; } |
195 const char* GetBuffer() const { return buffer_; } | 196 const char* GetBuffer() const { return buffer_; } |
196 | 197 |
197 // Overridden from Value: | 198 // Overridden from Value: |
| 199 virtual BinaryValue* AsBinary() OVERRIDE; |
198 virtual BinaryValue* DeepCopy() const OVERRIDE; | 200 virtual BinaryValue* DeepCopy() const OVERRIDE; |
199 virtual bool Equals(const Value* other) const OVERRIDE; | 201 virtual bool Equals(const Value* other) const OVERRIDE; |
200 | 202 |
201 private: | 203 private: |
202 // Constructor is private so that only objects with valid buffer pointers | 204 // Constructor is private so that only objects with valid buffer pointers |
203 // and size values can be created. | 205 // and size values can be created. |
204 BinaryValue(char* buffer, size_t size); | 206 BinaryValue(char* buffer, size_t size); |
205 | 207 |
206 char* buffer_; | 208 char* buffer_; |
207 size_t size_; | 209 size_t size_; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 466 |
465 } // namespace base | 467 } // namespace base |
466 | 468 |
467 // http://crbug.com/88666 | 469 // http://crbug.com/88666 |
468 using base::DictionaryValue; | 470 using base::DictionaryValue; |
469 using base::ListValue; | 471 using base::ListValue; |
470 using base::StringValue; | 472 using base::StringValue; |
471 using base::Value; | 473 using base::Value; |
472 | 474 |
473 #endif // BASE_VALUES_H_ | 475 #endif // BASE_VALUES_H_ |
OLD | NEW |