43 [[nodiscard]] LL_CONSTEXPR23
UniqueTagPtr(nullptr_t)
noexcept {}
45 [[nodiscard]] LL_CONSTEXPR23
explicit UniqueTagPtr(
Tag* p) noexcept : ptr(p) {}
47 [[nodiscard]] LL_CONSTEXPR23
UniqueTagPtr(std::unique_ptr<Tag>&& ptr) noexcept : ptr(ptr.release()) {}
59 LL_CONSTEXPR23
UniqueTagPtr& operator=(nullptr_t)
noexcept {
64 LL_CONSTEXPR23
UniqueTagPtr& operator=(std::unique_ptr<Tag>&& r)
noexcept {
75 if (r && &r !=
this) ptr = r->copy().release();
78 LL_CONSTEXPR23
void swap(
UniqueTagPtr& r)
noexcept { std::swap(ptr, r.ptr); }
82 [[nodiscard]] LL_CONSTEXPR23
Tag& operator*()
const noexcept {
return *ptr; }
84 [[nodiscard]] LL_CONSTEXPR23
Tag* operator->()
const noexcept {
return ptr; }
86 [[nodiscard]] LL_CONSTEXPR23
Tag* get()
const noexcept {
return ptr; }
88 LL_CONSTEXPR23
explicit operator bool()
const noexcept {
return static_cast<bool>(ptr); }
90 LL_CONSTEXPR23
operator std::unique_ptr<Tag>() &&
noexcept {
return std::unique_ptr<Tag>{release()}; }
92 LL_CONSTEXPR23
operator std::unique_ptr<Tag>()
const&
noexcept {
return ptr ? ptr->copy() :
nullptr; }
94 LL_CONSTEXPR23
Tag* release()
noexcept {
return std::exchange(ptr,
nullptr); }
96 LL_CONSTEXPR23
void reset(
Tag* p =
nullptr)
noexcept {
97 Tag* old = std::exchange(ptr, p);
102 [[nodiscard]]
UniqueTagPtr const& operator[](
size_t index)
const;
107 return operator[](std::string_view{index});
111 return operator[](std::string_view{index});
115 [[nodiscard]] std::unique_ptr<Tag> copy()
const {
return ptr ? ptr->copy() :
nullptr; }
117 [[nodiscard]] ::Tag::Type index()
const {
return ptr ? ptr->getId() : ::Tag::End; }
118 [[nodiscard]] Tag::Type getId()
const noexcept {
return index(); }
120 [[nodiscard]]
inline bool operator==(
UniqueTagPtr const& r)
const {
121 return (ptr == r.get()) || (ptr && r && *ptr == *r);
123 template <std::derived_from<Tag> T>
124 [[nodiscard]]
bool hold()
const noexcept {
125 return ptr && (Types::index<T> == (size_t)getId());
127 [[nodiscard]]
bool hold(::Tag::Type type)
const noexcept {
return ptr && (getId() == type); }
130 [[nodiscard]]
bool is_array()
const noexcept {
return hold(Tag::List); }
131 [[nodiscard]]
bool is_binary()
const noexcept {
return hold(Tag::ByteArray) || hold(Tag::IntArray); }
132 [[nodiscard]]
bool is_boolean()
const noexcept {
return hold(Tag::Byte); }
133 [[nodiscard]]
bool is_null()
const noexcept {
return hold(Tag::End); }
134 [[nodiscard]]
bool is_number_float()
const noexcept {
return hold(Tag::Float) || hold(Tag::Double); }
135 [[nodiscard]]
bool is_number_integer()
const noexcept {
136 return hold(Tag::Byte) || hold(Tag::Short) || hold(Tag::Int) || hold(Tag::Int64);
138 [[nodiscard]]
bool is_object()
const noexcept {
return hold(Tag::Compound); }
139 [[nodiscard]]
bool is_string()
const noexcept {
return hold(Tag::String); }
140 [[nodiscard]]
bool is_number()
const noexcept {
return is_number_float() || is_number_integer(); }
141 [[nodiscard]]
bool is_primitive()
const noexcept {
return is_null() || is_string() || is_number() || is_binary(); }
142 [[nodiscard]]
bool is_structured()
const noexcept {
return is_array() || is_object(); }
144 [[nodiscard]] std::string
145 toSnbt(SnbtFormat snbtFormat = SnbtFormat::PrettyFilePrint, uchar indent = 4)
const noexcept {
146 return ptr ? ptr->toSnbt(snbtFormat, indent) :
"";
148 template <std::derived_from<Tag> T>
152 template <std::derived_from<Tag> T>
153 [[nodiscard]]
bool contains(std::string_view key)
const noexcept {
154 return contains(key, (Tag::Type)Types::index<T>);
158 template <std::derived_from<Tag> T>
159 [[nodiscard]] T& get()
const;
161 [[nodiscard]]
bool contains(std::string_view key)
const noexcept;
162 [[nodiscard]]
bool contains(std::string_view key, Tag::Type type)
const noexcept;
163 [[nodiscard]]
size_t size()
const noexcept;
165 [[nodiscard]]
operator std::string
const&()
const;
166 [[nodiscard]]
operator std::string&() &;
167 [[nodiscard]]
operator std::string&&() &&;
168 [[nodiscard]]
operator std::string_view()
const;
171 requires(std::is_arithmetic_v<T> && !ll::traits::is_char_v<T>)
172 [[nodiscard]]
operator T()
const;