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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 | 84 |
| 85 // These methods allow the convenient retrieval of the contents of the Value. | 85 // These methods allow the convenient retrieval of the contents of the Value. |
| 86 // If the current object can be converted into the given type, the value is | 86 // If the current object can be converted into the given type, the value is |
| 87 // returned through the |out_value| parameter and true is returned; | 87 // returned through the |out_value| parameter and true is returned; |
| 88 // otherwise, false is returned and |out_value| is unchanged. | 88 // otherwise, false is returned and |out_value| is unchanged. |
| 89 virtual bool GetAsBoolean(bool* out_value) const; | 89 virtual bool GetAsBoolean(bool* out_value) const; |
| 90 virtual bool GetAsInteger(int* out_value) const; | 90 virtual bool GetAsInteger(int* out_value) const; |
| 91 virtual bool GetAsDouble(double* out_value) const; | 91 virtual bool GetAsDouble(double* out_value) const; |
| 92 virtual bool GetAsString(std::string* out_value) const; | 92 virtual bool GetAsString(std::string* out_value) const; |
| 93 virtual bool GetAsString(string16* out_value) const; | 93 virtual bool GetAsString(string16* out_value) const; |
| 94 virtual bool GetAsStringValue(const StringValue** out_value) const; | |
|
brettw
2014/01/28 03:00:24
This new name seems good but it doesn't follow the
| |
| 94 virtual bool GetAsList(ListValue** out_value); | 95 virtual bool GetAsList(ListValue** out_value); |
| 95 virtual bool GetAsList(const ListValue** out_value) const; | 96 virtual bool GetAsList(const ListValue** out_value) const; |
| 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 |
| 101 // to the copy. The caller gets ownership of the copy, of course. | 102 // to the copy. The caller gets ownership of the copy, of course. |
| 102 // | 103 // |
| 103 // Subclasses return their own type directly in their overrides; | 104 // Subclasses return their own type directly in their overrides; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 }; | 146 }; |
| 146 | 147 |
| 147 class BASE_EXPORT StringValue : public Value { | 148 class BASE_EXPORT StringValue : public Value { |
| 148 public: | 149 public: |
| 149 // Initializes a StringValue with a UTF-8 narrow character string. | 150 // Initializes a StringValue with a UTF-8 narrow character string. |
| 150 explicit StringValue(const std::string& in_value); | 151 explicit StringValue(const std::string& in_value); |
| 151 | 152 |
| 152 // Initializes a StringValue with a string16. | 153 // Initializes a StringValue with a string16. |
| 153 explicit StringValue(const string16& in_value); | 154 explicit StringValue(const string16& in_value); |
| 154 | 155 |
| 156 // Creates a string value that takes ownership of a string. | |
| 157 explicit StringValue(scoped_ptr<std::string> in_value); | |
| 158 | |
| 155 virtual ~StringValue(); | 159 virtual ~StringValue(); |
| 156 | 160 |
| 157 // Overridden from Value: | 161 // Overridden from Value: |
| 158 virtual bool GetAsString(std::string* out_value) const OVERRIDE; | 162 virtual bool GetAsString(std::string* out_value) const OVERRIDE; |
| 159 virtual bool GetAsString(string16* out_value) const OVERRIDE; | 163 virtual bool GetAsString(string16* out_value) const OVERRIDE; |
| 164 virtual bool GetAsStringValue(const StringValue** out_value) const OVERRIDE; | |
| 160 virtual StringValue* DeepCopy() const OVERRIDE; | 165 virtual StringValue* DeepCopy() const OVERRIDE; |
| 161 virtual bool Equals(const Value* other) const OVERRIDE; | 166 virtual bool Equals(const Value* other) const OVERRIDE; |
| 162 | 167 |
| 168 const std::string& value() const { return *value_; } | |
| 169 | |
| 163 private: | 170 private: |
| 164 std::string value_; | 171 scoped_ptr<std::string> value_; |
|
brettw
2014/01/28 03:00:24
I assume you did this to avoid the extra copy when
Evan Stade
2014/01/28 18:37:36
yes
Evan Stade
2014/01/28 18:43:35
Actually, it looks like StringPiece can't return a
Evan Stade
2014/01/28 18:48:45
Well, even in lieu of that other optimization, I s
| |
| 165 }; | 172 }; |
| 166 | 173 |
| 167 class BASE_EXPORT BinaryValue: public Value { | 174 class BASE_EXPORT BinaryValue: public Value { |
| 168 public: | 175 public: |
| 169 // Creates a BinaryValue with a null buffer and size of 0. | 176 // Creates a BinaryValue with a null buffer and size of 0. |
| 170 BinaryValue(); | 177 BinaryValue(); |
| 171 | 178 |
| 172 // Creates a BinaryValue, taking ownership of the bytes pointed to by | 179 // Creates a BinaryValue, taking ownership of the bytes pointed to by |
| 173 // |buffer|. | 180 // |buffer|. |
| 174 BinaryValue(scoped_ptr<char[]> buffer, size_t size); | 181 BinaryValue(scoped_ptr<char[]> buffer, size_t size); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 } | 524 } |
| 518 | 525 |
| 519 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, | 526 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, |
| 520 const ListValue& value) { | 527 const ListValue& value) { |
| 521 return out << static_cast<const Value&>(value); | 528 return out << static_cast<const Value&>(value); |
| 522 } | 529 } |
| 523 | 530 |
| 524 } // namespace base | 531 } // namespace base |
| 525 | 532 |
| 526 #endif // BASE_VALUES_H_ | 533 #endif // BASE_VALUES_H_ |
| OLD | NEW |