Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1454)

Side by Side Diff: base/values.h

Issue 148463003: libaddressinput - reduce number of copies in storage class by 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/values.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 GetAsString(const StringValue** out_value) const;
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
155 virtual ~StringValue(); 156 virtual ~StringValue();
156 157
158 // Returns |value_| as a pointer or reference.
159 std::string* GetString();
160 const std::string& GetString() const;
161
157 // Overridden from Value: 162 // Overridden from Value:
158 virtual bool GetAsString(std::string* out_value) const OVERRIDE; 163 virtual bool GetAsString(std::string* out_value) const OVERRIDE;
159 virtual bool GetAsString(string16* out_value) const OVERRIDE; 164 virtual bool GetAsString(string16* out_value) const OVERRIDE;
165 virtual bool GetAsString(const StringValue** out_value) const OVERRIDE;
160 virtual StringValue* DeepCopy() const OVERRIDE; 166 virtual StringValue* DeepCopy() const OVERRIDE;
161 virtual bool Equals(const Value* other) const OVERRIDE; 167 virtual bool Equals(const Value* other) const OVERRIDE;
162 168
163 private: 169 private:
164 std::string value_; 170 std::string value_;
165 }; 171 };
166 172
167 class BASE_EXPORT BinaryValue: public Value { 173 class BASE_EXPORT BinaryValue: public Value {
168 public: 174 public:
169 // Creates a BinaryValue with a null buffer and size of 0. 175 // Creates a BinaryValue with a null buffer and size of 0.
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 } 523 }
518 524
519 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, 525 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out,
520 const ListValue& value) { 526 const ListValue& value) {
521 return out << static_cast<const Value&>(value); 527 return out << static_cast<const Value&>(value);
522 } 528 }
523 529
524 } // namespace base 530 } // namespace base
525 531
526 #endif // BASE_VALUES_H_ 532 #endif // BASE_VALUES_H_
OLDNEW
« no previous file with comments | « no previous file | base/values.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698