Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 // its type after construction. | 72 // its type after construction. |
| 73 Type GetType() const { return type_; } | 73 Type GetType() const { return type_; } |
| 74 | 74 |
| 75 // Returns true if the current object represents a given type. | 75 // Returns true if the current object represents a given type. |
| 76 bool IsType(Type type) const { return type == type_; } | 76 bool IsType(Type type) const { return type == type_; } |
| 77 | 77 |
| 78 // These methods allow the convenient retrieval of the contents of the Value. | 78 // These methods allow the convenient retrieval of the contents of the Value. |
| 79 // If the current object can be converted into the given type, the value is | 79 // If the current object can be converted into the given type, the value is |
| 80 // returned through the |out_value| parameter and true is returned; | 80 // returned through the |out_value| parameter and true is returned; |
| 81 // otherwise, false is returned and |out_value| is unchanged. | 81 // otherwise, false is returned and |out_value| is unchanged. |
| 82 virtual bool GetAsBinary(std::string* out_value) const; | |
|
Mark Mentovai
2015/01/14 14:39:59
Can you keep these methods sorted like the Type en
| |
| 82 virtual bool GetAsBoolean(bool* out_value) const; | 83 virtual bool GetAsBoolean(bool* out_value) const; |
| 83 virtual bool GetAsInteger(int* out_value) const; | 84 virtual bool GetAsInteger(int* out_value) const; |
| 84 virtual bool GetAsDouble(double* out_value) const; | 85 virtual bool GetAsDouble(double* out_value) const; |
| 85 virtual bool GetAsString(std::string* out_value) const; | 86 virtual bool GetAsString(std::string* out_value) const; |
| 86 virtual bool GetAsString(string16* out_value) const; | 87 virtual bool GetAsString(string16* out_value) const; |
| 87 virtual bool GetAsString(const StringValue** out_value) const; | 88 virtual bool GetAsString(const StringValue** out_value) const; |
| 88 virtual bool GetAsList(ListValue** out_value); | 89 virtual bool GetAsList(ListValue** out_value); |
| 89 virtual bool GetAsList(const ListValue** out_value) const; | 90 virtual bool GetAsList(const ListValue** out_value) const; |
| 90 virtual bool GetAsDictionary(DictionaryValue** out_value); | 91 virtual bool GetAsDictionary(DictionaryValue** out_value); |
| 91 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; | 92 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 // buffer that's passed in. | 182 // buffer that's passed in. |
| 182 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); | 183 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); |
| 183 | 184 |
| 184 size_t GetSize() const { return size_; } | 185 size_t GetSize() const { return size_; } |
| 185 | 186 |
| 186 // May return NULL. | 187 // May return NULL. |
| 187 char* GetBuffer() { return buffer_.get(); } | 188 char* GetBuffer() { return buffer_.get(); } |
| 188 const char* GetBuffer() const { return buffer_.get(); } | 189 const char* GetBuffer() const { return buffer_.get(); } |
| 189 | 190 |
| 190 // Overridden from Value: | 191 // Overridden from Value: |
| 192 bool GetAsBinary(std::string* out_value) const override; | |
| 191 BinaryValue* DeepCopy() const override; | 193 BinaryValue* DeepCopy() const override; |
| 192 bool Equals(const Value* other) const override; | 194 bool Equals(const Value* other) const override; |
| 193 | 195 |
| 194 private: | 196 private: |
| 195 scoped_ptr<char[]> buffer_; | 197 scoped_ptr<char[]> buffer_; |
| 196 size_t size_; | 198 size_t size_; |
| 197 | 199 |
| 198 DISALLOW_COPY_AND_ASSIGN(BinaryValue); | 200 DISALLOW_COPY_AND_ASSIGN(BinaryValue); |
| 199 }; | 201 }; |
| 200 | 202 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 } | 530 } |
| 529 | 531 |
| 530 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, | 532 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
| 531 const ListValue& value) { | 533 const ListValue& value) { |
| 532 return out << static_cast<const Value&>(value); | 534 return out << static_cast<const Value&>(value); |
| 533 } | 535 } |
| 534 | 536 |
| 535 } // namespace base | 537 } // namespace base |
| 536 | 538 |
| 537 #endif // BASE_VALUES_H_ | 539 #endif // BASE_VALUES_H_ |
| OLD | NEW |