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

Side by Side Diff: base/values.h

Issue 2816513002: Revert of Change base::Value::ListStorage to std::vector<base::Value> (Closed)
Patch Set: Created 3 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/trace_event/trace_event_memory_overhead.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.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class Value; 42 class 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 = base::flat_map<std::string, std::unique_ptr<Value>>; 51 using DictStorage = base::flat_map<std::string, std::unique_ptr<Value>>;
52 using ListStorage = std::vector<Value>; 52 using ListStorage = std::vector<std::unique_ptr<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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value); 383 static std::unique_ptr<ListValue> From(std::unique_ptr<Value> value);
384 384
385 ListValue(); 385 ListValue();
386 386
387 // Clears the contents of this ListValue 387 // Clears the contents of this ListValue
388 void Clear(); 388 void Clear();
389 389
390 // Returns the number of Values in this list. 390 // Returns the number of Values in this list.
391 size_t GetSize() const { return list_->size(); } 391 size_t GetSize() const { return list_->size(); }
392 392
393 // Returns the capacity of storage for Values in this list.
394 size_t capacity() const { return list_->capacity(); }
395
396 // Returns whether the list is empty. 393 // Returns whether the list is empty.
397 bool empty() const { return list_->empty(); } 394 bool empty() const { return list_->empty(); }
398 395
399 // Reserves storage for at least |n| values.
400 void Reserve(size_t n);
401
402 // Sets the list item at the given index to be the Value specified by 396 // Sets the list item at the given index to be the Value specified by
403 // the value given. If the index beyond the current end of the list, null 397 // the value given. If the index beyond the current end of the list, null
404 // Values will be used to pad out the list. 398 // Values will be used to pad out the list.
405 // Returns true if successful, or false if the index was negative or 399 // Returns true if successful, or false if the index was negative or
406 // the value is a null pointer. 400 // the value is a null pointer.
407 bool Set(size_t index, Value* in_value); 401 bool Set(size_t index, Value* in_value);
408 // Preferred version of the above. TODO(estade): remove the above. 402 // Preferred version of the above. TODO(estade): remove the above.
409 bool Set(size_t index, std::unique_ptr<Value> in_value); 403 bool Set(size_t index, std::unique_ptr<Value> in_value);
410 404
411 // Gets the Value at the given index. Modifies |out_value| (and returns true) 405 // Gets the Value at the given index. Modifies |out_value| (and returns true)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 return out << static_cast<const Value&>(value); 532 return out << static_cast<const Value&>(value);
539 } 533 }
540 534
541 // Stream operator so that enum class Types can be used in log statements. 535 // Stream operator so that enum class Types can be used in log statements.
542 BASE_EXPORT std::ostream& operator<<(std::ostream& out, 536 BASE_EXPORT std::ostream& operator<<(std::ostream& out,
543 const Value::Type& type); 537 const Value::Type& type);
544 538
545 } // namespace base 539 } // namespace base
546 540
547 #endif // BASE_VALUES_H_ 541 #endif // BASE_VALUES_H_
OLDNEW
« no previous file with comments | « base/trace_event/trace_event_memory_overhead.cc ('k') | base/values.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698