Class endstone::nbt::Tag¶
ClassList > endstone > nbt > Tag
A single NBT tag that may hold any of the supported payload types. More...
#include <endstone/nbt/tag.h>
Public Types¶
| Type | Name |
|---|---|
| typedef std::variant< std::monostate, ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag, StringTag, ByteArrayTag, IntArrayTag, ListTag, CompoundTag > | Storage |
Public Functions¶
| Type | Name |
|---|---|
| Tag () noexcept |
|
| Tag (const ByteTag & v) |
|
| Tag (ByteTag && v) |
|
| Tag (const ShortTag & v) |
|
| Tag (ShortTag && v) |
|
| Tag (const IntTag & v) |
|
| Tag (IntTag && v) |
|
| Tag (const LongTag & v) |
|
| Tag (LongTag && v) |
|
| Tag (const FloatTag & v) |
|
| Tag (FloatTag && v) |
|
| Tag (const DoubleTag & v) |
|
| Tag (DoubleTag && v) |
|
| Tag (const StringTag & v) |
|
| Tag (StringTag && v) |
|
| Tag (const ByteArrayTag & v) |
|
| Tag (ByteArrayTag && v) |
|
| Tag (const IntArrayTag & v) |
|
| Tag (IntArrayTag && v) |
|
| Tag (const ListTag & v) |
|
| Tag (ListTag && v) |
|
| Tag (const CompoundTag & v) |
|
| Tag (CompoundTag && v) |
|
| Tag & | at (const std::string & key) Access the child tag with the given key, treating this tag as a compound, with bounds checking. |
| const Tag & | at (const std::string & key) const Access the child tag with the given key, treating this tag as a compound, with bounds checking. |
| Tag & | at (std::size_t index) Access the child tag at the given index, treating this tag as a list, with bounds checking. |
| const Tag & | at (std::size_t index) const Access the child tag at the given index, treating this tag as a list, with bounds checking. |
| bool | contains (const std::string & key) noexcept const Check whether this tag is a compound containing the given key. |
| std::string | dump (std::endian byte_order=std::endian::little, bool network=false) const Serialize this tag to binary NBT with an empty root name. |
| std::string | dump (const std::string & name, std::endian byte_order=std::endian::little, bool network=false) const Serialize this tag to binary NBT with a root name. |
| std::pair< CompoundTag::iterator, bool > | emplace (Args &&... args) Construct an entry in place in this compound. |
| ListTag & | emplace_back (Args &&... args) Construct a child tag in place at the end of this list. |
| bool | empty () noexcept const Check whether this tag holds no elements. |
| T & | get () Get the payload as the given tag type. |
| const T & | get () const Get the payload as the given tag type. |
| T * | get_if () noexcept Get a pointer to the payload if this tag holds the given type. |
| const T * | get_if () noexcept const Get a pointer to the payload if this tag holds the given type. |
| Tag & | operator[] (const std::string & key) Access the child tag with the given key, treating this tag as a compound. |
| Tag & | operator[] (std::size_t index) Access the child tag at the given index, treating this tag as a list. |
| std::size_t | size () noexcept const Get the number of elements held by this tag. |
| Type | type () noexcept const Get the type of payload currently held by this tag. |
| decltype(auto) | visit (Fn && visitor) const Apply a visitor to the payload currently held by this tag. |
| decltype(auto) | visit (Fn && visitor) Apply a visitor to the payload currently held by this tag. |
Detailed Description¶
A Tag behaves as a tagged union over every NBT type (byte, short, int, long, float, double, string, byte array, int array, list and compound). A default-constructed Tag is empty (the End type). Indexing or inserting into an empty Tag promotes it to a ListTag or CompoundTag as appropriate.
Public Types Documentation¶
typedef Storage¶
using endstone::nbt::Tag::Storage = std::variant<std::monostate, ByteTag, ShortTag, IntTag, LongTag, FloatTag, DoubleTag, StringTag, ByteArrayTag, IntArrayTag, ListTag, CompoundTag>;
Public Functions Documentation¶
function Tag [1/23]¶
function Tag [2/23]¶
function Tag [3/23]¶
function Tag [4/23]¶
function Tag [5/23]¶
function Tag [6/23]¶
function Tag [7/23]¶
function Tag [8/23]¶
function Tag [9/23]¶
function Tag [10/23]¶
function Tag [11/23]¶
function Tag [12/23]¶
function Tag [13/23]¶
function Tag [14/23]¶
function Tag [15/23]¶
function Tag [16/23]¶
function Tag [17/23]¶
function Tag [18/23]¶
function Tag [19/23]¶
function Tag [20/23]¶
function Tag [21/23]¶
function Tag [22/23]¶
function Tag [23/23]¶
function at [¼]¶
Access the child tag with the given key, treating this tag as a compound, with bounds checking.
An empty tag is promoted to a CompoundTag.
Parameters:
keythe key to access
Returns:
a reference to the child tag
Exception:
std::runtime_errorif this tag is not a compoundstd::out_of_rangeif the key is not present
function at [2/4]¶
Access the child tag with the given key, treating this tag as a compound, with bounds checking.
Parameters:
keythe key to access
Returns:
a const reference to the child tag
Exception:
std::runtime_errorif this tag is not a compoundstd::out_of_rangeif the key is not present
function at [¾]¶
Access the child tag at the given index, treating this tag as a list, with bounds checking.
An empty tag is promoted to a ListTag.
Parameters:
indexthe index to access
Returns:
a reference to the child tag
Exception:
std::runtime_errorif this tag is not a liststd::out_of_rangeif the index is out of range
function at [4/4]¶
Access the child tag at the given index, treating this tag as a list, with bounds checking.
Parameters:
indexthe index to access
Returns:
a const reference to the child tag
Exception:
std::runtime_errorif this tag is not a liststd::out_of_rangeif the index is out of range
function contains¶
Check whether this tag is a compound containing the given key.
Parameters:
keythe key to look up
Returns:
true if this tag is a compound and contains the key, false otherwise
function dump [½]¶
Serialize this tag to binary NBT with an empty root name.
inline std::string endstone::nbt::Tag::dump (
std::endian byte_order=std::endian::little,
bool network=false
) const
Parameters:
byte_orderstd::endian::little (Bedrock) or std::endian::big (Java).networkIftrue, use Bedrock network varint encoding.
Returns:
Binary NBT data.
See also: endstone::nbt::dump(), endstone::nbt::load()
function dump [2/2]¶
Serialize this tag to binary NBT with a root name.
inline std::string endstone::nbt::Tag::dump (
const std::string & name,
std::endian byte_order=std::endian::little,
bool network=false
) const
Parameters:
nameThe root tag name.byte_orderstd::endian::little (Bedrock) or std::endian::big (Java).networkIftrue, use Bedrock network varint encoding.
Returns:
Binary NBT data.
function emplace¶
Construct an entry in place in this compound.
template<class... Args>
inline std::pair< CompoundTag::iterator, bool > endstone::nbt::Tag::emplace (
Args &&... args
)
An empty tag is promoted to a CompoundTag.
Parameters:
argsthe arguments forwarded to construct the key/value entry
Returns:
a pair of an iterator to the entry and a bool that is true if a new entry was inserted
Exception:
std::runtime_errorif this tag is not a compound
function emplace_back¶
Construct a child tag in place at the end of this list.
An empty tag is promoted to a ListTag.
Parameters:
argsthe arguments forwarded to the element constructor
Returns:
a reference to this tag's underlying list
Exception:
std::runtime_errorif this tag is not a list
function empty¶
Check whether this tag holds no elements.
Returns:
true if size() is 0
function get [½]¶
Get the payload as the given tag type.
Template parameters:
Tthe tag type to retrieve
Returns:
a reference to the held value
Exception:
std::runtime_errorif this tag does not currently hold a T
function get [2/2]¶
Get the payload as the given tag type.
Template parameters:
Tthe tag type to retrieve
Returns:
a const reference to the held value
Exception:
std::runtime_errorif this tag does not currently hold a T
function get_if [½]¶
Get a pointer to the payload if this tag holds the given type.
Template parameters:
Tthe tag type to retrieve
Returns:
a pointer to the held value, or nullptr if this tag does not hold a T
function get_if [2/2]¶
Get a pointer to the payload if this tag holds the given type.
Template parameters:
Tthe tag type to retrieve
Returns:
a const pointer to the held value, or nullptr if this tag does not hold a T
function operator[]¶
Access the child tag with the given key, treating this tag as a compound.
An empty tag is promoted to a CompoundTag, and a missing key is inserted with an empty value.
Parameters:
keythe key to access
Returns:
a reference to the child tag
Exception:
std::runtime_errorif this tag is not a compound
function operator[]¶
Access the child tag at the given index, treating this tag as a list.
An empty tag is promoted to a ListTag.
Parameters:
indexthe index to access
Returns:
a reference to the child tag
Exception:
std::runtime_errorif this tag is not a list
function size¶
Get the number of elements held by this tag.
For a list, compound or array this is the element count; for a string it is the character count; scalar tags report 1 and an empty tag reports 0.
Returns:
the element count
function type¶
Get the type of payload currently held by this tag.
Returns:
the tag type, or Type::End if the tag is empty
function visit [½]¶
Apply a visitor to the payload currently held by this tag.
Template parameters:
Fnthe visitor type, callable with any of the tag payload types (including std::monostate)
Parameters:
visitorthe visitor to invoke
Returns:
whatever the visitor returns
function visit [2/2]¶
Apply a visitor to the payload currently held by this tag.
Template parameters:
Fnthe visitor type, callable with any of the tag payload types (including std::monostate)
Parameters:
visitorthe visitor to invoke
Returns:
whatever the visitor returns
Friends Documentation¶
friend operator!=¶
friend operator==¶
The documentation for this class was generated from the following file include/endstone/nbt/tag.h