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 21 matching lines...) Expand all Loading... |
32 #include "base/macros.h" | 32 #include "base/macros.h" |
33 #include "base/memory/manual_constructor.h" | 33 #include "base/memory/manual_constructor.h" |
34 #include "base/strings/string16.h" | 34 #include "base/strings/string16.h" |
35 #include "base/strings/string_piece.h" | 35 #include "base/strings/string_piece.h" |
36 | 36 |
37 namespace base { | 37 namespace base { |
38 | 38 |
39 class DictionaryValue; | 39 class DictionaryValue; |
40 class ListValue; | 40 class ListValue; |
41 class Value; | 41 class Value; |
42 using StringValue = Value; | |
43 using BinaryValue = Value; | 42 using BinaryValue = Value; |
44 | 43 |
45 // The Value class is the base class for Values. A Value can be instantiated | 44 // The Value class is the base class for Values. A Value can be instantiated |
46 // via the Create*Value() factory methods, or by directly creating instances of | 45 // via the Create*Value() factory methods, or by directly creating instances of |
47 // the subclasses. | 46 // the subclasses. |
48 // | 47 // |
49 // See the file-level comment above for more information. | 48 // See the file-level comment above for more information. |
50 class BASE_EXPORT Value { | 49 class BASE_EXPORT Value { |
51 public: | 50 public: |
52 using DictStorage = std::map<std::string, std::unique_ptr<Value>>; | 51 using DictStorage = std::map<std::string, std::unique_ptr<Value>>; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 135 |
137 // These methods allow the convenient retrieval of the contents of the Value. | 136 // These methods allow the convenient retrieval of the contents of the Value. |
138 // If the current object can be converted into the given type, the value is | 137 // If the current object can be converted into the given type, the value is |
139 // returned through the |out_value| parameter and true is returned; | 138 // returned through the |out_value| parameter and true is returned; |
140 // otherwise, false is returned and |out_value| is unchanged. | 139 // otherwise, false is returned and |out_value| is unchanged. |
141 bool GetAsBoolean(bool* out_value) const; | 140 bool GetAsBoolean(bool* out_value) const; |
142 bool GetAsInteger(int* out_value) const; | 141 bool GetAsInteger(int* out_value) const; |
143 bool GetAsDouble(double* out_value) const; | 142 bool GetAsDouble(double* out_value) const; |
144 bool GetAsString(std::string* out_value) const; | 143 bool GetAsString(std::string* out_value) const; |
145 bool GetAsString(string16* out_value) const; | 144 bool GetAsString(string16* out_value) const; |
146 bool GetAsString(const StringValue** out_value) const; | 145 bool GetAsString(const Value** out_value) const; |
147 bool GetAsString(StringPiece* out_value) const; | 146 bool GetAsString(StringPiece* out_value) const; |
148 bool GetAsBinary(const BinaryValue** out_value) const; | 147 bool GetAsBinary(const BinaryValue** out_value) const; |
149 // ListValue::From is the equivalent for std::unique_ptr conversions. | 148 // ListValue::From is the equivalent for std::unique_ptr conversions. |
150 bool GetAsList(ListValue** out_value); | 149 bool GetAsList(ListValue** out_value); |
151 bool GetAsList(const ListValue** out_value) const; | 150 bool GetAsList(const ListValue** out_value) const; |
152 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. | 151 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. |
153 bool GetAsDictionary(DictionaryValue** out_value); | 152 bool GetAsDictionary(DictionaryValue** out_value); |
154 bool GetAsDictionary(const DictionaryValue** out_value) const; | 153 bool GetAsDictionary(const DictionaryValue** out_value) const; |
155 // Note: Do not add more types. See the file-level comment above for why. | 154 // Note: Do not add more types. See the file-level comment above for why. |
156 | 155 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 return out << static_cast<const Value&>(value); | 514 return out << static_cast<const Value&>(value); |
516 } | 515 } |
517 | 516 |
518 // Stream operator so that enum class Types can be used in log statements. | 517 // Stream operator so that enum class Types can be used in log statements. |
519 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 518 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
520 const Value::Type& type); | 519 const Value::Type& type); |
521 | 520 |
522 } // namespace base | 521 } // namespace base |
523 | 522 |
524 #endif // BASE_VALUES_H_ | 523 #endif // BASE_VALUES_H_ |
OLD | NEW |