22template <
bool bIsConst>
25 template <
bool _bIsConst>
26 friend class NBT_Node_View;
33 using type = std::conditional<bIsConst, const T, T>::type;
37 using PtrType =
typename AddConstIf<T>::type *;
40 struct TypeListPointerToVariant;
42 template <
typename... Ts>
43 struct TypeListPointerToVariant<
NBT_Type::_TypeList<Ts...>>
45 using type = std::variant<PtrType<Ts>...>;
48 using VariantData = TypeListPointerToVariant<NBT_Type::TypeList>::type;
54 static inline constexpr bool is_const = bIsConst;
84 std::visit([
this](
auto &arg)
94 template <
typename =
void>
98 std::visit([
this](
auto &arg)
108 template <
typename =
void>
112 std::visit([
this](
auto &arg)
122 template <
typename T>
123 requires(!std::is_lvalue_reference_v<T>)
132 template <
typename T>
136 data.template emplace<PtrType<T>>(&value);
146 template <
typename T>
148 const T &
Set(
const T &value)
150 data.template emplace<PtrType<T>>(&value);
159 template <
typename =
void>
163 std::visit([
this](
auto &arg)
176 template <
typename =
void>
180 std::visit([
this](
auto &arg)
192 template <
typename T>
193 requires(!std::is_lvalue_reference_v<T>)
194 T &
Set(T &&_Temp) =
delete;
202 template <
typename T>
204 NBT_Node_View &
operator=(T &value)
217 template <
typename T>
219 NBT_Node_View &
operator=(
const T &value)
231 template <
typename =
void>
235 std::visit([
this](
auto &arg)
248 template <
typename =
void>
252 std::visit([
this](
auto &arg)
264 template <
typename T>
265 requires(!std::is_lvalue_reference_v<T>)
266 NBT_Node_View &
operator=(T &&_Temp) =
delete;
304 NBT_Node_View &
operator=(NBT_Node_View &&_Move)
noexcept
306 data = std::move(_Move.data);
317 if (
GetTag() != _Right.GetTag())
322 return std::visit([
this](
const auto *argL,
const auto *argR)->
bool
324 using TL =
const std::decay_t<
decltype(argL)>;
325 return *argL == *(TL)argR;
326 }, this->data, _Right.data);
336 if (
GetTag() != _Right.GetTag())
341 return std::visit([
this](
const auto *argL,
const auto *argR)->
bool
343 using TL =
const std::decay_t<
decltype(argL)>;
344 return *argL != *(TL)argR;
345 }, this->data, _Right.data);
353 std::partial_ordering
operator<=>(
const NBT_Node_View &_Right)
const noexcept
355 if (
GetTag() != _Right.GetTag())
357 return std::partial_ordering::unordered;
360 return std::visit([
this](
const auto *argL,
const auto *argR)-> std::partial_ordering
362 using TL =
const std::decay_t<
decltype(argL)>;
363 return *argL <=> *(TL)argR;
364 }, this->data, _Right.data);
381 return *std::get<PtrType<T>>(data);
392 return *std::get<PtrType<T>>(data);
401 return std::holds_alternative<PtrType<T>>(data);
409 std::get<PtrType<NBT_Type::End>>(data) == PtrType<NBT_Type::End>{};
415 data.template emplace<PtrType<NBT_Type::End>>(PtrType<NBT_Type::End>{});
424#define TYPE_GET_FUNC(type)\
430const NBT_Type::type &Get##type() const\
432 return *std::get<PtrType<NBT_Type::type>>(data);\
440template <typename = void>\
442NBT_Type::type &Get##type()\
444 return *std::get<PtrType<NBT_Type::type>>(data);\
451bool Is##type() const\
453 return std::holds_alternative<PtrType<NBT_Type::type>>(data);\
461friend std::conditional_t<bIsConst, const NBT_Type::type &, NBT_Type::type &> Get##type(NBT_Node_View & node)\
463 return node.Get##type();\
472friend std::conditional_t<bIsConst, const NBT_Type::type &, NBT_Type::type &> &Get##type(const NBT_Node_View & node)\
474 return node.Get##type();\
482friend bool Is##type(const NBT_Node_View &node)\
484 return node.Is##type();\
514#define TYPE_SET_FUNC(type)\
520template <typename = void>\
522NBT_Type::type &Set##type(NBT_Type::type &value)\
524 return Set<NBT_Type::type>(value); \
532template <typename = void>\
534const NBT_Type::type &Set##type(const NBT_Type::type &value)\
536 return Set<NBT_Type::type>(value); \
544NBT_Type::type &Set##type(NBT_Type::type &&_Temp) = delete;
#define TYPE_SET_FUNC(type)
不同类型名接口生成宏
定义 NBT_Node_View.hpp:489
#define TYPE_GET_FUNC(type)
不同类型名接口生成宏
定义 NBT_Node_View.hpp:424
NBT_TAG
枚举NBT类型对应的类型标签值
定义 NBT_TAG.hpp:17
@ Int
对应NBT_Type::Int
定义 NBT_TAG.hpp:21
@ Float
对应NBT_Type::Float
定义 NBT_TAG.hpp:23
@ ByteArray
对应NBT_Type::ByteArray
定义 NBT_TAG.hpp:25
@ Short
对应NBT_Type::Short
定义 NBT_TAG.hpp:20
@ Long
对应NBT_Type::Long
定义 NBT_TAG.hpp:22
@ End
对应NBT_Type::End
定义 NBT_TAG.hpp:18
@ LongArray
对应NBT_Type::LongArray
定义 NBT_TAG.hpp:30
@ Byte
对应NBT_Type::Byte
定义 NBT_TAG.hpp:19
@ IntArray
对应NBT_Type::IntArray
定义 NBT_TAG.hpp:29
@ Double
对应NBT_Type::Double
定义 NBT_TAG.hpp:24
static constexpr bool is_const
静态常量,表示当前视图指向的数据是否只读
定义 NBT_Node_View.hpp:54
bool operator==(const NBT_Node_View &_Right) const noexcept
相等比较运算符
定义 NBT_Node_View.hpp:315
~NBT_Node_View()=default
默认析构函数
NBT_Node_View(T &&_Temp)=delete
删除临时对象构造方式,防止从临时对象构造导致悬空指针
const T & Get() const
通过指定类型获取当前视图指向的数据对象
定义 NBT_Node_View.hpp:379
const NBT_Node & Set(const NBT_Node &node)
从NBT_Node重设视图(仅适用于const)
定义 NBT_Node_View.hpp:178
NBT_Node_View & operator=(NBT_Node_View &&_Move) noexcept
移动赋值运算符
定义 NBT_Node_View.hpp:304
NBT_Node & Set(NBT_Node &node)
从NBT_Node重设视图(仅适用于非const)
定义 NBT_Node_View.hpp:161
NBT_Node_View(const T &value)
通用构造函数(仅适用于const)
定义 NBT_Node_View.hpp:75
T & Set(T &&_Temp)=delete
删除临时对象设置方式,防止从临时对象构造导致悬空指针
NBT_Node_View(T &value)
通用构造函数(仅适用于非const)
定义 NBT_Node_View.hpp:65
NBT_Node_View(NBT_Node_View &&_Move) noexcept
移动构造函数
定义 NBT_Node_View.hpp:287
bool IsEmpty() const
为空判断
定义 NBT_Node_View.hpp:406
T & Set(T &value)
通用设置函数(仅适用于非const)
定义 NBT_Node_View.hpp:134
NBT_TAG GetTag() const noexcept
获取当前视图指向的NBT类型的枚举值
定义 NBT_Node_View.hpp:369
NBT_Node_View(const NBT_Node &node)
从NBT_Node构造视图(仅适用于const)
定义 NBT_Node_View.hpp:96
NBT_Node_View(const NBT_Node_View< false > &_Other)
从非const视图隐式构造const视图
定义 NBT_Node_View.hpp:110
NBT_Node_View(NBT_Node &node)
从NBT_Node构造视图(仅适用于非const)
定义 NBT_Node_View.hpp:82
NBT_Node_View()
默认构造函数
定义 NBT_Node_View.hpp:271
T & Get()
通过指定类型获取当前视图指向的数据对象(仅适用于非const视图)
定义 NBT_Node_View.hpp:390
void SetEmpty()
设置为空
定义 NBT_Node_View.hpp:413
std::partial_ordering operator<=>(const NBT_Node_View &_Right) const noexcept
三路比较运算符
定义 NBT_Node_View.hpp:353
bool TypeHolds() const
类型判断
定义 NBT_Node_View.hpp:399
NBT_Node_View & operator=(const NBT_Node_View &_Copy)
拷贝赋值运算符
定义 NBT_Node_View.hpp:294
bool operator!=(const NBT_Node_View &_Right) const noexcept
不等比较运算符
定义 NBT_Node_View.hpp:334
const T & Set(const T &value)
通用设置函数(仅适用于const)
定义 NBT_Node_View.hpp:148
NBT_Node_View(const NBT_Node_View &_Copy)
拷贝构造函数
定义 NBT_Node_View.hpp:281
NBT节点,用于存储NBT格式的各种数据类型
定义 NBT_Node.hpp:37
提供NBT类型定义,包括NBT格式中的所有数据类型,以及部分辅助功能,比如静态类型与Tag映射,类型存在查询,类型列表大小,类型最大小值等
定义 NBT_Type.hpp:28
static constexpr bool IsValidType_V
类型存在检查:用于编译期检查一个给定类型是否为NBT中的类型
定义 NBT_Type.hpp:182