载入中...
搜索中...
未找到
EditingValue.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include <cstdint>
6#include <map>
7#include <string>
8#include <variant>
9#include <vector>
10
11namespace eve::editing {
12
20public:
21 using Array = std::vector<Value>;
22 using Object = std::map<std::string, Value>;
23 using Storage = std::variant<std::monostate, bool, int64_t, double, std::string, Array, Object>;
24
26 enum class Type { Null, Bool, Integer, Number, String, Array, Object };
27
28 Value() = default;
29 Value(std::nullptr_t) {}
30 Value(bool value) : storage_(value) {}
31 Value(int value) : storage_(static_cast<int64_t>(value)) {}
32 Value(int64_t value) : storage_(value) {}
33 Value(float value) : storage_(static_cast<double>(value)) {}
34 Value(double value) : storage_(value) {}
35 Value(const char* value) : storage_(std::string(value ? value : "")) {}
36 Value(std::string value) : storage_(std::move(value)) {}
37 Value(Array value) : storage_(std::move(value)) {}
38 Value(Object value) : storage_(std::move(value)) {}
39
41 Type type() const;
43 const Storage& storage() const { return storage_; }
45 Storage& storage() { return storage_; }
46
52 template <class T>
53 const T* getIf() const {
54 return std::get_if<T>(&storage_);
55 }
61 template <class T>
62 T* getIf() {
63 return std::get_if<T>(&storage_);
64 }
65
73 bool isWithinLimits(size_t maxDepth, size_t maxElements, size_t maxStringBytes) const;
74
75 bool operator==(const Value&) const = default;
76
77private:
78 Storage storage_;
79};
80
81} // namespace eve::editing
double value
#define EVENGINE_API_PLATFORM
Definition Export.h:107
std::string string
Deterministic owning value tree shared by authoring hosts.
Value(const char *value)
Value(std::string value)
Type
Type public API.
Value(std::nullptr_t)
Value(int64_t value)
std::vector< Value > Array
Value(Array value)
Storage & storage()
Return mutable storage; all child borrows are invalidated by mutation.
bool operator==(const Value &) const =default
std::map< std::string, Value > Object
Value(float value)
Value(double value)
T * getIf()
Return an immediately borrowed mutable value.
std::variant< std::monostate, bool, int64_t, double, std::string, Array, Object > Storage
Value(Object value)
const Storage & storage() const
Return the underlying variant for typed visitors.
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