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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // These methods allow the convenient retrieval of the contents of the Value. | 81 // These methods allow the convenient retrieval of the contents of the Value. |
82 // If the current object can be converted into the given type, the value is | 82 // If the current object can be converted into the given type, the value is |
83 // returned through the |out_value| parameter and true is returned; | 83 // returned through the |out_value| parameter and true is returned; |
84 // otherwise, false is returned and |out_value| is unchanged. | 84 // otherwise, false is returned and |out_value| is unchanged. |
85 virtual bool GetAsBoolean(bool* out_value) const; | 85 virtual bool GetAsBoolean(bool* out_value) const; |
86 virtual bool GetAsInteger(int* out_value) const; | 86 virtual bool GetAsInteger(int* out_value) const; |
87 virtual bool GetAsDouble(double* out_value) const; | 87 virtual bool GetAsDouble(double* out_value) const; |
88 virtual bool GetAsString(std::string* out_value) const; | 88 virtual bool GetAsString(std::string* out_value) const; |
89 virtual bool GetAsString(string16* out_value) const; | 89 virtual bool GetAsString(string16* out_value) const; |
90 virtual bool GetAsString(const StringValue** out_value) const; | 90 virtual bool GetAsString(const StringValue** out_value) const; |
| 91 virtual bool GetAsString(StringPiece* out_value) const; |
91 virtual bool GetAsBinary(const BinaryValue** out_value) const; | 92 virtual bool GetAsBinary(const BinaryValue** out_value) const; |
92 // ListValue::From is the equivalent for std::unique_ptr conversions. | 93 // ListValue::From is the equivalent for std::unique_ptr conversions. |
93 virtual bool GetAsList(ListValue** out_value); | 94 virtual bool GetAsList(ListValue** out_value); |
94 virtual bool GetAsList(const ListValue** out_value) const; | 95 virtual bool GetAsList(const ListValue** out_value) const; |
95 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. | 96 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. |
96 virtual bool GetAsDictionary(DictionaryValue** out_value); | 97 virtual bool GetAsDictionary(DictionaryValue** out_value); |
97 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; | 98 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; |
98 // Note: Do not add more types. See the file-level comment above for why. | 99 // Note: Do not add more types. See the file-level comment above for why. |
99 | 100 |
100 // This creates a deep copy of the entire Value tree, and returns a pointer | 101 // This creates a deep copy of the entire Value tree, and returns a pointer |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 ~StringValue() override; | 160 ~StringValue() override; |
160 | 161 |
161 // Returns |value_| as a pointer or reference. | 162 // Returns |value_| as a pointer or reference. |
162 std::string* GetString(); | 163 std::string* GetString(); |
163 const std::string& GetString() const; | 164 const std::string& GetString() const; |
164 | 165 |
165 // Overridden from Value: | 166 // Overridden from Value: |
166 bool GetAsString(std::string* out_value) const override; | 167 bool GetAsString(std::string* out_value) const override; |
167 bool GetAsString(string16* out_value) const override; | 168 bool GetAsString(string16* out_value) const override; |
168 bool GetAsString(const StringValue** out_value) const override; | 169 bool GetAsString(const StringValue** out_value) const override; |
| 170 bool GetAsString(StringPiece* out_value) const override; |
169 StringValue* DeepCopy() const override; | 171 StringValue* DeepCopy() const override; |
170 bool Equals(const Value* other) const override; | 172 bool Equals(const Value* other) const override; |
171 | 173 |
172 private: | 174 private: |
173 std::string value_; | 175 std::string value_; |
174 }; | 176 }; |
175 | 177 |
176 class BASE_EXPORT BinaryValue: public Value { | 178 class BASE_EXPORT BinaryValue: public Value { |
177 public: | 179 public: |
178 // Creates a BinaryValue with a null buffer and size of 0. | 180 // Creates a BinaryValue with a null buffer and size of 0. |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 return out << static_cast<const Value&>(value); | 564 return out << static_cast<const Value&>(value); |
563 } | 565 } |
564 | 566 |
565 // Stream operator so that enum class Types can be used in log statements. | 567 // Stream operator so that enum class Types can be used in log statements. |
566 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 568 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
567 const Value::Type& type); | 569 const Value::Type& type); |
568 | 570 |
569 } // namespace base | 571 } // namespace base |
570 | 572 |
571 #endif // BASE_VALUES_H_ | 573 #endif // BASE_VALUES_H_ |
OLD | NEW |