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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 using StringValue = Value; | 43 using StringValue = Value; |
44 using BinaryValue = Value; | 44 using BinaryValue = Value; |
45 | 45 |
46 // The Value class is the base class for Values. A Value can be instantiated | 46 // The Value class is the base class for Values. A Value can be instantiated |
47 // via the Create*Value() factory methods, or by directly creating instances of | 47 // via the Create*Value() factory methods, or by directly creating instances of |
48 // the subclasses. | 48 // the subclasses. |
49 // | 49 // |
50 // See the file-level comment above for more information. | 50 // See the file-level comment above for more information. |
51 class BASE_EXPORT Value { | 51 class BASE_EXPORT Value { |
52 public: | 52 public: |
53 using DictStorage = std::map<std::string, std::unique_ptr<Value>>; | |
54 using ListStorage = std::vector<std::unique_ptr<Value>>; | |
55 | |
53 enum class Type { | 56 enum class Type { |
54 NONE = 0, | 57 NONE = 0, |
55 BOOLEAN, | 58 BOOLEAN, |
56 INTEGER, | 59 INTEGER, |
57 DOUBLE, | 60 DOUBLE, |
58 STRING, | 61 STRING, |
59 BINARY, | 62 BINARY, |
60 DICTIONARY, | 63 DICTIONARY, |
61 LIST | 64 LIST |
62 // Note: Do not add more types. See the file-level comment above for why. | 65 // Note: Do not add more types. See the file-level comment above for why. |
(...skipping 29 matching lines...) Expand all Loading... | |
92 explicit Value(const char16* in_string); | 95 explicit Value(const char16* in_string); |
93 explicit Value(const string16& in_string); | 96 explicit Value(const string16& in_string); |
94 explicit Value(StringPiece in_string); | 97 explicit Value(StringPiece in_string); |
95 | 98 |
96 explicit Value(const std::vector<char>& in_blob); | 99 explicit Value(const std::vector<char>& in_blob); |
97 explicit Value(std::vector<char>&& in_blob); | 100 explicit Value(std::vector<char>&& in_blob); |
98 | 101 |
99 Value& operator=(const Value& that); | 102 Value& operator=(const Value& that); |
100 Value& operator=(Value&& that); | 103 Value& operator=(Value&& that); |
101 | 104 |
102 virtual ~Value(); | 105 ~Value(); |
103 | 106 |
104 // Returns the name for a given |type|. | 107 // Returns the name for a given |type|. |
105 static const char* GetTypeName(Type type); | 108 static const char* GetTypeName(Type type); |
106 | 109 |
107 // Returns the type of the value stored by the current Value object. | 110 // Returns the type of the value stored by the current Value object. |
108 // Each type will be implemented by only one subclass of Value, so it's | 111 // Each type will be implemented by only one subclass of Value, so it's |
109 // safe to use the Type to determine whether you can cast from | 112 // safe to use the Type to determine whether you can cast from |
110 // Value* to (Implementing Class)*. Also, a Value object never changes | 113 // Value* to (Implementing Class)*. Also, a Value object never changes |
111 // its type after construction. | 114 // its type after construction. |
112 Type GetType() const { return type_; } // DEPRECATED, use type(). | 115 Type GetType() const { return type_; } // DEPRECATED, use type(). |
(...skipping 16 matching lines...) Expand all Loading... | |
129 const std::string& GetString() const; | 132 const std::string& GetString() const; |
130 const std::vector<char>& GetBlob() const; | 133 const std::vector<char>& GetBlob() const; |
131 | 134 |
132 size_t GetSize() const; // DEPRECATED, use GetBlob().size() instead. | 135 size_t GetSize() const; // DEPRECATED, use GetBlob().size() instead. |
133 const char* GetBuffer() const; // DEPRECATED, use GetBlob().data() instead. | 136 const char* GetBuffer() const; // DEPRECATED, use GetBlob().data() instead. |
134 | 137 |
135 // These methods allow the convenient retrieval of the contents of the Value. | 138 // These methods allow the convenient retrieval of the contents of the Value. |
136 // If the current object can be converted into the given type, the value is | 139 // If the current object can be converted into the given type, the value is |
137 // returned through the |out_value| parameter and true is returned; | 140 // returned through the |out_value| parameter and true is returned; |
138 // otherwise, false is returned and |out_value| is unchanged. | 141 // otherwise, false is returned and |out_value| is unchanged. |
139 virtual bool GetAsBoolean(bool* out_value) const; | 142 bool GetAsBoolean(bool* out_value) const; |
140 virtual bool GetAsInteger(int* out_value) const; | 143 bool GetAsInteger(int* out_value) const; |
141 virtual bool GetAsDouble(double* out_value) const; | 144 bool GetAsDouble(double* out_value) const; |
142 virtual bool GetAsString(std::string* out_value) const; | 145 bool GetAsString(std::string* out_value) const; |
143 virtual bool GetAsString(string16* out_value) const; | 146 bool GetAsString(string16* out_value) const; |
144 virtual bool GetAsString(const StringValue** out_value) const; | 147 bool GetAsString(const StringValue** out_value) const; |
145 virtual bool GetAsString(StringPiece* out_value) const; | 148 bool GetAsString(StringPiece* out_value) const; |
146 virtual bool GetAsBinary(const BinaryValue** out_value) const; | 149 bool GetAsBinary(const BinaryValue** out_value) const; |
147 // ListValue::From is the equivalent for std::unique_ptr conversions. | 150 // ListValue::From is the equivalent for std::unique_ptr conversions. |
148 virtual bool GetAsList(ListValue** out_value); | 151 bool GetAsList(ListValue** out_value); |
149 virtual bool GetAsList(const ListValue** out_value) const; | 152 bool GetAsList(const ListValue** out_value) const; |
150 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. | 153 // DictionaryValue::From is the equivalent for std::unique_ptr conversions. |
151 virtual bool GetAsDictionary(DictionaryValue** out_value); | 154 bool GetAsDictionary(DictionaryValue** out_value); |
152 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; | 155 bool GetAsDictionary(const DictionaryValue** out_value) const; |
153 // Note: Do not add more types. See the file-level comment above for why. | 156 // Note: Do not add more types. See the file-level comment above for why. |
154 | 157 |
155 // This creates a deep copy of the entire Value tree, and returns a pointer | 158 // This creates a deep copy of the entire Value tree, and returns a pointer |
156 // to the copy. The caller gets ownership of the copy, of course. | 159 // to the copy. The caller gets ownership of the copy, of course. |
157 // Subclasses return their own type directly in their overrides; | 160 // Subclasses return their own type directly in their overrides; |
158 // this works because C++ supports covariant return types. | 161 // this works because C++ supports covariant return types. |
159 virtual Value* DeepCopy() const; | 162 Value* DeepCopy() const; |
160 // Preferred version of DeepCopy. TODO(estade): remove the above. | 163 // Preferred version of DeepCopy. TODO(estade): remove the above. |
161 std::unique_ptr<Value> CreateDeepCopy() const; | 164 std::unique_ptr<Value> CreateDeepCopy() const; |
162 | 165 |
163 // Compares if two Value objects have equal contents. | 166 // Compares if two Value objects have equal contents. |
164 virtual bool Equals(const Value* other) const; | 167 bool Equals(const Value* other) const; |
165 | 168 |
166 // Compares if two Value objects have equal contents. Can handle NULLs. | 169 // Compares if two Value objects have equal contents. Can handle NULLs. |
167 // NULLs are considered equal but different from Value::CreateNullValue(). | 170 // NULLs are considered equal but different from Value::CreateNullValue(). |
168 static bool Equals(const Value* a, const Value* b); | 171 static bool Equals(const Value* a, const Value* b); |
169 | 172 |
170 private: | 173 protected: |
171 void InternalCopyFundamentalValue(const Value& that); | 174 // TODO(crbug.com/646113): Make these private once DictionaryValue and |
172 void InternalCopyConstructFrom(const Value& that); | 175 // ListValue are properly inlined. |
173 void InternalMoveConstructFrom(Value&& that); | |
174 void InternalCopyAssignFrom(const Value& that); | |
175 void InternalMoveAssignFrom(Value&& that); | |
176 void InternalCleanup(); | |
177 | |
178 Type type_; | 176 Type type_; |
179 | 177 |
180 union { | 178 union { |
181 bool bool_value_; | 179 bool bool_value_; |
182 int int_value_; | 180 int int_value_; |
183 double double_value_; | 181 double double_value_; |
184 ManualConstructor<std::string> string_value_; | 182 ManualConstructor<std::string> string_value_; |
185 ManualConstructor<std::vector<char>> binary_value_; | 183 ManualConstructor<std::vector<char>> binary_value_; |
184 // For current gcc and clang sizeof(DictStorage) = 48, which would result | |
185 // in sizeof(Value) = 56 if DictStorage was stack allocated. Allocating it | |
186 // on the heap results in sizeof(Value) = 40 for all of gcc, clang and MSVC. | |
187 ManualConstructor<std::unique_ptr<DictStorage>> dict_ptr_; | |
188 ManualConstructor<ListStorage> list_; | |
186 }; | 189 }; |
190 | |
191 private: | |
192 void InternalCopyFundamentalValue(const Value& that); | |
193 void InternalCopyConstructFrom(const Value& that); | |
194 void InternalMoveConstructFrom(Value&& that); | |
195 void InternalCopyAssignFrom(const Value& that); | |
196 void InternalMoveAssignFrom(Value&& that); | |
197 void InternalCleanup(); | |
187 }; | 198 }; |
188 | 199 |
189 // DictionaryValue provides a key-value dictionary with (optional) "path" | 200 // DictionaryValue provides a key-value dictionary with (optional) "path" |
190 // parsing for recursive access; see the comment at the top of the file. Keys | 201 // parsing for recursive access; see the comment at the top of the file. Keys |
191 // are |std::string|s and should be UTF-8 encoded. | 202 // are |std::string|s and should be UTF-8 encoded. |
192 class BASE_EXPORT DictionaryValue : public Value { | 203 class BASE_EXPORT DictionaryValue : public Value { |
193 public: | 204 public: |
194 using Storage = std::map<std::string, std::unique_ptr<Value>>; | |
195 // Returns |value| if it is a dictionary, nullptr otherwise. | 205 // Returns |value| if it is a dictionary, nullptr otherwise. |
196 static std::unique_ptr<DictionaryValue> From(std::unique_ptr<Value> value); | 206 static std::unique_ptr<DictionaryValue> From(std::unique_ptr<Value> value); |
197 | 207 |
198 DictionaryValue(); | 208 DictionaryValue(); |
199 ~DictionaryValue() override; | |
jdoerrie
2017/02/15 15:29:09
Deleting this and the |DISALLOW_COPY_AND_ASSIGN| m
brettw
2017/02/15 21:28:29
Your reasoning sounds right to me.
| |
200 | |
201 // Overridden from Value: | |
202 bool GetAsDictionary(DictionaryValue** out_value) override; | |
203 bool GetAsDictionary(const DictionaryValue** out_value) const override; | |
204 | 209 |
205 // Returns true if the current dictionary has a value for the given key. | 210 // Returns true if the current dictionary has a value for the given key. |
206 bool HasKey(StringPiece key) const; | 211 bool HasKey(StringPiece key) const; |
207 | 212 |
208 // Returns the number of Values in this dictionary. | 213 // Returns the number of Values in this dictionary. |
209 size_t size() const { return dictionary_.size(); } | 214 size_t size() const { return (*dict_ptr_)->size(); } |
210 | 215 |
211 // Returns whether the dictionary is empty. | 216 // Returns whether the dictionary is empty. |
212 bool empty() const { return dictionary_.empty(); } | 217 bool empty() const { return (*dict_ptr_)->empty(); } |
213 | 218 |
214 // Clears any current contents of this dictionary. | 219 // Clears any current contents of this dictionary. |
215 void Clear(); | 220 void Clear(); |
216 | 221 |
217 // Sets the Value associated with the given path starting from this object. | 222 // Sets the Value associated with the given path starting from this object. |
218 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes | 223 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes |
219 // into the next DictionaryValue down. Obviously, "." can't be used | 224 // into the next DictionaryValue down. Obviously, "." can't be used |
220 // within a key, but there are no other restrictions on keys. | 225 // within a key, but there are no other restrictions on keys. |
221 // If the key at any step of the way doesn't exist, or exists but isn't | 226 // If the key at any step of the way doesn't exist, or exists but isn't |
222 // a DictionaryValue, a new DictionaryValue will be created and attached | 227 // a DictionaryValue, a new DictionaryValue will be created and attached |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 // Removes the Value with the specified path from this dictionary (or one | 307 // Removes the Value with the specified path from this dictionary (or one |
303 // of its child dictionaries, if the path is more than just a local key). | 308 // of its child dictionaries, if the path is more than just a local key). |
304 // If |out_value| is non-NULL, the removed Value will be passed out via | 309 // If |out_value| is non-NULL, the removed Value will be passed out via |
305 // |out_value|. If |out_value| is NULL, the removed value will be deleted. | 310 // |out_value|. If |out_value| is NULL, the removed value will be deleted. |
306 // This method returns true if |path| is a valid path; otherwise it will | 311 // This method returns true if |path| is a valid path; otherwise it will |
307 // return false and the DictionaryValue object will be unchanged. | 312 // return false and the DictionaryValue object will be unchanged. |
308 bool Remove(StringPiece path, std::unique_ptr<Value>* out_value); | 313 bool Remove(StringPiece path, std::unique_ptr<Value>* out_value); |
309 | 314 |
310 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs | 315 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs |
311 // to be used as paths. | 316 // to be used as paths. |
312 virtual bool RemoveWithoutPathExpansion(StringPiece key, | 317 bool RemoveWithoutPathExpansion(StringPiece key, |
313 std::unique_ptr<Value>* out_value); | 318 std::unique_ptr<Value>* out_value); |
314 | 319 |
315 // Removes a path, clearing out all dictionaries on |path| that remain empty | 320 // Removes a path, clearing out all dictionaries on |path| that remain empty |
316 // after removing the value at |path|. | 321 // after removing the value at |path|. |
317 bool RemovePath(StringPiece path, std::unique_ptr<Value>* out_value); | 322 bool RemovePath(StringPiece path, std::unique_ptr<Value>* out_value); |
318 | 323 |
319 // Makes a copy of |this| but doesn't include empty dictionaries and lists in | 324 // Makes a copy of |this| but doesn't include empty dictionaries and lists in |
320 // the copy. This never returns NULL, even if |this| itself is empty. | 325 // the copy. This never returns NULL, even if |this| itself is empty. |
321 std::unique_ptr<DictionaryValue> DeepCopyWithoutEmptyChildren() const; | 326 std::unique_ptr<DictionaryValue> DeepCopyWithoutEmptyChildren() const; |
322 | 327 |
323 // Merge |dictionary| into this dictionary. This is done recursively, i.e. any | 328 // Merge |dictionary| into this dictionary. This is done recursively, i.e. any |
324 // sub-dictionaries will be merged as well. In case of key collisions, the | 329 // sub-dictionaries will be merged as well. In case of key collisions, the |
325 // passed in dictionary takes precedence and data already present will be | 330 // passed in dictionary takes precedence and data already present will be |
326 // replaced. Values within |dictionary| are deep-copied, so |dictionary| may | 331 // replaced. Values within |dictionary| are deep-copied, so |dictionary| may |
327 // be freed any time after this call. | 332 // be freed any time after this call. |
328 void MergeDictionary(const DictionaryValue* dictionary); | 333 void MergeDictionary(const DictionaryValue* dictionary); |
329 | 334 |
330 // Swaps contents with the |other| dictionary. | 335 // Swaps contents with the |other| dictionary. |
331 virtual void Swap(DictionaryValue* other); | 336 void Swap(DictionaryValue* other); |
332 | 337 |
333 // This class provides an iterator over both keys and values in the | 338 // This class provides an iterator over both keys and values in the |
334 // dictionary. It can't be used to modify the dictionary. | 339 // dictionary. It can't be used to modify the dictionary. |
335 class BASE_EXPORT Iterator { | 340 class BASE_EXPORT Iterator { |
336 public: | 341 public: |
337 explicit Iterator(const DictionaryValue& target); | 342 explicit Iterator(const DictionaryValue& target); |
338 Iterator(const Iterator& other); | 343 Iterator(const Iterator& other); |
339 ~Iterator(); | 344 ~Iterator(); |
340 | 345 |
341 bool IsAtEnd() const { return it_ == target_.dictionary_.end(); } | 346 bool IsAtEnd() const { return it_ == (*target_.dict_ptr_)->end(); } |
342 void Advance() { ++it_; } | 347 void Advance() { ++it_; } |
343 | 348 |
344 const std::string& key() const { return it_->first; } | 349 const std::string& key() const { return it_->first; } |
345 const Value& value() const { return *it_->second; } | 350 const Value& value() const { return *it_->second; } |
346 | 351 |
347 private: | 352 private: |
348 const DictionaryValue& target_; | 353 const DictionaryValue& target_; |
349 Storage::const_iterator it_; | 354 DictStorage::const_iterator it_; |
350 }; | 355 }; |
351 | 356 |
352 // Overridden from Value: | 357 DictionaryValue* DeepCopy() const; |
353 DictionaryValue* DeepCopy() const override; | |
354 // Preferred version of DeepCopy. TODO(estade): remove the above. | 358 // Preferred version of DeepCopy. TODO(estade): remove the above. |
355 std::unique_ptr<DictionaryValue> CreateDeepCopy() const; | 359 std::unique_ptr<DictionaryValue> CreateDeepCopy() const; |
356 bool Equals(const Value* other) const override; | |
357 | |
358 private: | |
359 Storage dictionary_; | |
360 | |
361 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); | |
362 }; | 360 }; |
363 | 361 |
364 // This type of Value represents a list of other Value values. | 362 // This type of Value represents a list of other Value values. |
365 class BASE_EXPORT ListValue : public Value { | 363 class BASE_EXPORT ListValue : public Value { |
366 public: | 364 public: |
367 using Storage = std::vector<std::unique_ptr<Value>>; | 365 using const_iterator = ListStorage::const_iterator; |
368 using const_iterator = Storage::const_iterator; | 366 using iterator = ListStorage::iterator; |
369 using iterator = Storage::iterator; | |
370 | 367 |
371 // Returns |value| if it is a list, nullptr otherwise. | 368 // Returns |value| if it is a list, nullptr otherwise. |
372 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); | 369 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); |
373 | 370 |
374 ListValue(); | 371 ListValue(); |
375 ~ListValue() override; | |
jdoerrie
2017/02/15 15:29:09
Same here.
| |
376 | 372 |
377 // Clears the contents of this ListValue | 373 // Clears the contents of this ListValue |
378 void Clear(); | 374 void Clear(); |
379 | 375 |
380 // Returns the number of Values in this list. | 376 // Returns the number of Values in this list. |
381 size_t GetSize() const { return list_.size(); } | 377 size_t GetSize() const { return list_->size(); } |
382 | 378 |
383 // Returns whether the list is empty. | 379 // Returns whether the list is empty. |
384 bool empty() const { return list_.empty(); } | 380 bool empty() const { return list_->empty(); } |
385 | 381 |
386 // Sets the list item at the given index to be the Value specified by | 382 // Sets the list item at the given index to be the Value specified by |
387 // the value given. If the index beyond the current end of the list, null | 383 // the value given. If the index beyond the current end of the list, null |
388 // Values will be used to pad out the list. | 384 // Values will be used to pad out the list. |
389 // Returns true if successful, or false if the index was negative or | 385 // Returns true if successful, or false if the index was negative or |
390 // the value is a null pointer. | 386 // the value is a null pointer. |
391 bool Set(size_t index, Value* in_value); | 387 bool Set(size_t index, Value* in_value); |
392 // Preferred version of the above. TODO(estade): remove the above. | 388 // Preferred version of the above. TODO(estade): remove the above. |
393 bool Set(size_t index, std::unique_ptr<Value> in_value); | 389 bool Set(size_t index, std::unique_ptr<Value> in_value); |
394 | 390 |
(...skipping 20 matching lines...) Expand all Loading... | |
415 bool GetDictionary(size_t index, const DictionaryValue** out_value) const; | 411 bool GetDictionary(size_t index, const DictionaryValue** out_value) const; |
416 bool GetDictionary(size_t index, DictionaryValue** out_value); | 412 bool GetDictionary(size_t index, DictionaryValue** out_value); |
417 bool GetList(size_t index, const ListValue** out_value) const; | 413 bool GetList(size_t index, const ListValue** out_value) const; |
418 bool GetList(size_t index, ListValue** out_value); | 414 bool GetList(size_t index, ListValue** out_value); |
419 | 415 |
420 // Removes the Value with the specified index from this list. | 416 // Removes the Value with the specified index from this list. |
421 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be | 417 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be |
422 // passed out via |out_value|. If |out_value| is NULL, the removed value will | 418 // passed out via |out_value|. If |out_value| is NULL, the removed value will |
423 // be deleted. This method returns true if |index| is valid; otherwise | 419 // be deleted. This method returns true if |index| is valid; otherwise |
424 // it will return false and the ListValue object will be unchanged. | 420 // it will return false and the ListValue object will be unchanged. |
425 virtual bool Remove(size_t index, std::unique_ptr<Value>* out_value); | 421 bool Remove(size_t index, std::unique_ptr<Value>* out_value); |
426 | 422 |
427 // Removes the first instance of |value| found in the list, if any, and | 423 // Removes the first instance of |value| found in the list, if any, and |
428 // deletes it. |index| is the location where |value| was found. Returns false | 424 // deletes it. |index| is the location where |value| was found. Returns false |
429 // if not found. | 425 // if not found. |
430 bool Remove(const Value& value, size_t* index); | 426 bool Remove(const Value& value, size_t* index); |
431 | 427 |
432 // Removes the element at |iter|. If |out_value| is NULL, the value will be | 428 // Removes the element at |iter|. If |out_value| is NULL, the value will be |
433 // deleted, otherwise ownership of the value is passed back to the caller. | 429 // deleted, otherwise ownership of the value is passed back to the caller. |
434 // Returns an iterator pointing to the location of the element that | 430 // Returns an iterator pointing to the location of the element that |
435 // followed the erased element. | 431 // followed the erased element. |
(...skipping 22 matching lines...) Expand all Loading... | |
458 // Insert a Value at index. | 454 // Insert a Value at index. |
459 // Returns true if successful, or false if the index was out of range. | 455 // Returns true if successful, or false if the index was out of range. |
460 bool Insert(size_t index, std::unique_ptr<Value> in_value); | 456 bool Insert(size_t index, std::unique_ptr<Value> in_value); |
461 | 457 |
462 // Searches for the first instance of |value| in the list using the Equals | 458 // Searches for the first instance of |value| in the list using the Equals |
463 // method of the Value type. | 459 // method of the Value type. |
464 // Returns a const_iterator to the found item or to end() if none exists. | 460 // Returns a const_iterator to the found item or to end() if none exists. |
465 const_iterator Find(const Value& value) const; | 461 const_iterator Find(const Value& value) const; |
466 | 462 |
467 // Swaps contents with the |other| list. | 463 // Swaps contents with the |other| list. |
468 virtual void Swap(ListValue* other); | 464 void Swap(ListValue* other); |
469 | 465 |
470 // Iteration. | 466 // Iteration. |
471 iterator begin() { return list_.begin(); } | 467 iterator begin() { return list_->begin(); } |
472 iterator end() { return list_.end(); } | 468 iterator end() { return list_->end(); } |
473 | 469 |
474 const_iterator begin() const { return list_.begin(); } | 470 const_iterator begin() const { return list_->begin(); } |
475 const_iterator end() const { return list_.end(); } | 471 const_iterator end() const { return list_->end(); } |
476 | 472 |
477 // Overridden from Value: | 473 ListValue* DeepCopy() const; |
478 bool GetAsList(ListValue** out_value) override; | |
479 bool GetAsList(const ListValue** out_value) const override; | |
480 ListValue* DeepCopy() const override; | |
481 bool Equals(const Value* other) const override; | |
482 | |
483 // Preferred version of DeepCopy. TODO(estade): remove DeepCopy. | 474 // Preferred version of DeepCopy. TODO(estade): remove DeepCopy. |
484 std::unique_ptr<ListValue> CreateDeepCopy() const; | 475 std::unique_ptr<ListValue> CreateDeepCopy() const; |
485 | |
486 private: | |
487 Storage list_; | |
488 | |
489 DISALLOW_COPY_AND_ASSIGN(ListValue); | |
490 }; | 476 }; |
491 | 477 |
492 // This interface is implemented by classes that know how to serialize | 478 // This interface is implemented by classes that know how to serialize |
493 // Value objects. | 479 // Value objects. |
494 class BASE_EXPORT ValueSerializer { | 480 class BASE_EXPORT ValueSerializer { |
495 public: | 481 public: |
496 virtual ~ValueSerializer(); | 482 virtual ~ValueSerializer(); |
497 | 483 |
498 virtual bool Serialize(const Value& root) = 0; | 484 virtual bool Serialize(const Value& root) = 0; |
499 }; | 485 }; |
(...skipping 30 matching lines...) Expand all Loading... | |
530 return out << static_cast<const Value&>(value); | 516 return out << static_cast<const Value&>(value); |
531 } | 517 } |
532 | 518 |
533 // Stream operator so that enum class Types can be used in log statements. | 519 // Stream operator so that enum class Types can be used in log statements. |
534 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 520 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
535 const Value::Type& type); | 521 const Value::Type& type); |
536 | 522 |
537 } // namespace base | 523 } // namespace base |
538 | 524 |
539 #endif // BASE_VALUES_H_ | 525 #endif // BASE_VALUES_H_ |
OLD | NEW |