4#include <unordered_map>
7#include <initializer_list>
63template<
typename Compound>
66 friend class NBT_Reader;
67 friend class NBT_Writer;
68 friend class NBT_Helper;
91 template<
typename... Args>
98 NBT_Compound(std::initializer_list<typename Compound::value_type> init) : Compound(init)
121 Compound::operator=(std::move(_Move));
130 Compound::operator=(_Copy);
147 return (
const Compound &)*
this == (
const Compound &)_Right;
156 return (
const Compound &)*
this != (
const Compound &)_Right;
173 return (
const Compound &)*this <=> (
const Compound &)_Right;
177 if (
auto _cmpSize = Compound::size() <=> _Right.size(); _cmpSize != 0)
184 const auto _rSort = _Right.KeySortIt();
185 typename Compound::size_type _Size = Compound::size();
187 for (
typename Compound::size_type _i = 0; _i < _Size; ++_i)
189 const auto &_lIt = _lSort[_i];
190 const auto &_rIt = _rSort[_i];
193 if (
auto _cmpKey = _lIt->first <=> _rIt->first; _cmpKey != 0)
199 if (
auto _cmpVal = _lIt->second <=> _rIt->second; _cmpVal != 0)
206 return std::partial_ordering::equivalent;
216 std::vector<typename Compound::iterator>
KeySortIt(
void)
218 std::vector<typename Compound::iterator> listSortIt;
219 listSortIt.reserve(Compound::size());
220 for (
auto it = Compound::begin(); it != Compound::end(); ++it)
222 listSortIt.push_back(it);
225 std::sort(listSortIt.begin(), listSortIt.end(),
226 [](
const auto &l,
const auto &r) ->
bool
228 return l->first < r->first;
241 std::vector<typename Compound::const_iterator>
KeySortIt(
void)
const
243 std::vector<typename Compound::const_iterator> listSortIt;
244 listSortIt.reserve(Compound::size());
245 for (
auto it = Compound::cbegin(); it != Compound::cend(); ++it)
247 listSortIt.push_back(it);
250 std::sort(listSortIt.begin(), listSortIt.end(),
251 [](
const auto &l,
const auto &r) ->
bool
253 return l->first < r->first;
265 using Compound::begin;
267 using Compound::cbegin;
268 using Compound::cend;
269 using Compound::operator[];
281 auto rbegin() const requires NBT_Compound_Concept::HasRBegin<
Compound> {
return Compound::rbegin();}
282 auto crbegin() const noexcept requires NBT_Compound_Concept::HasCRBegin<
Compound> {
return Compound::crbegin();}
284 auto rend()
requires NBT_Compound_Concept::HasREnd<
Compound> {
return Compound::rend();}
285 auto rend() const requires NBT_Compound_Concept::HasREnd<
Compound> {
return Compound::rend();}
286 auto crend() const noexcept requires NBT_Compound_Concept::HasCREnd<
Compound> {
return Compound::crend();}
297 typename Compound::mapped_type &
Get(
const typename Compound::key_type &sTagName)
299 return Compound::at(sTagName);
306 const typename Compound::mapped_type &
Get(
const typename Compound::key_type &sTagName)
const
308 return Compound::at(sTagName);
316 typename Compound::mapped_type *
Has(
const typename Compound::key_type &sTagName)
noexcept
318 auto find = Compound::find(sTagName);
319 return find == Compound::end()
328 const typename Compound::mapped_type *
Has(
const typename Compound::key_type &sTagName)
const noexcept
330 auto find = Compound::find(sTagName);
331 return find == Compound::end()
347 template <
typename K,
typename V>
348 requires std::constructible_from<typename Compound::key_type, K &&> &&std::constructible_from<typename Compound::mapped_type, V &&>
349 std::pair<typename Compound::iterator, bool>
Put(K &&sTagName, V &&vTagVal)
357 return Compound::insert_or_assign(std::forward<K>(sTagName), std::forward<V>(vTagVal));
368 template <
typename K,
typename V>
369 requires std::constructible_from<typename Compound::key_type, K &&> &&std::constructible_from<typename Compound::mapped_type, V &&>
370 std::pair<typename Compound::iterator, bool>
TryPut(K &&sTagName, V &&vTagVal)
378 return Compound::try_emplace(std::forward<K>(sTagName), std::forward<V>(vTagVal));
384 bool Remove(
const typename Compound::key_type &sTagName)
386 return Compound::erase(sTagName) != 0;
400 return Compound::empty();
405 typename Compound::size_type
Size(
void)
const noexcept
407 return Compound::size();
416 Compound::merge(_Copy);
425 Compound::merge(std::move(_Move));
431 bool Contains(
const typename Compound::key_type &sTagName)
const noexcept
433 return Compound::contains(sTagName);
441 template<
typename Predicate>
444 return std::find_if(Compound::begin(), Compound::end(), pred) != Compound::end();
454#define TYPE_GET_FUNC(type)\
461bool Contains##type(const typename Compound::key_type &sTagName) const\
463 auto *p = Has(sTagName);\
464 return p != NULL && p->GetTag() == NBT_TAG::type;\
474const typename NBT_Type::type &Get##type(const typename Compound::key_type & sTagName) const\
476 return Compound::at(sTagName).Get##type();\
486typename NBT_Type::type &Get##type(const typename Compound::key_type & sTagName)\
488 return Compound::at(sTagName).Get##type();\
497const typename NBT_Type::type *Has##type(const typename Compound::key_type & sTagName) const noexcept\
499 auto *p = Has(sTagName);\
500 return p != NULL && p->Is##type()\
511typename NBT_Type::type *Has##type(const typename Compound::key_type & sTagName) noexcept\
513 auto *p = Has(sTagName);\
514 return p != NULL && p->Is##type()\
546#define TYPE_PUT_FUNC(type)\
556template <typename K>\
557requires std::constructible_from<typename Compound::key_type, K &&>\
558std::pair<typename Compound::iterator, bool> Put##type(K &&sTagName, const typename NBT_Type::type &vTagVal)\
560 return Put(std::forward<K>(sTagName), vTagVal);\
572template <typename K>\
573requires std::constructible_from<typename Compound::key_type, K &&>\
574std::pair<typename Compound::iterator, bool> Put##type(K &&sTagName, typename NBT_Type::type &&vTagVal)\
576 return Put(std::forward<K>(sTagName), std::move(vTagVal));\
588template <typename K>\
589requires std::constructible_from<typename Compound::key_type, K &&>\
590std::pair<typename Compound::iterator, bool> TryPut##type(K &&sTagName, const typename NBT_Type::type &vTagVal)\
592 return TryPut(std::forward<K>(sTagName), vTagVal);\
604template <typename K>\
605requires std::constructible_from<typename Compound::key_type, K &&>\
606std::pair<typename Compound::iterator, bool> TryPut##type(K &&sTagName, typename NBT_Type::type &&vTagVal)\
608 return TryPut(std::forward<K>(sTagName), std::move(vTagVal));\
#define TYPE_PUT_FUNC(type)
不同类型名接口生成宏
定义 NBT_Compound.hpp:519
#define TYPE_GET_FUNC(type)
不同类型名接口生成宏
定义 NBT_Compound.hpp:454
@ 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:98
std::vector< typename Compound::const_iterator > KeySortIt(void) const
获取按键名排序的常量迭代器向量(常量版本)
定义 NBT_Compound.hpp:241
std::partial_ordering operator<=>(const NBT_Compound &_Right) const noexcept
三路比较运算符
定义 NBT_Compound.hpp:169
void Clear(void)
清空所有标签
定义 NBT_Compound.hpp:391
bool operator!=(const NBT_Compound &_Right) const noexcept
不等比较运算符
定义 NBT_Compound.hpp:154
NBT_Compound(void)=default
默认构造函数
NBT_Compound(NBT_Compound &&_Move) noexcept
移动构造函数
定义 NBT_Compound.hpp:108
NBT_Compound & operator=(const NBT_Compound &_Copy)
拷贝赋值运算符
定义 NBT_Compound.hpp:128
NBT_Compound & operator=(NBT_Compound &&_Move) noexcept
移动赋值运算符
定义 NBT_Compound.hpp:119
std::pair< typename Compound::iterator, bool > TryPut(K &&sTagName, V &&vTagVal)
原位构造键值对
定义 NBT_Compound.hpp:370
Compound::mapped_type & Get(const typename Compound::key_type &sTagName)
根据标签名获取对应的NBT值
定义 NBT_Compound.hpp:297
std::pair< typename Compound::iterator, bool > Put(K &&sTagName, V &&vTagVal)
插入或替换键值对
定义 NBT_Compound.hpp:349
void Merge(NBT_Compound &&_Move)
合并另一个NBT_Compound的内容(移动)
定义 NBT_Compound.hpp:423
const Compound & GetData(void) const noexcept
获取底层容器数据的常量引用
定义 NBT_Compound.hpp:136
const Compound::mapped_type * Has(const typename Compound::key_type &sTagName) const noexcept
搜索标签是否存在(常量版本)
定义 NBT_Compound.hpp:328
const Compound::mapped_type & Get(const typename Compound::key_type &sTagName) const
根据标签名获取对应的NBT值(常量版本)
定义 NBT_Compound.hpp:306
bool Empty(void) const noexcept
检查容器是否为空
定义 NBT_Compound.hpp:398
bool Contains(const typename Compound::key_type &sTagName) const noexcept
检查是否包含指定标签
定义 NBT_Compound.hpp:431
NBT_Compound(const NBT_Compound &_Copy) noexcept
拷贝构造函数
定义 NBT_Compound.hpp:113
bool operator==(const NBT_Compound &_Right) const noexcept
相等比较运算符
定义 NBT_Compound.hpp:145
NBT_Compound(Args &&... args)
完美转发构造函数
定义 NBT_Compound.hpp:92
~NBT_Compound(void)=default
默认析构函数
Compound::mapped_type * Has(const typename Compound::key_type &sTagName) noexcept
搜索标签是否存在
定义 NBT_Compound.hpp:316
bool ContainsIf(Predicate pred) const noexcept
使用谓词检查是否存在满足条件的元素
定义 NBT_Compound.hpp:442
std::vector< typename Compound::iterator > KeySortIt(void)
获取按键名排序的迭代器向量(非常量版本)
定义 NBT_Compound.hpp:216
Compound::size_type Size(void) const noexcept
获取容器中元素的数量
定义 NBT_Compound.hpp:405
void Merge(const NBT_Compound &_Copy)
合并另一个NBT_Compound的内容(拷贝)
定义 NBT_Compound.hpp:414
bool Remove(const typename Compound::key_type &sTagName)
删除指定标签
定义 NBT_Compound.hpp:384
用于格式化打印、序列化、计算哈希等功能
定义 NBT_Helper.hpp:25
这个类用于提供从NBT二进制流读取到NBT_Type::Compound对象的反序列化功能
定义 NBT_Reader.hpp:23
这个类用于提供从NBT_Type::Compound对象写出到NBT二进制流的序列化功能
定义 NBT_Writer.hpp:22
概念约束,检查类型T是否具有crbegin()成员函数
定义 NBT_Compound.hpp:40
概念约束,检查类型T是否具有crend()成员函数
定义 NBT_Compound.hpp:54
概念约束,检查类型T是否具有rbegin()成员函数
定义 NBT_Compound.hpp:33
概念约束,检查类型T是否具有rend()成员函数
定义 NBT_Compound.hpp:47
概念约束,检查类型T是否支持三路比较运算符(<=>)
定义 NBT_Compound.hpp:24
用于存放NBT_Compound使用的,无法存在于类内的概念
定义 NBT_Compound.hpp:21
在std命名空间中添加类的默认hash特化以便unordered_map等容器自动获取
定义 NBT_String.hpp:428