载入中...
搜索中...
未找到
EditingValue.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cstdint>
6#include <map>
7#include <string>
8#include <type_traits>
9#include <variant>
10#include <vector>
11
12namespace eve::editing {
13
24public:
25 using Array = std::vector<Value>;
26 using Object = std::map<std::string, Value>;
27 using Storage = std::variant<std::monostate, bool, int64_t, double, std::string, Array, Object>;
28
30 enum class Type { Null, Bool, Integer, Number, String, Array, Object };
31
33 Value() noexcept;
35 ~Value() noexcept;
37 Value(const Value& other);
39 Value& operator=(const Value& other);
41 Value(Value&& other) noexcept(std::is_nothrow_move_constructible_v<Storage>);
43 Value& operator=(Value&& other) noexcept(std::is_nothrow_move_assignable_v<Storage>);
45 Value(std::nullptr_t);
47 Value(bool value);
49 Value(int value);
51 Value(int64_t value);
53 Value(float value);
55 Value(double value);
57 Value(const char* value);
59 Value(std::string value);
64
66 Type type() const;
68 const Storage& storage() const { return storage_; }
70 Storage& storage() { return storage_; }
71
77 template <class T>
78 const T* getIf() const {
79 return std::get_if<T>(&storage_);
80 }
86 template <class T>
87 T* getIf() {
88 return std::get_if<T>(&storage_);
89 }
90
98 bool isWithinLimits(size_t maxDepth, size_t maxElements, size_t maxStringBytes) const;
99
101 bool operator==(const Value&) const;
102
103private:
104 Storage storage_;
105};
106
107} // namespace eve::editing
108
109// Platform owns the Windows DLL container operations. Elements retain their
110// independent storage; consumers use the same CRT and iterator configuration.
111#if defined(_WIN32) && defined(EVENGINE_MODULE_DLL) && !defined(EVENGINE_EXPORTS_PLATFORM)
112extern template class __declspec(dllimport) std::vector<eve::editing::Value>;
113extern template class __declspec(dllimport) std::map<std::string, eve::editing::Value>;
114#endif
115
116// Share common Windows DLL getters without changing the variant or its borrows.
117// Returned pointers still refer directly into the caller-owned Value.
118#if defined(_WIN32) && defined(EVENGINE_MODULE_DLL) && !defined(EVENGINE_EXPORTS_PLATFORM)
119extern template __declspec(dllimport) std::monostate* eve::editing::Value::getIf<std::monostate>();
120extern template __declspec(dllimport) const std::monostate* eve::editing::Value::getIf<std::monostate>() const;
121extern template __declspec(dllimport) bool* eve::editing::Value::getIf<bool>();
122extern template __declspec(dllimport) const bool* eve::editing::Value::getIf<bool>() const;
123extern template __declspec(dllimport) int64_t* eve::editing::Value::getIf<int64_t>();
124extern template __declspec(dllimport) const int64_t* eve::editing::Value::getIf<int64_t>() const;
125extern template __declspec(dllimport) double* eve::editing::Value::getIf<double>();
126extern template __declspec(dllimport) const double* eve::editing::Value::getIf<double>() const;
127extern template __declspec(dllimport) std::string* eve::editing::Value::getIf<std::string>();
128extern template __declspec(dllimport) const std::string* eve::editing::Value::getIf<std::string>() const;
129extern template __declspec(dllimport) eve::editing::Value::Array*
130 eve::editing::Value::getIf<eve::editing::Value::Array>();
131extern template __declspec(dllimport) const eve::editing::Value::Array*
132 eve::editing::Value::getIf<eve::editing::Value::Array>() const;
133extern template __declspec(dllimport) eve::editing::Value::Object*
134 eve::editing::Value::getIf<eve::editing::Value::Object>();
135extern template __declspec(dllimport) const eve::editing::Value::Object*
136eve::editing::Value::getIf<eve::editing::Value::Object>() const;
137#endif
#define EVENGINE_API_PLATFORM
Definition Export.h:107
Object::Ptr value
Deterministic owning value tree shared by authoring hosts.
Value() noexcept
Construct a null owning value.
Type
Type public API.
std::vector< Value > Array
Storage & storage()
Return mutable storage; all child borrows are invalidated by mutation.
std::map< std::string, Value > Object
T * getIf()
Return an immediately borrowed mutable value.
std::variant< std::monostate, bool, int64_t, double, std::string, Array, Object > Storage
const T * getIf() const
Return an immediately borrowed typed value.
enum EVENGINE_API_FOUNDATION Bool
OT_BOOL.
Definition Runtime.h:116
enum EVENGINE_API_FOUNDATION Integer
OT_INTEGER.
Definition Runtime.h:117
enum EVENGINE_API_FOUNDATION String
OT_STRING.
Definition Runtime.h:119