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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 explicit Value(std::string&& in_string) noexcept; | 91 explicit Value(std::string&& in_string) noexcept; |
92 explicit Value(const char16* in_string); | 92 explicit Value(const char16* in_string); |
93 explicit Value(const string16& in_string); | 93 explicit Value(const string16& in_string); |
94 explicit Value(StringPiece in_string); | 94 explicit Value(StringPiece in_string); |
95 | 95 |
96 explicit Value(const BlobStorage& in_blob); | 96 explicit Value(const BlobStorage& in_blob); |
97 explicit Value(BlobStorage&& in_blob) noexcept; | 97 explicit Value(BlobStorage&& in_blob) noexcept; |
98 | 98 |
99 explicit Value(DictStorage&& in_dict) noexcept; | 99 explicit Value(DictStorage&& in_dict) noexcept; |
100 | 100 |
| 101 explicit Value(const ListStorage& in_list); |
| 102 explicit Value(ListStorage&& in_list) noexcept; |
| 103 |
101 Value& operator=(const Value& that); | 104 Value& operator=(const Value& that); |
102 Value& operator=(Value&& that) noexcept; | 105 Value& operator=(Value&& that) noexcept; |
103 | 106 |
104 ~Value(); | 107 ~Value(); |
105 | 108 |
106 // Returns the name for a given |type|. | 109 // Returns the name for a given |type|. |
107 static const char* GetTypeName(Type type); | 110 static const char* GetTypeName(Type type); |
108 | 111 |
109 // Returns the type of the value stored by the current Value object. | 112 // Returns the type of the value stored by the current Value object. |
110 // Each type will be implemented by only one subclass of Value, so it's | 113 // Each type will be implemented by only one subclass of Value, so it's |
(...skipping 13 matching lines...) Expand all Loading... |
124 bool is_dict() const { return type() == Type::DICTIONARY; } | 127 bool is_dict() const { return type() == Type::DICTIONARY; } |
125 bool is_list() const { return type() == Type::LIST; } | 128 bool is_list() const { return type() == Type::LIST; } |
126 | 129 |
127 // These will all fatally assert if the type doesn't match. | 130 // These will all fatally assert if the type doesn't match. |
128 bool GetBool() const; | 131 bool GetBool() const; |
129 int GetInt() const; | 132 int GetInt() const; |
130 double GetDouble() const; // Implicitly converts from int if necessary. | 133 double GetDouble() const; // Implicitly converts from int if necessary. |
131 const std::string& GetString() const; | 134 const std::string& GetString() const; |
132 const BlobStorage& GetBlob() const; | 135 const BlobStorage& GetBlob() const; |
133 | 136 |
| 137 ListStorage& GetList(); |
| 138 const ListStorage& GetList() const; |
| 139 |
134 size_t GetSize() const; // DEPRECATED, use GetBlob().size() instead. | 140 size_t GetSize() const; // DEPRECATED, use GetBlob().size() instead. |
135 const char* GetBuffer() const; // DEPRECATED, use GetBlob().data() instead. | 141 const char* GetBuffer() const; // DEPRECATED, use GetBlob().data() instead. |
136 | 142 |
137 // These methods allow the convenient retrieval of the contents of the Value. | 143 // 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 | 144 // 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; | 145 // returned through the |out_value| parameter and true is returned; |
140 // otherwise, false is returned and |out_value| is unchanged. | 146 // otherwise, false is returned and |out_value| is unchanged. |
141 bool GetAsBoolean(bool* out_value) const; | 147 bool GetAsBoolean(bool* out_value) const; |
142 bool GetAsInteger(int* out_value) const; | 148 bool GetAsInteger(int* out_value) const; |
143 bool GetAsDouble(double* out_value) const; | 149 bool GetAsDouble(double* out_value) const; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 return out << static_cast<const Value&>(value); | 538 return out << static_cast<const Value&>(value); |
533 } | 539 } |
534 | 540 |
535 // Stream operator so that enum class Types can be used in log statements. | 541 // Stream operator so that enum class Types can be used in log statements. |
536 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 542 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
537 const Value::Type& type); | 543 const Value::Type& type); |
538 | 544 |
539 } // namespace base | 545 } // namespace base |
540 | 546 |
541 #endif // BASE_VALUES_H_ | 547 #endif // BASE_VALUES_H_ |
OLD | NEW |