22template <
bool bIsConst>
25 template <
bool _bIsConst>
26 friend class NBT_Node_View;
34 using type = std::conditional<bIsConst, const T, T>::type;
38 using PtrType =
typename AddConstIf<T>::type *;
41 struct TypeListPointerToVariant;
43 template <
typename... Ts>
44 struct TypeListPointerToVariant<
NBT_Type::_TypeList<Ts...>>
46 using type = std::variant<PtrType<Ts>...>;
51 using VariantData = TypeListPointerToVariant<NBT_Type::TypeList>::type;
59 static inline constexpr bool is_const = bIsConst;
87 std::visit([
this](
auto &arg)
97 template <
typename =
void>
101 std::visit([
this](
auto &arg)
111 template <
typename =
void>
115 std::visit([
this](
auto &arg)
125 template <
typename T>
126 requires(!std::is_lvalue_reference_v<T>)
135 template <
typename T>
139 data.template emplace<PtrType<T>>(&value);
149 template <
typename T>
151 const T &
Set(
const T &value)
153 data.template emplace<PtrType<T>>(&value);
162 template <
typename =
void>
166 std::visit([
this](
auto &arg)
179 template <
typename =
void>
183 std::visit([
this](
auto &arg)
195 template <
typename T>
196 requires(!std::is_lvalue_reference_v<T>)
197 T &
Set(T &&_Temp) =
delete;
205 template <
typename T>
207 NBT_Node_View &
operator=(T &value)
220 template <
typename T>
222 NBT_Node_View &
operator=(
const T &value)
234 template <
typename =
void>
238 std::visit([
this](
auto &arg)
251 template <
typename =
void>
255 std::visit([
this](
auto &arg)
267 template <
typename T>
268 requires(!std::is_lvalue_reference_v<T>)
269 NBT_Node_View &
operator=(T &&_Temp) =
delete;
321 NBT_Node_View &
operator=(NBT_Node_View &&_Move)
noexcept
323 data = std::move(_Move.data);
334 if (
GetTag() != _Right.GetTag())
339 return std::visit([
this](
const auto *argL,
const auto *argR)->
bool
341 using TL =
const std::decay_t<
decltype(argL)>;
342 return *argL == *(TL)argR;
343 }, this->data, _Right.data);
353 if (
GetTag() != _Right.GetTag())
358 return std::visit([
this](
const auto *argL,
const auto *argR)->
bool
360 using TL =
const std::decay_t<
decltype(argL)>;
361 return *argL != *(TL)argR;
362 }, this->data, _Right.data);
370 std::partial_ordering
operator<=>(
const NBT_Node_View &_Right)
const noexcept
372 if (
GetTag() != _Right.GetTag())
374 return std::partial_ordering::unordered;
377 return std::visit([
this](
const auto *argL,
const auto *argR)-> std::partial_ordering
379 using TL =
const std::decay_t<
decltype(argL)>;
380 return *argL <=> *(TL)argR;
381 }, this->data, _Right.data);
396 std::conditional_t<bIsConst, const T &, T &>
Get()
const
398 return *std::get<PtrType<T>>(
data);
406 std::conditional_t<bIsConst, const T &, T &>
Get()
408 return *std::get<PtrType<T>>(
data);
416 std::conditional_t<bIsConst, const T *, T *>
GetIf() const noexcept
418 auto p = std::get_if<PtrType<T>>(&
data);
419 return p !=
nullptr ? *p :
nullptr;
427 std::conditional_t<bIsConst, const T *, T *>
GetIf() noexcept
429 auto p = std::get_if<PtrType<T>>(&
data);
430 return p !=
nullptr ? *p :
nullptr;
439 return std::holds_alternative<PtrType<T>>(
data);
447 std::get<PtrType<NBT_Type::End>>(
data) == PtrType<NBT_Type::End>{};
453 data.template emplace<PtrType<NBT_Type::End>>(PtrType<NBT_Type::End>{});
462#define TYPE_GET_FUNC(type)\
468std::conditional_t<bIsConst, const NBT_Type::type &, NBT_Type::type &> Get##type() const\
470 return *std::get<PtrType<NBT_Type::type>>(data);\
478std::conditional_t<bIsConst, const NBT_Type::type &, NBT_Type::type &> Get##type()\
480 return *std::get<PtrType<NBT_Type::type>>(data);\
488std::conditional_t<bIsConst, const NBT_Type::type *, NBT_Type::type *> GetIf##type() const noexcept\
490 auto p = std::get_if<PtrType<NBT_Type::type>>(&data);\
491 return p != nullptr ? *p : nullptr;\
499std::conditional_t<bIsConst, const NBT_Type::type *, NBT_Type::type *> GetIf##type() noexcept\
501 auto p = std::get_if<PtrType<NBT_Type::type>>(&data); \
502 return p != nullptr ? *p : nullptr; \
509bool Is##type() const\
511 return std::holds_alternative<PtrType<NBT_Type::type>>(data);\
519friend std::conditional_t<bIsConst, const NBT_Type::type &, NBT_Type::type &> Get##type(NBT_Node_View & node)\
521 return node.Get##type();\
530friend std::conditional_t<bIsConst, const NBT_Type::type &, NBT_Type::type &> Get##type(const NBT_Node_View & node)\
532 return node.Get##type();\
541friend std::conditional_t<bIsConst, const NBT_Type::type *, NBT_Type::type *> GetIf##type(NBT_Node_View & node) noexcept\
543 return node.GetIf##type();\
552friend std::conditional_t<bIsConst, const NBT_Type::type *, NBT_Type::type *> GetIf##type(const NBT_Node_View & node) noexcept\
554 return node.GetIf##type();\
562friend bool Is##type(const NBT_Node_View &node)\
564 return node.Is##type();\
594#define TYPE_SET_FUNC(type)\
600template <typename = void>\
602NBT_Type::type &Set##type(NBT_Type::type &value)\
604 return Set<NBT_Type::type>(value); \
612template <typename = void>\
614const NBT_Type::type &Set##type(const NBT_Type::type &value)\
616 return Set<NBT_Type::type>(value); \
624NBT_Type::type &Set##type(NBT_Type::type &&_Temp) = delete;
#define TYPE_SET_FUNC(type)
不同类型名接口生成宏
定义 NBT_Node_View.hpp:551
#define TYPE_GET_FUNC(type)
不同类型名接口生成宏
定义 NBT_Node_View.hpp:462
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
TypeListPointerToVariant< NBT_Type::TypeList >::type VariantData
用于存储指向NBT数据的指针的具体变体类型
定义 NBT_Node_View.hpp:51
static constexpr bool is_const
静态常量,表示当前视图指向的数据是否只读
定义 NBT_Node_View.hpp:59
NBT_Node_View(const NBT_Node &node)
从NBT_Node构造视图(仅适用于const)
定义 NBT_Node_View.hpp:99
bool operator==(const NBT_Node_View &_Right) const noexcept
相等比较运算符
定义 NBT_Node_View.hpp:332
std::conditional_t< bIsConst, const T *, T * > GetIf() noexcept
通过指定类型获取当前视图指向的数据对象的指针(根据视图的const属性决定返回常量指针或非常量指针)
定义 NBT_Node_View.hpp:427
~NBT_Node_View()=default
默认析构函数
NBT_Node_View(const NBT_Node_View< false > &_Other)
从非const视图隐式构造const视图
定义 NBT_Node_View.hpp:113
NBT_Node_View & operator=(NBT_Node_View &&_Move) noexcept
移动赋值运算符
定义 NBT_Node_View.hpp:321
std::conditional_t< bIsConst, const T *, T * > GetIf() const noexcept
通过指定类型获取当前视图指向的数据对象的指针(根据视图的const属性决定返回常量指针或非常量指针)
定义 NBT_Node_View.hpp:416
std::conditional_t< bIsConst, const T &, T & > Get() const
通过指定类型获取当前视图指向的数据对象
定义 NBT_Node_View.hpp:396
NBT_Node_View(T &&_Temp)=delete
删除临时对象构造方式,防止从临时对象构造导致悬空指针
std::conditional_t< bIsConst, const T &, T & > Get()
通过指定类型获取当前视图指向的数据对象
定义 NBT_Node_View.hpp:406
const T & Set(const T &value)
通用设置函数(仅适用于const)
定义 NBT_Node_View.hpp:151
NBT_Node_View(NBT_Node_View &&_Move) noexcept
移动构造函数
定义 NBT_Node_View.hpp:290
NBT_Node_View(T &value)
通用构造函数(仅适用于非const)
定义 NBT_Node_View.hpp:68
const NBT_Node & Set(const NBT_Node &node)
从NBT_Node重设视图(仅适用于const)
定义 NBT_Node_View.hpp:181
bool IsEmpty() const
为空判断
定义 NBT_Node_View.hpp:444
NBT_TAG GetTag() const noexcept
获取当前视图指向的NBT类型的枚举值
定义 NBT_Node_View.hpp:386
T & Set(T &&_Temp)=delete
删除临时对象设置方式,防止从临时对象构造导致悬空指针
NBT_Node_View(NBT_Node &node)
从NBT_Node构造视图(仅适用于非const)
定义 NBT_Node_View.hpp:85
VariantData & GetData(void) noexcept
获取底层容器数据的引用
定义 NBT_Node_View.hpp:302
NBT_Node_View()
默认构造函数
定义 NBT_Node_View.hpp:274
void SetEmpty()
设置为空
定义 NBT_Node_View.hpp:451
std::partial_ordering operator<=>(const NBT_Node_View &_Right) const noexcept
三路比较运算符
定义 NBT_Node_View.hpp:370
VariantData data
数据对象(仅持有数据的指针)
定义 NBT_Node_View.hpp:55
NBT_Node_View(const T &value)
通用构造函数(仅适用于const)
定义 NBT_Node_View.hpp:78
bool TypeHolds() const
类型判断
定义 NBT_Node_View.hpp:437
NBT_Node_View & operator=(const NBT_Node_View &_Copy)
拷贝赋值运算符
定义 NBT_Node_View.hpp:311
bool operator!=(const NBT_Node_View &_Right) const noexcept
不等比较运算符
定义 NBT_Node_View.hpp:351
NBT_Node_View(const NBT_Node_View &_Copy)
拷贝构造函数
定义 NBT_Node_View.hpp:284
T & Set(T &value)
通用设置函数(仅适用于非const)
定义 NBT_Node_View.hpp:137
NBT_Node & Set(NBT_Node &node)
从NBT_Node重设视图(仅适用于非const)
定义 NBT_Node_View.hpp:164
const VariantData & GetData(void) const noexcept
获取底层容器数据的常量引用
定义 NBT_Node_View.hpp:295
NBT节点,用于存储NBT格式的各种数据类型
定义 NBT_Node.hpp:37
VariantData data
数据对象(要求必须持有数据)
定义 NBT_Node.hpp:59
提供NBT类型定义,包括NBT格式中的所有数据类型,以及部分辅助功能,比如静态类型与Tag映射,类型存在查询,类型列表大小,类型最大小值等
定义 NBT_Type.hpp:29
static constexpr bool IsValidType_V
类型存在检查:用于编译期检查一个给定类型是否为NBT中的类型
定义 NBT_Type.hpp:183