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 11 matching lines...) Expand all Loading... |
22 | 22 |
23 #include <iosfwd> | 23 #include <iosfwd> |
24 #include <map> | 24 #include <map> |
25 #include <memory> | 25 #include <memory> |
26 #include <string> | 26 #include <string> |
27 #include <utility> | 27 #include <utility> |
28 #include <vector> | 28 #include <vector> |
29 | 29 |
30 #include "base/base_export.h" | 30 #include "base/base_export.h" |
31 #include "base/compiler_specific.h" | 31 #include "base/compiler_specific.h" |
32 #include "base/containers/flat_map.h" | |
33 #include "base/macros.h" | 32 #include "base/macros.h" |
34 #include "base/memory/manual_constructor.h" | 33 #include "base/memory/manual_constructor.h" |
35 #include "base/strings/string16.h" | 34 #include "base/strings/string16.h" |
36 #include "base/strings/string_piece.h" | 35 #include "base/strings/string_piece.h" |
37 | 36 |
38 namespace base { | 37 namespace base { |
39 | 38 |
40 class DictionaryValue; | 39 class DictionaryValue; |
41 class ListValue; | 40 class ListValue; |
42 class Value; | 41 class Value; |
43 using BinaryValue = Value; | 42 using BinaryValue = Value; |
44 | 43 |
45 // 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 |
46 // 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 |
47 // the subclasses. | 46 // the subclasses. |
48 // | 47 // |
49 // See the file-level comment above for more information. | 48 // See the file-level comment above for more information. |
50 class BASE_EXPORT Value { | 49 class BASE_EXPORT Value { |
51 public: | 50 public: |
52 using DictStorage = base::flat_map<std::string, std::unique_ptr<Value>>; | 51 using DictStorage = std::map<std::string, std::unique_ptr<Value>>; |
53 using ListStorage = std::vector<std::unique_ptr<Value>>; | 52 using ListStorage = std::vector<std::unique_ptr<Value>>; |
54 | 53 |
55 enum class Type { | 54 enum class Type { |
56 NONE = 0, | 55 NONE = 0, |
57 BOOLEAN, | 56 BOOLEAN, |
58 INTEGER, | 57 INTEGER, |
59 DOUBLE, | 58 DOUBLE, |
60 STRING, | 59 STRING, |
61 BINARY, | 60 BINARY, |
62 DICTIONARY, | 61 DICTIONARY, |
(...skipping 26 matching lines...) Expand all Loading... |
89 explicit Value(const char* in_string); | 88 explicit Value(const char* in_string); |
90 explicit Value(const std::string& in_string); | 89 explicit Value(const std::string& in_string); |
91 explicit Value(std::string&& in_string) noexcept; | 90 explicit Value(std::string&& in_string) noexcept; |
92 explicit Value(const char16* in_string); | 91 explicit Value(const char16* in_string); |
93 explicit Value(const string16& in_string); | 92 explicit Value(const string16& in_string); |
94 explicit Value(StringPiece in_string); | 93 explicit Value(StringPiece in_string); |
95 | 94 |
96 explicit Value(const std::vector<char>& in_blob); | 95 explicit Value(const std::vector<char>& in_blob); |
97 explicit Value(std::vector<char>&& in_blob) noexcept; | 96 explicit Value(std::vector<char>&& in_blob) noexcept; |
98 | 97 |
99 explicit Value(DictStorage&& in_dict) noexcept; | |
100 | |
101 Value& operator=(const Value& that); | 98 Value& operator=(const Value& that); |
102 Value& operator=(Value&& that) noexcept; | 99 Value& operator=(Value&& that) noexcept; |
103 | 100 |
104 ~Value(); | 101 ~Value(); |
105 | 102 |
106 // Returns the name for a given |type|. | 103 // Returns the name for a given |type|. |
107 static const char* GetTypeName(Type type); | 104 static const char* GetTypeName(Type type); |
108 | 105 |
109 // Returns the type of the value stored by the current Value object. | 106 // Returns the type of the value stored by the current Value object. |
110 // Each type will be implemented by only one subclass of Value, so it's | 107 // Each type will be implemented by only one subclass of Value, so it's |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 return out << static_cast<const Value&>(value); | 530 return out << static_cast<const Value&>(value); |
534 } | 531 } |
535 | 532 |
536 // Stream operator so that enum class Types can be used in log statements. | 533 // Stream operator so that enum class Types can be used in log statements. |
537 BASE_EXPORT std::ostream& operator<<(std::ostream& out, | 534 BASE_EXPORT std::ostream& operator<<(std::ostream& out, |
538 const Value::Type& type); | 535 const Value::Type& type); |
539 | 536 |
540 } // namespace base | 537 } // namespace base |
541 | 538 |
542 #endif // BASE_VALUES_H_ | 539 #endif // BASE_VALUES_H_ |
OLD | NEW |