4#include <unordered_map>
7#include <initializer_list>
21template<
typename Compound>
24 friend class NBT_Reader;
25 friend class NBT_Writer;
26 friend class NBT_Helper;
37 using Hasher =
typename Compound::hasher;
45 using Pointer =
typename Compound::pointer;
65 template<
typename... Args>
72 NBT_Compound(std::initializer_list<typename Compound::value_type> init) : Compound(init)
92 const Compound &
GetData(
void)
const noexcept
109 Compound::operator=(std::move(_Move));
118 Compound::operator=(_Copy);
128 return (
const Compound &)*
this == (
const Compound &)_Right;
137 return (
const Compound &)*
this != (
const Compound &)_Right;
152 if (
auto _cmpSize = Compound::size() <=> _Right.size(); _cmpSize != 0)
159 const auto _rSort = _Right.KeySortIt();
160 typename Compound::size_type _Size = Compound::size();
162 for (
typename Compound::size_type _i = 0; _i < _Size; ++_i)
164 const auto &_lIt = _lSort[_i];
165 const auto &_rIt = _rSort[_i];
168 if (
auto _cmpKey = _lIt->first <=> _rIt->first; _cmpKey != 0)
174 if (
auto _cmpVal = _lIt->second <=> _rIt->second; _cmpVal != 0)
181 return std::partial_ordering::equivalent;
191 template<
bool bAscending = true>
192 std::vector<typename Compound::iterator>
KeySortIt(
void)
194 std::vector<typename Compound::iterator> listSortIt;
195 listSortIt.reserve(Compound::size());
196 for (
auto it = Compound::begin(); it != Compound::end(); ++it)
198 listSortIt.push_back(it);
201 std::sort(listSortIt.begin(), listSortIt.end(),
202 [](
const auto &l,
const auto &r) ->
bool
204 if constexpr (bAscending)
206 return l->first < r->first;
210 return l->first > r->first;
225 template<
bool bAscending = true>
226 std::vector<typename Compound::const_iterator>
KeySortIt(
void)
const
228 std::vector<typename Compound::const_iterator> listSortIt;
229 listSortIt.reserve(Compound::size());
230 for (
auto it = Compound::cbegin(); it != Compound::cend(); ++it)
232 listSortIt.push_back(it);
235 std::sort(listSortIt.begin(), listSortIt.end(),
236 [](
const auto &l,
const auto &r) ->
bool
238 if constexpr (bAscending)
240 return l->first < r->first;
244 return l->first > r->first;
256 using Compound::begin;
258 using Compound::cbegin;
259 using Compound::cend;
260 using Compound::operator[];
270 typename Compound::mapped_type &
Get(
const typename Compound::key_type &sTagName)
272 return Compound::at(sTagName);
279 const typename Compound::mapped_type &
Get(
const typename Compound::key_type &sTagName)
const
281 return Compound::at(sTagName);
289 typename Compound::mapped_type *
Has(
const typename Compound::key_type &sTagName)
noexcept
291 auto find = Compound::find(sTagName);
292 return find == Compound::end()
301 const typename Compound::mapped_type *
Has(
const typename Compound::key_type &sTagName)
const noexcept
303 auto find = Compound::find(sTagName);
304 return find == Compound::end()
320 template <
typename K,
typename V>
321 requires std::constructible_from<typename Compound::key_type, K &&> &&std::constructible_from<typename Compound::mapped_type, V &&>
322 std::pair<typename Compound::iterator, bool>
Put(K &&sTagName, V &&vTagVal)
324 return Compound::insert_or_assign(std::forward<K>(sTagName), std::forward<V>(vTagVal));
335 template <
typename K,
typename V>
336 requires std::constructible_from<typename Compound::key_type, K &&> &&std::constructible_from<typename Compound::mapped_type, V &&>
337 std::pair<typename Compound::iterator, bool>
TryPut(K &&sTagName, V &&vTagVal)
339 return Compound::try_emplace(std::forward<K>(sTagName), std::forward<V>(vTagVal));
345 bool Remove(
const typename Compound::key_type &sTagName)
347 return Compound::erase(sTagName) != 0;
361 return Compound::empty();
366 typename Compound::size_type
Size(
void)
const noexcept
368 return Compound::size();
377 Compound::merge(_Copy);
386 Compound::merge(std::move(_Move));
392 bool Contains(
const typename Compound::key_type &sTagName)
const noexcept
394 return Compound::contains(sTagName);
402 template<
typename Predicate>
405 return std::find_if(Compound::begin(), Compound::end(), pred) != Compound::end();
415#define TYPE_GET_FUNC(type)\
422bool Contains##type(const typename Compound::key_type &sTagName) const\
424 auto *p = Has(sTagName);\
425 return p != nullptr && p->Is##type();\
435const typename NBT_Type::type &Get##type(const typename Compound::key_type & sTagName) const\
437 return Compound::at(sTagName).Get##type();\
447typename NBT_Type::type &Get##type(const typename Compound::key_type & sTagName)\
449 return Compound::at(sTagName).Get##type();\
458const typename NBT_Type::type *Has##type(const typename Compound::key_type & sTagName) const noexcept\
460 auto *p = Has(sTagName);\
472typename NBT_Type::type *Has##type(const typename Compound::key_type & sTagName) noexcept\
474 auto *p = Has(sTagName);\
507#define TYPE_PUT_FUNC(type)\
517template <typename K>\
518requires std::constructible_from<typename Compound::key_type, K &&>\
519std::pair<typename Compound::iterator, bool> Put##type(K &&sTagName, const typename NBT_Type::type &vTagVal)\
521 return Put(std::forward<K>(sTagName), vTagVal);\
533template <typename K>\
534requires std::constructible_from<typename Compound::key_type, K &&>\
535std::pair<typename Compound::iterator, bool> Put##type(K &&sTagName, typename NBT_Type::type &&vTagVal)\
537 return Put(std::forward<K>(sTagName), std::move(vTagVal));\
549template <typename K>\
550requires std::constructible_from<typename Compound::key_type, K &&>\
551std::pair<typename Compound::iterator, bool> TryPut##type(K &&sTagName, const typename NBT_Type::type &vTagVal)\
553 return TryPut(std::forward<K>(sTagName), vTagVal);\
565template <typename K>\
566requires std::constructible_from<typename Compound::key_type, K &&>\
567std::pair<typename Compound::iterator, bool> TryPut##type(K &&sTagName, typename NBT_Type::type &&vTagVal)\
569 return TryPut(std::forward<K>(sTagName), std::move(vTagVal));\
#define TYPE_PUT_FUNC(type)
不同类型名接口生成宏
定义 NBT_Compound.hpp:480
#define TYPE_GET_FUNC(type)
不同类型名接口生成宏
定义 NBT_Compound.hpp:415
@ Int
对应NBT_Type::Int
定义 NBT_TAG.hpp:21
@ Float
对应NBT_Type::Float
定义 NBT_TAG.hpp:23
@ Compound
对应NBT_Type::Compound
定义 NBT_TAG.hpp:28
@ 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
NBT_Compound(std::initializer_list< typename Compound::value_type > init)
初始化列表构造函数
定义 NBT_Compound.hpp:72
typename Compound::const_pointer Const_Pointer
标准库容器公开类型映射
定义 NBT_Compound.hpp:46
std::partial_ordering operator<=>(const NBT_Compound &_Right) const noexcept
三路比较运算符
定义 NBT_Compound.hpp:150
void Clear(void)
清空所有标签
定义 NBT_Compound.hpp:352
bool operator!=(const NBT_Compound &_Right) const noexcept
不等比较运算符
定义 NBT_Compound.hpp:135
typename Compound::mapped_type Mapped_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:39
NBT_Compound(void)=default
默认构造函数
Compound Super
父类类型
定义 NBT_Compound.hpp:30
std::vector< typename Compound::iterator > KeySortIt(void)
获取按键名排序的迭代器向量(非常量版本)
定义 NBT_Compound.hpp:192
NBT_Compound(NBT_Compound &&_Move) noexcept
移动构造函数
定义 NBT_Compound.hpp:82
NBT_Compound & operator=(const NBT_Compound &_Copy)
拷贝赋值运算符
定义 NBT_Compound.hpp:116
NBT_Compound & operator=(NBT_Compound &&_Move) noexcept
移动赋值运算符
定义 NBT_Compound.hpp:107
std::vector< typename Compound::const_iterator > KeySortIt(void) const
获取按键名排序的常量迭代器向量(常量版本)
定义 NBT_Compound.hpp:226
typename Compound::allocator_type Allocator_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:42
typename Compound::key_equal Key_Equal
标准库容器公开类型映射
定义 NBT_Compound.hpp:40
Compound::mapped_type & Get(const typename Compound::key_type &sTagName)
根据标签名获取对应的NBT值
定义 NBT_Compound.hpp:270
typename Compound::const_local_iterator Const_Local_Iterator
标准库容器公开类型映射
定义 NBT_Compound.hpp:52
void Merge(NBT_Compound &&_Move)
合并另一个NBT_Compound的内容(移动)
定义 NBT_Compound.hpp:384
typename Compound::value_type Value_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:41
const Compound & GetData(void) const noexcept
获取底层容器数据的常量引用
定义 NBT_Compound.hpp:92
const Compound::mapped_type * Has(const typename Compound::key_type &sTagName) const noexcept
搜索标签是否存在(常量版本)
定义 NBT_Compound.hpp:301
const Compound::mapped_type & Get(const typename Compound::key_type &sTagName) const
根据标签名获取对应的NBT值(常量版本)
定义 NBT_Compound.hpp:279
typename Compound::size_type Size_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:43
typename Compound::iterator Iterator
标准库容器公开类型映射
定义 NBT_Compound.hpp:49
typename Compound::const_reference Const_Reference
标准库容器公开类型映射
定义 NBT_Compound.hpp:48
bool Empty(void) const noexcept
检查容器是否为空
定义 NBT_Compound.hpp:359
bool Contains(const typename Compound::key_type &sTagName) const noexcept
检查是否包含指定标签
定义 NBT_Compound.hpp:392
Compound & GetData(void) noexcept
获取底层容器数据的引用
定义 NBT_Compound.hpp:99
NBT_Compound(const NBT_Compound &_Copy)
拷贝构造函数
定义 NBT_Compound.hpp:87
typename Compound::insert_return_type Insert_Return_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:54
typename Compound::key_type Key_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:38
typename Compound::const_iterator Const_Iterator
标准库容器公开类型映射
定义 NBT_Compound.hpp:50
typename Compound::hasher Hasher
标准库容器公开类型映射
定义 NBT_Compound.hpp:37
typename Compound::local_iterator Local_Iterator
标准库容器公开类型映射
定义 NBT_Compound.hpp:51
bool operator==(const NBT_Compound &_Right) const noexcept
相等比较运算符
定义 NBT_Compound.hpp:126
NBT_Compound(Args &&... args)
完美转发构造函数
定义 NBT_Compound.hpp:66
~NBT_Compound(void)=default
默认析构函数
Compound::mapped_type * Has(const typename Compound::key_type &sTagName) noexcept
搜索标签是否存在
定义 NBT_Compound.hpp:289
bool ContainsIf(Predicate pred) const noexcept
使用谓词检查是否存在满足条件的元素
定义 NBT_Compound.hpp:403
typename Compound::difference_type Difference_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:44
Compound::size_type Size(void) const noexcept
获取容器中元素的数量
定义 NBT_Compound.hpp:366
typename Compound::reference Reference
标准库容器公开类型映射
定义 NBT_Compound.hpp:47
void Merge(const NBT_Compound &_Copy)
合并另一个NBT_Compound的内容(拷贝)
定义 NBT_Compound.hpp:375
std::pair< typename Compound::iterator, bool > TryPut(K &&sTagName, V &&vTagVal)
原位构造键值对
定义 NBT_Compound.hpp:337
typename Compound::pointer Pointer
标准库容器公开类型映射
定义 NBT_Compound.hpp:45
std::pair< typename Compound::iterator, bool > Put(K &&sTagName, V &&vTagVal)
插入或替换键值对
定义 NBT_Compound.hpp:322
bool Remove(const typename Compound::key_type &sTagName)
删除指定标签
定义 NBT_Compound.hpp:345
typename Compound::node_type Node_Type
标准库容器公开类型映射
定义 NBT_Compound.hpp:53
用于格式化打印、序列化、计算哈希等功能
定义 NBT_Helper.hpp:25
这个类用于提供从NBT二进制流读取到NBT_Type::Compound对象的反序列化功能
定义 NBT_Reader.hpp:23
这个类用于提供从NBT_Type::Compound对象写出到NBT二进制流的序列化功能
定义 NBT_Writer.hpp:23
在std命名空间中添加类的默认hash特化以便unordered_map等容器自动获取
定义 NBT_String.hpp:456