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(); | |
91 virtual ListValue* AsList(); | |
92 | |
93 // These methods allow the convenient retrieval of settings. | 90 // These methods allow the convenient retrieval of settings. |
94 // If the current setting object can be converted into the given type, | 91 // If the current setting object can be converted into the given type, |
95 // the value is returned through the |out_value| parameter and true is | 92 // the value is returned through the |out_value| parameter and true is |
96 // returned; otherwise, false is returned and |out_value| is unchanged. | 93 // returned; otherwise, false is returned and |out_value| is unchanged. |
97 virtual bool GetAsBoolean(bool* out_value) const; | 94 virtual bool GetAsBoolean(bool* out_value) const; |
98 virtual bool GetAsInteger(int* out_value) const; | 95 virtual bool GetAsInteger(int* out_value) const; |
99 virtual bool GetAsDouble(double* out_value) const; | 96 virtual bool GetAsDouble(double* out_value) const; |
100 virtual bool GetAsString(std::string* out_value) const; | 97 virtual bool GetAsString(std::string* out_value) const; |
101 virtual bool GetAsString(string16* out_value) const; | 98 virtual bool GetAsString(string16* out_value) const; |
102 virtual bool GetAsList(ListValue** out_value); | 99 virtual bool GetAsList(ListValue** out_value); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // factory method creates a new BinaryValue by copying the contents of the | 186 // factory method creates a new BinaryValue by copying the contents of the |
190 // buffer that's passed in. | 187 // buffer that's passed in. |
191 // Returns NULL if buffer is NULL. | 188 // Returns NULL if buffer is NULL. |
192 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 189 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
193 | 190 |
194 size_t GetSize() const { return size_; } | 191 size_t GetSize() const { return size_; } |
195 char* GetBuffer() { return buffer_; } | 192 char* GetBuffer() { return buffer_; } |
196 const char* GetBuffer() const { return buffer_; } | 193 const char* GetBuffer() const { return buffer_; } |
197 | 194 |
198 // Overridden from Value: | 195 // Overridden from Value: |
199 virtual BinaryValue* AsBinary() OVERRIDE; | |
200 virtual BinaryValue* DeepCopy() const OVERRIDE; | 196 virtual BinaryValue* DeepCopy() const OVERRIDE; |
201 virtual bool Equals(const Value* other) const OVERRIDE; | 197 virtual bool Equals(const Value* other) const OVERRIDE; |
202 | 198 |
203 private: | 199 private: |
204 // Constructor is private so that only objects with valid buffer pointers | 200 // Constructor is private so that only objects with valid buffer pointers |
205 // and size values can be created. | 201 // and size values can be created. |
206 BinaryValue(char* buffer, size_t size); | 202 BinaryValue(char* buffer, size_t size); |
207 | 203 |
208 char* buffer_; | 204 char* buffer_; |
209 size_t size_; | 205 size_t size_; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 424 } |
429 | 425 |
430 // Iteration. | 426 // Iteration. |
431 iterator begin() { return list_.begin(); } | 427 iterator begin() { return list_.begin(); } |
432 iterator end() { return list_.end(); } | 428 iterator end() { return list_.end(); } |
433 | 429 |
434 const_iterator begin() const { return list_.begin(); } | 430 const_iterator begin() const { return list_.begin(); } |
435 const_iterator end() const { return list_.end(); } | 431 const_iterator end() const { return list_.end(); } |
436 | 432 |
437 // Overridden from Value: | 433 // Overridden from Value: |
438 virtual ListValue* AsList() OVERRIDE; | |
439 virtual bool GetAsList(ListValue** out_value) OVERRIDE; | 434 virtual bool GetAsList(ListValue** out_value) OVERRIDE; |
440 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; | 435 virtual bool GetAsList(const ListValue** out_value) const OVERRIDE; |
441 virtual ListValue* DeepCopy() const OVERRIDE; | 436 virtual ListValue* DeepCopy() const OVERRIDE; |
442 virtual bool Equals(const Value* other) const OVERRIDE; | 437 virtual bool Equals(const Value* other) const OVERRIDE; |
443 | 438 |
444 private: | 439 private: |
445 ValueVector list_; | 440 ValueVector list_; |
446 | 441 |
447 DISALLOW_COPY_AND_ASSIGN(ListValue); | 442 DISALLOW_COPY_AND_ASSIGN(ListValue); |
448 }; | 443 }; |
(...skipping 17 matching lines...) Expand all Loading... |
466 | 461 |
467 } // namespace base | 462 } // namespace base |
468 | 463 |
469 // http://crbug.com/88666 | 464 // http://crbug.com/88666 |
470 using base::DictionaryValue; | 465 using base::DictionaryValue; |
471 using base::ListValue; | 466 using base::ListValue; |
472 using base::StringValue; | 467 using base::StringValue; |
473 using base::Value; | 468 using base::Value; |
474 | 469 |
475 #endif // BASE_VALUES_H_ | 470 #endif // BASE_VALUES_H_ |
OLD | NEW |