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