OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 settings and other persistable data. | 6 // storing settings and other persistable data. |
7 // | 7 // |
8 // A Value represents something that can be stored in JSON or passed to/from | 8 // A Value represents something that can be stored in JSON or passed to/from |
9 // JavaScript. As such, it is NOT a generalized variant type, since only the | 9 // JavaScript. As such, it is NOT a generalized variant type, since only the |
10 // types supported by JavaScript/JSON are supported. | 10 // types supported by JavaScript/JSON are supported. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 class BASE_EXPORT FundamentalValue : public Value { | 126 class BASE_EXPORT FundamentalValue : public Value { |
127 public: | 127 public: |
128 explicit FundamentalValue(bool in_value); | 128 explicit FundamentalValue(bool in_value); |
129 explicit FundamentalValue(int in_value); | 129 explicit FundamentalValue(int in_value); |
130 explicit FundamentalValue(double in_value); | 130 explicit FundamentalValue(double in_value); |
131 virtual ~FundamentalValue(); | 131 virtual ~FundamentalValue(); |
132 | 132 |
133 // Overridden from Value: | 133 // Overridden from Value: |
134 virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; | 134 virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; |
135 virtual bool GetAsInteger(int* out_value) const OVERRIDE; | 135 virtual bool GetAsInteger(int* out_value) const OVERRIDE; |
| 136 // Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as |
| 137 // doubles. |
136 virtual bool GetAsDouble(double* out_value) const OVERRIDE; | 138 virtual bool GetAsDouble(double* out_value) const OVERRIDE; |
137 virtual FundamentalValue* DeepCopy() const OVERRIDE; | 139 virtual FundamentalValue* DeepCopy() const OVERRIDE; |
138 virtual bool Equals(const Value* other) const OVERRIDE; | 140 virtual bool Equals(const Value* other) const OVERRIDE; |
139 | 141 |
140 private: | 142 private: |
141 union { | 143 union { |
142 bool boolean_value_; | 144 bool boolean_value_; |
143 int integer_value_; | 145 int integer_value_; |
144 double double_value_; | 146 double double_value_; |
145 }; | 147 }; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 void SetStringWithoutPathExpansion(const std::string& path, | 262 void SetStringWithoutPathExpansion(const std::string& path, |
261 const string16& in_value); | 263 const string16& in_value); |
262 | 264 |
263 // Gets the Value associated with the given path starting from this object. | 265 // Gets the Value associated with the given path starting from this object. |
264 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 266 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
265 // into the next DictionaryValue down. If the path can be resolved | 267 // into the next DictionaryValue down. If the path can be resolved |
266 // successfully, the value for the last key in the path will be returned | 268 // successfully, the value for the last key in the path will be returned |
267 // through the |out_value| parameter, and the function will return true. | 269 // through the |out_value| parameter, and the function will return true. |
268 // Otherwise, it will return false and |out_value| will be untouched. | 270 // Otherwise, it will return false and |out_value| will be untouched. |
269 // Note that the dictionary always owns the value that's returned. | 271 // Note that the dictionary always owns the value that's returned. |
| 272 // |out_value| is optional and will only be set if non-NULL. |
270 bool Get(const std::string& path, const Value** out_value) const; | 273 bool Get(const std::string& path, const Value** out_value) const; |
271 bool Get(const std::string& path, Value** out_value); | 274 bool Get(const std::string& path, Value** out_value); |
272 | 275 |
273 // These are convenience forms of Get(). The value will be retrieved | 276 // These are convenience forms of Get(). The value will be retrieved |
274 // and the return value will be true if the path is valid and the value at | 277 // and the return value will be true if the path is valid and the value at |
275 // the end of the path can be returned in the form specified. | 278 // the end of the path can be returned in the form specified. |
| 279 // |out_value| is optional and will only be set if non-NULL. |
276 bool GetBoolean(const std::string& path, bool* out_value) const; | 280 bool GetBoolean(const std::string& path, bool* out_value) const; |
277 bool GetInteger(const std::string& path, int* out_value) const; | 281 bool GetInteger(const std::string& path, int* out_value) const; |
| 282 // Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as |
| 283 // doubles. |
278 bool GetDouble(const std::string& path, double* out_value) const; | 284 bool GetDouble(const std::string& path, double* out_value) const; |
279 bool GetString(const std::string& path, std::string* out_value) const; | 285 bool GetString(const std::string& path, std::string* out_value) const; |
280 bool GetString(const std::string& path, string16* out_value) const; | 286 bool GetString(const std::string& path, string16* out_value) const; |
281 bool GetStringASCII(const std::string& path, std::string* out_value) const; | 287 bool GetStringASCII(const std::string& path, std::string* out_value) const; |
282 bool GetBinary(const std::string& path, const BinaryValue** out_value) const; | 288 bool GetBinary(const std::string& path, const BinaryValue** out_value) const; |
283 bool GetBinary(const std::string& path, BinaryValue** out_value); | 289 bool GetBinary(const std::string& path, BinaryValue** out_value); |
284 bool GetDictionary(const std::string& path, | 290 bool GetDictionary(const std::string& path, |
285 const DictionaryValue** out_value) const; | 291 const DictionaryValue** out_value) const; |
286 bool GetDictionary(const std::string& path, DictionaryValue** out_value); | 292 bool GetDictionary(const std::string& path, DictionaryValue** out_value); |
287 bool GetList(const std::string& path, const ListValue** out_value) const; | 293 bool GetList(const std::string& path, const ListValue** out_value) const; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 // Sets the list item at the given index to be the Value specified by | 399 // Sets the list item at the given index to be the Value specified by |
394 // the value given. If the index beyond the current end of the list, null | 400 // the value given. If the index beyond the current end of the list, null |
395 // Values will be used to pad out the list. | 401 // Values will be used to pad out the list. |
396 // Returns true if successful, or false if the index was negative or | 402 // Returns true if successful, or false if the index was negative or |
397 // the value is a null pointer. | 403 // the value is a null pointer. |
398 bool Set(size_t index, Value* in_value); | 404 bool Set(size_t index, Value* in_value); |
399 | 405 |
400 // Gets the Value at the given index. Modifies |out_value| (and returns true) | 406 // Gets the Value at the given index. Modifies |out_value| (and returns true) |
401 // only if the index falls within the current list range. | 407 // only if the index falls within the current list range. |
402 // Note that the list always owns the Value passed out via |out_value|. | 408 // Note that the list always owns the Value passed out via |out_value|. |
| 409 // |out_value| is optional and will only be set if non-NULL. |
403 bool Get(size_t index, const Value** out_value) const; | 410 bool Get(size_t index, const Value** out_value) const; |
404 bool Get(size_t index, Value** out_value); | 411 bool Get(size_t index, Value** out_value); |
405 | 412 |
406 // Convenience forms of Get(). Modifies |out_value| (and returns true) | 413 // Convenience forms of Get(). Modifies |out_value| (and returns true) |
407 // only if the index is valid and the Value at that index can be returned | 414 // only if the index is valid and the Value at that index can be returned |
408 // in the specified form. | 415 // in the specified form. |
| 416 // |out_value| is optional and will only be set if non-NULL. |
409 bool GetBoolean(size_t index, bool* out_value) const; | 417 bool GetBoolean(size_t index, bool* out_value) const; |
410 bool GetInteger(size_t index, int* out_value) const; | 418 bool GetInteger(size_t index, int* out_value) const; |
| 419 // Values of both type TYPE_INTEGER and TYPE_DOUBLE can be obtained as |
| 420 // doubles. |
411 bool GetDouble(size_t index, double* out_value) const; | 421 bool GetDouble(size_t index, double* out_value) const; |
412 bool GetString(size_t index, std::string* out_value) const; | 422 bool GetString(size_t index, std::string* out_value) const; |
413 bool GetString(size_t index, string16* out_value) const; | 423 bool GetString(size_t index, string16* out_value) const; |
414 bool GetBinary(size_t index, const BinaryValue** out_value) const; | 424 bool GetBinary(size_t index, const BinaryValue** out_value) const; |
415 bool GetBinary(size_t index, BinaryValue** out_value); | 425 bool GetBinary(size_t index, BinaryValue** out_value); |
416 bool GetDictionary(size_t index, const DictionaryValue** out_value) const; | 426 bool GetDictionary(size_t index, const DictionaryValue** out_value) const; |
417 bool GetDictionary(size_t index, DictionaryValue** out_value); | 427 bool GetDictionary(size_t index, DictionaryValue** out_value); |
418 bool GetList(size_t index, const ListValue** out_value) const; | 428 bool GetList(size_t index, const ListValue** out_value) const; |
419 bool GetList(size_t index, ListValue** out_value); | 429 bool GetList(size_t index, ListValue** out_value); |
420 | 430 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 533 } |
524 | 534 |
525 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, | 535 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
526 const ListValue& value) { | 536 const ListValue& value) { |
527 return out << static_cast<const Value&>(value); | 537 return out << static_cast<const Value&>(value); |
528 } | 538 } |
529 | 539 |
530 } // namespace base | 540 } // namespace base |
531 | 541 |
532 #endif // BASE_VALUES_H_ | 542 #endif // BASE_VALUES_H_ |
OLD | NEW |