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 setting and other persistable data. It includes the ability to | 6 // storing setting and other persistable data. It includes the ability to |
7 // specify (recursive) lists and dictionaries, so it's fairly expressive. | 7 // specify (recursive) lists and dictionaries, so it's fairly expressive. |
8 // However, the API is optimized for the common case, namely storing a | 8 // However, the API is optimized for the common case, namely storing a |
9 // hierarchical tree of simple values. Given a DictionaryValue root, you can | 9 // hierarchical tree of simple values. Given a DictionaryValue root, you can |
10 // easily do things like: | 10 // easily do things like: |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 virtual Value* DeepCopy() const; | 107 virtual Value* DeepCopy() const; |
108 | 108 |
109 // Compares if two Value objects have equal contents. | 109 // Compares if two Value objects have equal contents. |
110 virtual bool Equals(const Value* other) const; | 110 virtual bool Equals(const Value* other) const; |
111 | 111 |
112 // Compares if two Value objects have equal contents. Can handle NULLs. | 112 // Compares if two Value objects have equal contents. Can handle NULLs. |
113 // NULLs are considered equal but different from Value::CreateNullValue(). | 113 // NULLs are considered equal but different from Value::CreateNullValue(). |
114 static bool Equals(const Value* a, const Value* b); | 114 static bool Equals(const Value* a, const Value* b); |
115 | 115 |
116 protected: | 116 protected: |
117 // This isn't safe for end-users (they should use the Create*Value() | 117 // These aren't safe for end-users, but they are useful for subclasses. |
118 // static methods above), but it's useful for subclasses. | |
119 explicit Value(Type type); | 118 explicit Value(Type type); |
119 Value(const Value& value); | |
120 void operator=(const Value& value); | |
brettw
2012/11/17 20:57:01
This should return Value&
| |
120 | 121 |
121 private: | 122 private: |
122 Value(); | |
123 | |
124 Type type_; | 123 Type type_; |
125 | |
126 DISALLOW_COPY_AND_ASSIGN(Value); | |
127 }; | 124 }; |
128 | 125 |
129 // FundamentalValue represents the simple fundamental types of values. | 126 // FundamentalValue represents the simple fundamental types of values. |
130 class BASE_EXPORT FundamentalValue : public Value { | 127 class BASE_EXPORT FundamentalValue : public Value { |
131 public: | 128 public: |
132 explicit FundamentalValue(bool in_value); | 129 explicit FundamentalValue(bool in_value); |
133 explicit FundamentalValue(int in_value); | 130 explicit FundamentalValue(int in_value); |
134 explicit FundamentalValue(double in_value); | 131 explicit FundamentalValue(double in_value); |
135 virtual ~FundamentalValue(); | 132 virtual ~FundamentalValue(); |
136 | 133 |
137 // Overridden from Value: | 134 // Overridden from Value: |
138 virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; | 135 virtual bool GetAsBoolean(bool* out_value) const OVERRIDE; |
139 virtual bool GetAsInteger(int* out_value) const OVERRIDE; | 136 virtual bool GetAsInteger(int* out_value) const OVERRIDE; |
140 virtual bool GetAsDouble(double* out_value) const OVERRIDE; | 137 virtual bool GetAsDouble(double* out_value) const OVERRIDE; |
141 virtual FundamentalValue* DeepCopy() const OVERRIDE; | 138 virtual FundamentalValue* DeepCopy() const OVERRIDE; |
142 virtual bool Equals(const Value* other) const OVERRIDE; | 139 virtual bool Equals(const Value* other) const OVERRIDE; |
143 | 140 |
144 private: | 141 private: |
145 union { | 142 union { |
146 bool boolean_value_; | 143 bool boolean_value_; |
147 int integer_value_; | 144 int integer_value_; |
148 double double_value_; | 145 double double_value_; |
149 }; | 146 }; |
150 | |
151 DISALLOW_COPY_AND_ASSIGN(FundamentalValue); | |
152 }; | 147 }; |
153 | 148 |
154 class BASE_EXPORT StringValue : public Value { | 149 class BASE_EXPORT StringValue : public Value { |
155 public: | 150 public: |
156 // Initializes a StringValue with a UTF-8 narrow character string. | 151 // Initializes a StringValue with a UTF-8 narrow character string. |
157 explicit StringValue(const std::string& in_value); | 152 explicit StringValue(const std::string& in_value); |
158 | 153 |
159 // Initializes a StringValue with a string16. | 154 // Initializes a StringValue with a string16. |
160 explicit StringValue(const string16& in_value); | 155 explicit StringValue(const string16& in_value); |
161 | 156 |
162 virtual ~StringValue(); | 157 virtual ~StringValue(); |
163 | 158 |
164 // Overridden from Value: | 159 // Overridden from Value: |
165 virtual bool GetAsString(std::string* out_value) const OVERRIDE; | 160 virtual bool GetAsString(std::string* out_value) const OVERRIDE; |
166 virtual bool GetAsString(string16* out_value) const OVERRIDE; | 161 virtual bool GetAsString(string16* out_value) const OVERRIDE; |
167 virtual StringValue* DeepCopy() const OVERRIDE; | 162 virtual StringValue* DeepCopy() const OVERRIDE; |
168 virtual bool Equals(const Value* other) const OVERRIDE; | 163 virtual bool Equals(const Value* other) const OVERRIDE; |
169 | 164 |
170 private: | 165 private: |
171 std::string value_; | 166 std::string value_; |
172 | |
173 DISALLOW_COPY_AND_ASSIGN(StringValue); | |
174 }; | 167 }; |
175 | 168 |
176 class BASE_EXPORT BinaryValue: public Value { | 169 class BASE_EXPORT BinaryValue: public Value { |
177 public: | 170 public: |
178 virtual ~BinaryValue(); | 171 virtual ~BinaryValue(); |
179 | 172 |
180 // Creates a Value to represent a binary buffer. The new object takes | 173 // Creates a Value to represent a binary buffer. The new object takes |
181 // ownership of the pointer passed in, if successful. | 174 // ownership of the pointer passed in, if successful. |
182 // Returns NULL if buffer is NULL. | 175 // Returns NULL if buffer is NULL. |
183 static BinaryValue* Create(char* buffer, size_t size); | 176 static BinaryValue* Create(char* buffer, size_t size); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 | 522 |
530 } // namespace base | 523 } // namespace base |
531 | 524 |
532 // http://crbug.com/88666 | 525 // http://crbug.com/88666 |
533 using base::DictionaryValue; | 526 using base::DictionaryValue; |
534 using base::ListValue; | 527 using base::ListValue; |
535 using base::StringValue; | 528 using base::StringValue; |
536 using base::Value; | 529 using base::Value; |
537 | 530 |
538 #endif // BASE_VALUES_H_ | 531 #endif // BASE_VALUES_H_ |
OLD | NEW |