|
|
|
@ -44,6 +44,8 @@ namespace NBT
|
|
|
|
|
// Get uncompressed NBT binary data
|
|
|
|
|
const DataBuffer GetData() const; |
|
|
|
|
|
|
|
|
|
virtual const char* GetValueString() const; |
|
|
|
|
|
|
|
|
|
const char* ToString() const; |
|
|
|
|
|
|
|
|
|
operator bool() const; |
|
|
|
@ -104,10 +106,16 @@ namespace NBT
|
|
|
|
|
{ |
|
|
|
|
// Iterator for use in range-based for loops.
|
|
|
|
|
// TODO: this might not need to be a nested class
|
|
|
|
|
class iterator : public std::iterator<std::input_iterator_tag, T, int32_t, const T*, const T&> |
|
|
|
|
class iterator |
|
|
|
|
{ |
|
|
|
|
list_head* m_pos; |
|
|
|
|
public: |
|
|
|
|
using iterator_category = std::input_iterator_tag; |
|
|
|
|
using value_type = T; |
|
|
|
|
using difference_type = int32_t; |
|
|
|
|
using pointer = const T*; |
|
|
|
|
using reference = const T&; |
|
|
|
|
|
|
|
|
|
// TODO: could inline some of this
|
|
|
|
|
|
|
|
|
|
explicit iterator(ListTag<T>& tag, int32_t offset = 0) : m_pos(Internal::GetFirstItem(tag.m_node)) |
|
|
|
@ -135,6 +143,31 @@ namespace NBT
|
|
|
|
|
// A Compound Tag is an unordered list of named tags
|
|
|
|
|
class CompoundTag : public Tag |
|
|
|
|
{ |
|
|
|
|
// TODO: see ListTag::iterator
|
|
|
|
|
class iterator |
|
|
|
|
{ |
|
|
|
|
list_head* m_pos; |
|
|
|
|
public: |
|
|
|
|
using iterator_category = std::input_iterator_tag; |
|
|
|
|
using value_type = Tag; |
|
|
|
|
using difference_type = int32_t; |
|
|
|
|
using pointer = const Tag*; |
|
|
|
|
using reference = const Tag&; |
|
|
|
|
|
|
|
|
|
// TODO: could inline some of this
|
|
|
|
|
|
|
|
|
|
explicit iterator(CompoundTag& tag, int32_t offset = 0) : m_pos(Internal::GetFirstItem(tag.m_node)) |
|
|
|
|
{ |
|
|
|
|
// If we have an offset, call operator++ that number of times
|
|
|
|
|
for (int i = 0; i < offset; i++) { ++(*this); } |
|
|
|
|
} |
|
|
|
|
iterator& operator++() { m_pos = Internal::GetNextItem(m_pos); return *this; } |
|
|
|
|
bool operator==(iterator other) const { return m_pos == other.m_pos; } |
|
|
|
|
bool operator!=(iterator other) const { return !(*this == other); } |
|
|
|
|
Tag operator*() const { return Tag::CreateTag(Internal::GetListEntry(m_pos)); } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// only true if the tree was allocated by constructor
|
|
|
|
|
const bool m_isRoot; |
|
|
|
|
|
|
|
|
@ -159,6 +192,9 @@ namespace NBT
|
|
|
|
|
inline const CompoundTag GetCompound(const char* name) const { return Get<CompoundTag>(name); } |
|
|
|
|
|
|
|
|
|
const Tag operator[](const char* name) const; |
|
|
|
|
|
|
|
|
|
iterator begin() { return iterator(*this); } |
|
|
|
|
iterator end() { return iterator(*this, Tag::GetLength()); } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
|