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

Side by Side Diff: base/values.h

Issue 2740143002: Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Fix Android Compilation Error Created 3 years, 9 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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 using BinaryValue = Value; 42 using BinaryValue = Value;
43 43
44 // The Value class is the base class for Values. A Value can be instantiated 44 // The Value class is the base class for Values. A Value can be instantiated
45 // via the Create*Value() factory methods, or by directly creating instances of 45 // via the Create*Value() factory methods, or by directly creating instances of
46 // the subclasses. 46 // the subclasses.
47 // 47 //
48 // See the file-level comment above for more information. 48 // See the file-level comment above for more information.
49 class BASE_EXPORT Value { 49 class BASE_EXPORT Value {
50 public: 50 public:
51 using DictStorage = std::map<std::string, std::unique_ptr<Value>>; 51 using DictStorage = std::map<std::string, std::unique_ptr<Value>>;
52 using ListStorage = std::vector<std::unique_ptr<Value>>; 52 using ListStorage = std::vector<Value>;
53 53
54 enum class Type { 54 enum class Type {
55 NONE = 0, 55 NONE = 0,
56 BOOLEAN, 56 BOOLEAN,
57 INTEGER, 57 INTEGER,
58 DOUBLE, 58 DOUBLE,
59 STRING, 59 STRING,
60 BINARY, 60 BINARY,
61 DICTIONARY, 61 DICTIONARY,
62 LIST 62 LIST
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); 366 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value);
367 367
368 ListValue(); 368 ListValue();
369 369
370 // Clears the contents of this ListValue 370 // Clears the contents of this ListValue
371 void Clear(); 371 void Clear();
372 372
373 // Returns the number of Values in this list. 373 // Returns the number of Values in this list.
374 size_t GetSize() const { return list_->size(); } 374 size_t GetSize() const { return list_->size(); }
375 375
376 // Returns the capacity of storage for Values in this list.
377 size_t capacity() const { return list_->capacity(); }
378
376 // Returns whether the list is empty. 379 // Returns whether the list is empty.
377 bool empty() const { return list_->empty(); } 380 bool empty() const { return list_->empty(); }
378 381
382 // Reserves storage for at least |n| values.
383 void Reserve(size_t n);
384
379 // Sets the list item at the given index to be the Value specified by 385 // Sets the list item at the given index to be the Value specified by
380 // the value given. If the index beyond the current end of the list, null 386 // the value given. If the index beyond the current end of the list, null
381 // Values will be used to pad out the list. 387 // Values will be used to pad out the list.
382 // Returns true if successful, or false if the index was negative or 388 // Returns true if successful, or false if the index was negative or
383 // the value is a null pointer. 389 // the value is a null pointer.
384 bool Set(size_t index, Value* in_value); 390 bool Set(size_t index, Value* in_value);
385 // Preferred version of the above. TODO(estade): remove the above. 391 // Preferred version of the above. TODO(estade): remove the above.
386 bool Set(size_t index, std::unique_ptr<Value> in_value); 392 bool Set(size_t index, std::unique_ptr<Value> in_value);
387 393
388 // Gets the Value at the given index. Modifies |out_value| (and returns true) 394 // Gets the Value at the given index. Modifies |out_value| (and returns true)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 return out << static_cast<const Value&>(value); 519 return out << static_cast<const Value&>(value);
514 } 520 }
515 521
516 // Stream operator so that enum class Types can be used in log statements. 522 // Stream operator so that enum class Types can be used in log statements.
517 BASE_EXPORT std::ostream& operator<<(std::ostream& out, 523 BASE_EXPORT std::ostream& operator<<(std::ostream& out,
518 const Value::Type& type); 524 const Value::Type& type);
519 525
520 } // namespace base 526 } // namespace base
521 527
522 #endif // BASE_VALUES_H_ 528 #endif // BASE_VALUES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698