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

Side by Side Diff: base/values.h

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/tracked_objects_unittest.cc ('k') | 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.
11 // 11 //
12 // IN PARTICULAR this means that there is no support for int64_t or unsigned 12 // IN PARTICULAR this means that there is no support for int64_t or unsigned
13 // numbers. Writing JSON with such types would violate the spec. If you need 13 // numbers. Writing JSON with such types would violate the spec. If you need
14 // something like this, either use a double or make a string value containing 14 // something like this, either use a double or make a string value containing
15 // the number you want. 15 // the number you want.
16 16
17 #ifndef BASE_VALUES_H_ 17 #ifndef BASE_VALUES_H_
18 #define BASE_VALUES_H_ 18 #define BASE_VALUES_H_
19 19
20 #include <stddef.h> 20 #include <stddef.h>
21 #include <stdint.h> 21 #include <stdint.h>
22 22
23 #include <iosfwd> 23 #include <iosfwd>
24 #include <map> 24 #include <map>
25 #include <memory>
25 #include <string> 26 #include <string>
26 #include <utility> 27 #include <utility>
27 #include <vector> 28 #include <vector>
28 29
29 #include "base/base_export.h" 30 #include "base/base_export.h"
30 #include "base/compiler_specific.h" 31 #include "base/compiler_specific.h"
31 #include "base/macros.h" 32 #include "base/macros.h"
32 #include "base/memory/scoped_ptr.h"
33 #include "base/strings/string16.h" 33 #include "base/strings/string16.h"
34 #include "base/strings/string_piece.h" 34 #include "base/strings/string_piece.h"
35 35
36 namespace base { 36 namespace base {
37 37
38 class BinaryValue; 38 class BinaryValue;
39 class DictionaryValue; 39 class DictionaryValue;
40 class FundamentalValue; 40 class FundamentalValue;
41 class ListValue; 41 class ListValue;
42 class StringValue; 42 class StringValue;
(...skipping 16 matching lines...) Expand all
59 TYPE_DOUBLE, 59 TYPE_DOUBLE,
60 TYPE_STRING, 60 TYPE_STRING,
61 TYPE_BINARY, 61 TYPE_BINARY,
62 TYPE_DICTIONARY, 62 TYPE_DICTIONARY,
63 TYPE_LIST 63 TYPE_LIST
64 // Note: Do not add more types. See the file-level comment above for why. 64 // Note: Do not add more types. See the file-level comment above for why.
65 }; 65 };
66 66
67 virtual ~Value(); 67 virtual ~Value();
68 68
69 static scoped_ptr<Value> CreateNullValue(); 69 static std::unique_ptr<Value> CreateNullValue();
70 70
71 // Returns the type of the value stored by the current Value object. 71 // Returns the type of the value stored by the current Value object.
72 // Each type will be implemented by only one subclass of Value, so it's 72 // Each type will be implemented by only one subclass of Value, so it's
73 // safe to use the Type to determine whether you can cast from 73 // safe to use the Type to determine whether you can cast from
74 // Value* to (Implementing Class)*. Also, a Value object never changes 74 // Value* to (Implementing Class)*. Also, a Value object never changes
75 // its type after construction. 75 // its type after construction.
76 Type GetType() const { return type_; } 76 Type GetType() const { return type_; }
77 77
78 // Returns true if the current object represents a given type. 78 // Returns true if the current object represents a given type.
79 bool IsType(Type type) const { return type == type_; } 79 bool IsType(Type type) const { return type == type_; }
(...skipping 15 matching lines...) Expand all
95 virtual bool GetAsDictionary(const DictionaryValue** out_value) const; 95 virtual bool GetAsDictionary(const DictionaryValue** out_value) const;
96 // Note: Do not add more types. See the file-level comment above for why. 96 // Note: Do not add more types. See the file-level comment above for why.
97 97
98 // This creates a deep copy of the entire Value tree, and returns a pointer 98 // This creates a deep copy of the entire Value tree, and returns a pointer
99 // to the copy. The caller gets ownership of the copy, of course. 99 // to the copy. The caller gets ownership of the copy, of course.
100 // 100 //
101 // Subclasses return their own type directly in their overrides; 101 // Subclasses return their own type directly in their overrides;
102 // this works because C++ supports covariant return types. 102 // this works because C++ supports covariant return types.
103 virtual Value* DeepCopy() const; 103 virtual Value* DeepCopy() const;
104 // Preferred version of DeepCopy. TODO(estade): remove the above. 104 // Preferred version of DeepCopy. TODO(estade): remove the above.
105 scoped_ptr<Value> CreateDeepCopy() const; 105 std::unique_ptr<Value> CreateDeepCopy() const;
106 106
107 // Compares if two Value objects have equal contents. 107 // Compares if two Value objects have equal contents.
108 virtual bool Equals(const Value* other) const; 108 virtual bool Equals(const Value* other) const;
109 109
110 // Compares if two Value objects have equal contents. Can handle NULLs. 110 // Compares if two Value objects have equal contents. Can handle NULLs.
111 // NULLs are considered equal but different from Value::CreateNullValue(). 111 // NULLs are considered equal but different from Value::CreateNullValue().
112 static bool Equals(const Value* a, const Value* b); 112 static bool Equals(const Value* a, const Value* b);
113 113
114 protected: 114 protected:
115 // These aren't safe for end-users, but they are useful for subclasses. 115 // These aren't safe for end-users, but they are useful for subclasses.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 std::string value_; 171 std::string value_;
172 }; 172 };
173 173
174 class BASE_EXPORT BinaryValue: public Value { 174 class BASE_EXPORT BinaryValue: public Value {
175 public: 175 public:
176 // Creates a BinaryValue with a null buffer and size of 0. 176 // Creates a BinaryValue with a null buffer and size of 0.
177 BinaryValue(); 177 BinaryValue();
178 178
179 // Creates a BinaryValue, taking ownership of the bytes pointed to by 179 // Creates a BinaryValue, taking ownership of the bytes pointed to by
180 // |buffer|. 180 // |buffer|.
181 BinaryValue(scoped_ptr<char[]> buffer, size_t size); 181 BinaryValue(std::unique_ptr<char[]> buffer, size_t size);
182 182
183 ~BinaryValue() override; 183 ~BinaryValue() override;
184 184
185 // For situations where you want to keep ownership of your buffer, this 185 // For situations where you want to keep ownership of your buffer, this
186 // factory method creates a new BinaryValue by copying the contents of the 186 // factory method creates a new BinaryValue by copying the contents of the
187 // buffer that's passed in. 187 // buffer that's passed in.
188 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size); 188 static BinaryValue* CreateWithCopiedBuffer(const char* buffer, size_t size);
189 189
190 size_t GetSize() const { return size_; } 190 size_t GetSize() const { return size_; }
191 191
192 // May return NULL. 192 // May return NULL.
193 char* GetBuffer() { return buffer_.get(); } 193 char* GetBuffer() { return buffer_.get(); }
194 const char* GetBuffer() const { return buffer_.get(); } 194 const char* GetBuffer() const { return buffer_.get(); }
195 195
196 // Overridden from Value: 196 // Overridden from Value:
197 bool GetAsBinary(const BinaryValue** out_value) const override; 197 bool GetAsBinary(const BinaryValue** out_value) const override;
198 BinaryValue* DeepCopy() const override; 198 BinaryValue* DeepCopy() const override;
199 bool Equals(const Value* other) const override; 199 bool Equals(const Value* other) const override;
200 200
201 private: 201 private:
202 scoped_ptr<char[]> buffer_; 202 std::unique_ptr<char[]> buffer_;
203 size_t size_; 203 size_t size_;
204 204
205 DISALLOW_COPY_AND_ASSIGN(BinaryValue); 205 DISALLOW_COPY_AND_ASSIGN(BinaryValue);
206 }; 206 };
207 207
208 // DictionaryValue provides a key-value dictionary with (optional) "path" 208 // DictionaryValue provides a key-value dictionary with (optional) "path"
209 // parsing for recursive access; see the comment at the top of the file. Keys 209 // parsing for recursive access; see the comment at the top of the file. Keys
210 // are |std::string|s and should be UTF-8 encoded. 210 // are |std::string|s and should be UTF-8 encoded.
211 class BASE_EXPORT DictionaryValue : public Value { 211 class BASE_EXPORT DictionaryValue : public Value {
212 public: 212 public:
213 // Returns |value| if it is a dictionary, nullptr otherwise. 213 // Returns |value| if it is a dictionary, nullptr otherwise.
214 static scoped_ptr<DictionaryValue> From(scoped_ptr<Value> value); 214 static std::unique_ptr<DictionaryValue> From(std::unique_ptr<Value> value);
215 215
216 DictionaryValue(); 216 DictionaryValue();
217 ~DictionaryValue() override; 217 ~DictionaryValue() override;
218 218
219 // Overridden from Value: 219 // Overridden from Value:
220 bool GetAsDictionary(DictionaryValue** out_value) override; 220 bool GetAsDictionary(DictionaryValue** out_value) override;
221 bool GetAsDictionary(const DictionaryValue** out_value) const override; 221 bool GetAsDictionary(const DictionaryValue** out_value) const override;
222 222
223 // Returns true if the current dictionary has a value for the given key. 223 // Returns true if the current dictionary has a value for the given key.
224 bool HasKey(const std::string& key) const; 224 bool HasKey(const std::string& key) const;
225 225
226 // Returns the number of Values in this dictionary. 226 // Returns the number of Values in this dictionary.
227 size_t size() const { return dictionary_.size(); } 227 size_t size() const { return dictionary_.size(); }
228 228
229 // Returns whether the dictionary is empty. 229 // Returns whether the dictionary is empty.
230 bool empty() const { return dictionary_.empty(); } 230 bool empty() const { return dictionary_.empty(); }
231 231
232 // Clears any current contents of this dictionary. 232 // Clears any current contents of this dictionary.
233 void Clear(); 233 void Clear();
234 234
235 // Sets the Value associated with the given path starting from this object. 235 // Sets the Value associated with the given path starting from this object.
236 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes 236 // A path has the form "<key>" or "<key>.<key>.[...]", where "." indexes
237 // into the next DictionaryValue down. Obviously, "." can't be used 237 // into the next DictionaryValue down. Obviously, "." can't be used
238 // within a key, but there are no other restrictions on keys. 238 // within a key, but there are no other restrictions on keys.
239 // If the key at any step of the way doesn't exist, or exists but isn't 239 // If the key at any step of the way doesn't exist, or exists but isn't
240 // a DictionaryValue, a new DictionaryValue will be created and attached 240 // a DictionaryValue, a new DictionaryValue will be created and attached
241 // to the path in that location. |in_value| must be non-null. 241 // to the path in that location. |in_value| must be non-null.
242 void Set(const std::string& path, scoped_ptr<Value> in_value); 242 void Set(const std::string& path, std::unique_ptr<Value> in_value);
243 // Deprecated version of the above. TODO(estade): remove. 243 // Deprecated version of the above. TODO(estade): remove.
244 void Set(const std::string& path, Value* in_value); 244 void Set(const std::string& path, Value* in_value);
245 245
246 // Convenience forms of Set(). These methods will replace any existing 246 // Convenience forms of Set(). These methods will replace any existing
247 // value at that path, even if it has a different type. 247 // value at that path, even if it has a different type.
248 void SetBoolean(const std::string& path, bool in_value); 248 void SetBoolean(const std::string& path, bool in_value);
249 void SetInteger(const std::string& path, int in_value); 249 void SetInteger(const std::string& path, int in_value);
250 void SetDouble(const std::string& path, double in_value); 250 void SetDouble(const std::string& path, double in_value);
251 void SetString(const std::string& path, const std::string& in_value); 251 void SetString(const std::string& path, const std::string& in_value);
252 void SetString(const std::string& path, const string16& in_value); 252 void SetString(const std::string& path, const string16& in_value);
253 253
254 // Like Set(), but without special treatment of '.'. This allows e.g. URLs to 254 // Like Set(), but without special treatment of '.'. This allows e.g. URLs to
255 // be used as paths. 255 // be used as paths.
256 void SetWithoutPathExpansion(const std::string& key, 256 void SetWithoutPathExpansion(const std::string& key,
257 scoped_ptr<Value> in_value); 257 std::unique_ptr<Value> in_value);
258 // Deprecated version of the above. TODO(estade): remove. 258 // Deprecated version of the above. TODO(estade): remove.
259 void SetWithoutPathExpansion(const std::string& key, Value* in_value); 259 void SetWithoutPathExpansion(const std::string& key, Value* in_value);
260 260
261 // Convenience forms of SetWithoutPathExpansion(). 261 // Convenience forms of SetWithoutPathExpansion().
262 void SetBooleanWithoutPathExpansion(const std::string& path, bool in_value); 262 void SetBooleanWithoutPathExpansion(const std::string& path, bool in_value);
263 void SetIntegerWithoutPathExpansion(const std::string& path, int in_value); 263 void SetIntegerWithoutPathExpansion(const std::string& path, int in_value);
264 void SetDoubleWithoutPathExpansion(const std::string& path, double in_value); 264 void SetDoubleWithoutPathExpansion(const std::string& path, double in_value);
265 void SetStringWithoutPathExpansion(const std::string& path, 265 void SetStringWithoutPathExpansion(const std::string& path,
266 const std::string& in_value); 266 const std::string& in_value);
267 void SetStringWithoutPathExpansion(const std::string& path, 267 void SetStringWithoutPathExpansion(const std::string& path,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const ListValue** out_value) const; 322 const ListValue** out_value) const;
323 bool GetListWithoutPathExpansion(const std::string& key, 323 bool GetListWithoutPathExpansion(const std::string& key,
324 ListValue** out_value); 324 ListValue** out_value);
325 325
326 // Removes the Value with the specified path from this dictionary (or one 326 // Removes the Value with the specified path from this dictionary (or one
327 // of its child dictionaries, if the path is more than just a local key). 327 // of its child dictionaries, if the path is more than just a local key).
328 // If |out_value| is non-NULL, the removed Value will be passed out via 328 // If |out_value| is non-NULL, the removed Value will be passed out via
329 // |out_value|. If |out_value| is NULL, the removed value will be deleted. 329 // |out_value|. If |out_value| is NULL, the removed value will be deleted.
330 // This method returns true if |path| is a valid path; otherwise it will 330 // This method returns true if |path| is a valid path; otherwise it will
331 // return false and the DictionaryValue object will be unchanged. 331 // return false and the DictionaryValue object will be unchanged.
332 virtual bool Remove(const std::string& path, scoped_ptr<Value>* out_value); 332 virtual bool Remove(const std::string& path,
333 std::unique_ptr<Value>* out_value);
333 334
334 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs 335 // Like Remove(), but without special treatment of '.'. This allows e.g. URLs
335 // to be used as paths. 336 // to be used as paths.
336 virtual bool RemoveWithoutPathExpansion(const std::string& key, 337 virtual bool RemoveWithoutPathExpansion(const std::string& key,
337 scoped_ptr<Value>* out_value); 338 std::unique_ptr<Value>* out_value);
338 339
339 // Removes a path, clearing out all dictionaries on |path| that remain empty 340 // Removes a path, clearing out all dictionaries on |path| that remain empty
340 // after removing the value at |path|. 341 // after removing the value at |path|.
341 virtual bool RemovePath(const std::string& path, 342 virtual bool RemovePath(const std::string& path,
342 scoped_ptr<Value>* out_value); 343 std::unique_ptr<Value>* out_value);
343 344
344 // Makes a copy of |this| but doesn't include empty dictionaries and lists in 345 // Makes a copy of |this| but doesn't include empty dictionaries and lists in
345 // the copy. This never returns NULL, even if |this| itself is empty. 346 // the copy. This never returns NULL, even if |this| itself is empty.
346 scoped_ptr<DictionaryValue> DeepCopyWithoutEmptyChildren() const; 347 std::unique_ptr<DictionaryValue> DeepCopyWithoutEmptyChildren() const;
347 348
348 // Merge |dictionary| into this dictionary. This is done recursively, i.e. any 349 // Merge |dictionary| into this dictionary. This is done recursively, i.e. any
349 // sub-dictionaries will be merged as well. In case of key collisions, the 350 // sub-dictionaries will be merged as well. In case of key collisions, the
350 // passed in dictionary takes precedence and data already present will be 351 // passed in dictionary takes precedence and data already present will be
351 // replaced. Values within |dictionary| are deep-copied, so |dictionary| may 352 // replaced. Values within |dictionary| are deep-copied, so |dictionary| may
352 // be freed any time after this call. 353 // be freed any time after this call.
353 void MergeDictionary(const DictionaryValue* dictionary); 354 void MergeDictionary(const DictionaryValue* dictionary);
354 355
355 // Swaps contents with the |other| dictionary. 356 // Swaps contents with the |other| dictionary.
356 virtual void Swap(DictionaryValue* other); 357 virtual void Swap(DictionaryValue* other);
(...skipping 13 matching lines...) Expand all
370 const Value& value() const { return *it_->second; } 371 const Value& value() const { return *it_->second; }
371 372
372 private: 373 private:
373 const DictionaryValue& target_; 374 const DictionaryValue& target_;
374 ValueMap::const_iterator it_; 375 ValueMap::const_iterator it_;
375 }; 376 };
376 377
377 // Overridden from Value: 378 // Overridden from Value:
378 DictionaryValue* DeepCopy() const override; 379 DictionaryValue* DeepCopy() const override;
379 // Preferred version of DeepCopy. TODO(estade): remove the above. 380 // Preferred version of DeepCopy. TODO(estade): remove the above.
380 scoped_ptr<DictionaryValue> CreateDeepCopy() const; 381 std::unique_ptr<DictionaryValue> CreateDeepCopy() const;
381 bool Equals(const Value* other) const override; 382 bool Equals(const Value* other) const override;
382 383
383 private: 384 private:
384 ValueMap dictionary_; 385 ValueMap dictionary_;
385 386
386 DISALLOW_COPY_AND_ASSIGN(DictionaryValue); 387 DISALLOW_COPY_AND_ASSIGN(DictionaryValue);
387 }; 388 };
388 389
389 // This type of Value represents a list of other Value values. 390 // This type of Value represents a list of other Value values.
390 class BASE_EXPORT ListValue : public Value { 391 class BASE_EXPORT ListValue : public Value {
391 public: 392 public:
392 typedef ValueVector::iterator iterator; 393 typedef ValueVector::iterator iterator;
393 typedef ValueVector::const_iterator const_iterator; 394 typedef ValueVector::const_iterator const_iterator;
394 395
395 // Returns |value| if it is a list, nullptr otherwise. 396 // Returns |value| if it is a list, nullptr otherwise.
396 static scoped_ptr<ListValue> From(scoped_ptr<Value> value); 397 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value);
397 398
398 ListValue(); 399 ListValue();
399 ~ListValue() override; 400 ~ListValue() override;
400 401
401 // Clears the contents of this ListValue 402 // Clears the contents of this ListValue
402 void Clear(); 403 void Clear();
403 404
404 // Returns the number of Values in this list. 405 // Returns the number of Values in this list.
405 size_t GetSize() const { return list_.size(); } 406 size_t GetSize() const { return list_.size(); }
406 407
407 // Returns whether the list is empty. 408 // Returns whether the list is empty.
408 bool empty() const { return list_.empty(); } 409 bool empty() const { return list_.empty(); }
409 410
410 // Sets the list item at the given index to be the Value specified by 411 // Sets the list item at the given index to be the Value specified by
411 // the value given. If the index beyond the current end of the list, null 412 // the value given. If the index beyond the current end of the list, null
412 // Values will be used to pad out the list. 413 // Values will be used to pad out the list.
413 // Returns true if successful, or false if the index was negative or 414 // Returns true if successful, or false if the index was negative or
414 // the value is a null pointer. 415 // the value is a null pointer.
415 bool Set(size_t index, Value* in_value); 416 bool Set(size_t index, Value* in_value);
416 // Preferred version of the above. TODO(estade): remove the above. 417 // Preferred version of the above. TODO(estade): remove the above.
417 bool Set(size_t index, scoped_ptr<Value> in_value); 418 bool Set(size_t index, std::unique_ptr<Value> in_value);
418 419
419 // Gets the Value at the given index. Modifies |out_value| (and returns true) 420 // Gets the Value at the given index. Modifies |out_value| (and returns true)
420 // only if the index falls within the current list range. 421 // only if the index falls within the current list range.
421 // Note that the list always owns the Value passed out via |out_value|. 422 // Note that the list always owns the Value passed out via |out_value|.
422 // |out_value| is optional and will only be set if non-NULL. 423 // |out_value| is optional and will only be set if non-NULL.
423 bool Get(size_t index, const Value** out_value) const; 424 bool Get(size_t index, const Value** out_value) const;
424 bool Get(size_t index, Value** out_value); 425 bool Get(size_t index, Value** out_value);
425 426
426 // Convenience forms of Get(). Modifies |out_value| (and returns true) 427 // Convenience forms of Get(). Modifies |out_value| (and returns true)
427 // only if the index is valid and the Value at that index can be returned 428 // only if the index is valid and the Value at that index can be returned
(...skipping 11 matching lines...) Expand all
439 bool GetDictionary(size_t index, const DictionaryValue** out_value) const; 440 bool GetDictionary(size_t index, const DictionaryValue** out_value) const;
440 bool GetDictionary(size_t index, DictionaryValue** out_value); 441 bool GetDictionary(size_t index, DictionaryValue** out_value);
441 bool GetList(size_t index, const ListValue** out_value) const; 442 bool GetList(size_t index, const ListValue** out_value) const;
442 bool GetList(size_t index, ListValue** out_value); 443 bool GetList(size_t index, ListValue** out_value);
443 444
444 // Removes the Value with the specified index from this list. 445 // Removes the Value with the specified index from this list.
445 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be 446 // If |out_value| is non-NULL, the removed Value AND ITS OWNERSHIP will be
446 // passed out via |out_value|. If |out_value| is NULL, the removed value will 447 // passed out via |out_value|. If |out_value| is NULL, the removed value will
447 // be deleted. This method returns true if |index| is valid; otherwise 448 // be deleted. This method returns true if |index| is valid; otherwise
448 // it will return false and the ListValue object will be unchanged. 449 // it will return false and the ListValue object will be unchanged.
449 virtual bool Remove(size_t index, scoped_ptr<Value>* out_value); 450 virtual bool Remove(size_t index, std::unique_ptr<Value>* out_value);
450 451
451 // Removes the first instance of |value| found in the list, if any, and 452 // Removes the first instance of |value| found in the list, if any, and
452 // deletes it. |index| is the location where |value| was found. Returns false 453 // deletes it. |index| is the location where |value| was found. Returns false
453 // if not found. 454 // if not found.
454 bool Remove(const Value& value, size_t* index); 455 bool Remove(const Value& value, size_t* index);
455 456
456 // Removes the element at |iter|. If |out_value| is NULL, the value will be 457 // Removes the element at |iter|. If |out_value| is NULL, the value will be
457 // deleted, otherwise ownership of the value is passed back to the caller. 458 // deleted, otherwise ownership of the value is passed back to the caller.
458 // Returns an iterator pointing to the location of the element that 459 // Returns an iterator pointing to the location of the element that
459 // followed the erased element. 460 // followed the erased element.
460 iterator Erase(iterator iter, scoped_ptr<Value>* out_value); 461 iterator Erase(iterator iter, std::unique_ptr<Value>* out_value);
461 462
462 // Appends a Value to the end of the list. 463 // Appends a Value to the end of the list.
463 void Append(scoped_ptr<Value> in_value); 464 void Append(std::unique_ptr<Value> in_value);
464 // Deprecated version of the above. TODO(estade): remove. 465 // Deprecated version of the above. TODO(estade): remove.
465 void Append(Value* in_value); 466 void Append(Value* in_value);
466 467
467 // Convenience forms of Append. 468 // Convenience forms of Append.
468 void AppendBoolean(bool in_value); 469 void AppendBoolean(bool in_value);
469 void AppendInteger(int in_value); 470 void AppendInteger(int in_value);
470 void AppendDouble(double in_value); 471 void AppendDouble(double in_value);
471 void AppendString(const std::string& in_value); 472 void AppendString(const std::string& in_value);
472 void AppendString(const string16& in_value); 473 void AppendString(const string16& in_value);
473 void AppendStrings(const std::vector<std::string>& in_values); 474 void AppendStrings(const std::vector<std::string>& in_values);
(...skipping 23 matching lines...) Expand all
497 const_iterator begin() const { return list_.begin(); } 498 const_iterator begin() const { return list_.begin(); }
498 const_iterator end() const { return list_.end(); } 499 const_iterator end() const { return list_.end(); }
499 500
500 // Overridden from Value: 501 // Overridden from Value:
501 bool GetAsList(ListValue** out_value) override; 502 bool GetAsList(ListValue** out_value) override;
502 bool GetAsList(const ListValue** out_value) const override; 503 bool GetAsList(const ListValue** out_value) const override;
503 ListValue* DeepCopy() const override; 504 ListValue* DeepCopy() const override;
504 bool Equals(const Value* other) const override; 505 bool Equals(const Value* other) const override;
505 506
506 // Preferred version of DeepCopy. TODO(estade): remove DeepCopy. 507 // Preferred version of DeepCopy. TODO(estade): remove DeepCopy.
507 scoped_ptr<ListValue> CreateDeepCopy() const; 508 std::unique_ptr<ListValue> CreateDeepCopy() const;
508 509
509 private: 510 private:
510 ValueVector list_; 511 ValueVector list_;
511 512
512 DISALLOW_COPY_AND_ASSIGN(ListValue); 513 DISALLOW_COPY_AND_ASSIGN(ListValue);
513 }; 514 };
514 515
515 // This interface is implemented by classes that know how to serialize 516 // This interface is implemented by classes that know how to serialize
516 // Value objects. 517 // Value objects.
517 class BASE_EXPORT ValueSerializer { 518 class BASE_EXPORT ValueSerializer {
518 public: 519 public:
519 virtual ~ValueSerializer(); 520 virtual ~ValueSerializer();
520 521
521 virtual bool Serialize(const Value& root) = 0; 522 virtual bool Serialize(const Value& root) = 0;
522 }; 523 };
523 524
524 // This interface is implemented by classes that know how to deserialize Value 525 // This interface is implemented by classes that know how to deserialize Value
525 // objects. 526 // objects.
526 class BASE_EXPORT ValueDeserializer { 527 class BASE_EXPORT ValueDeserializer {
527 public: 528 public:
528 virtual ~ValueDeserializer(); 529 virtual ~ValueDeserializer();
529 530
530 // This method deserializes the subclass-specific format into a Value object. 531 // This method deserializes the subclass-specific format into a Value object.
531 // If the return value is non-NULL, the caller takes ownership of returned 532 // If the return value is non-NULL, the caller takes ownership of returned
532 // Value. If the return value is NULL, and if error_code is non-NULL, 533 // Value. If the return value is NULL, and if error_code is non-NULL,
533 // error_code will be set with the underlying error. 534 // error_code will be set with the underlying error.
534 // If |error_message| is non-null, it will be filled in with a formatted 535 // If |error_message| is non-null, it will be filled in with a formatted
535 // error message including the location of the error if appropriate. 536 // error message including the location of the error if appropriate.
536 virtual scoped_ptr<Value> Deserialize(int* error_code, 537 virtual std::unique_ptr<Value> Deserialize(int* error_code,
537 std::string* error_str) = 0; 538 std::string* error_str) = 0;
538 }; 539 };
539 540
540 // Stream operator so Values can be used in assertion statements. In order that 541 // Stream operator so Values can be used in assertion statements. In order that
541 // gtest uses this operator to print readable output on test failures, we must 542 // gtest uses this operator to print readable output on test failures, we must
542 // override each specific type. Otherwise, the default template implementation 543 // override each specific type. Otherwise, the default template implementation
543 // is preferred over an upcast. 544 // is preferred over an upcast.
544 BASE_EXPORT std::ostream& operator<<(std::ostream& out, const Value& value); 545 BASE_EXPORT std::ostream& operator<<(std::ostream& out, const Value& value);
545 546
546 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, 547 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out,
547 const FundamentalValue& value) { 548 const FundamentalValue& value) {
(...skipping 11 matching lines...) Expand all
559 } 560 }
560 561
561 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out, 562 BASE_EXPORT inline std::ostream& operator<<(std::ostream& out,
562 const ListValue& value) { 563 const ListValue& value) {
563 return out << static_cast<const Value&>(value); 564 return out << static_cast<const Value&>(value);
564 } 565 }
565 566
566 } // namespace base 567 } // namespace base
567 568
568 #endif // BASE_VALUES_H_ 569 #endif // BASE_VALUES_H_
OLDNEW
« no previous file with comments | « base/tracked_objects_unittest.cc ('k') | base/values.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698