the whole game

This commit is contained in:
Kolyah35
2026-03-02 22:04:18 +03:00
parent 816e9060b4
commit f0617a5d22
2069 changed files with 581500 additions and 0 deletions

79
src/nbt/ByteArrayTag.h Executable file
View File

@@ -0,0 +1,79 @@
#ifndef COM_MOJANG_NBT__ByteArrayTag_H__
#define COM_MOJANG_NBT__ByteArrayTag_H__
//package com.mojang.nbt;
/* import java.io.* */
#include "Tag.h"
#include <string>
typedef struct TagMemoryChunk {
TagMemoryChunk()
: data(NULL),
len(0)
{}
void* data;
int len;
} TagMemoryChunk;
class ByteArrayTag: public Tag
{
typedef Tag super;
public:
TagMemoryChunk data;
ByteArrayTag(const std::string& name)
: super(name)
{
}
ByteArrayTag(const std::string& name, TagMemoryChunk data)
: super(name),
data(data)
{
}
char getId() const {
return TAG_Byte_Array;
}
std::string toString() const {
std::stringstream ss;
ss << "[" << data.len << " bytes]";
return ss.str();
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
ByteArrayTag& o = (ByteArrayTag&) rhs;
if (data.len != o.data.len)
return false;
return memcmp(data.data, o.data.data, data.len) == 0;
}
return false;
}
//@Override
Tag* copy() const {
TagMemoryChunk chunk;
chunk.data = new char[data.len];
memcpy(chunk.data, data.data, data.len);
return new ByteArrayTag(getName(), chunk);
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeInt(data.len);
dos->writeBytes(data.data, data.len);
}
void load(IDataInput* dis) /*throws IOException*/ {
int length = dis->readInt();
data.data = new char[length];
dis->readBytes(data.data, length);
}
};
#endif /*COM_MOJANG_NBT__ByteArrayTag_H__*/

57
src/nbt/ByteTag.h Executable file
View File

@@ -0,0 +1,57 @@
#ifndef COM_MOJANG_NBT__ByteTag_H__
#define COM_MOJANG_NBT__ByteTag_H__
//package com.mojang.nbt;
/* import java.io.* */
#include "Tag.h"
#include <string>
class ByteTag: public Tag
{
typedef Tag super;
public:
char data;
ByteTag(const std::string& name)
: super(name)
{}
ByteTag(const std::string& name, char data)
: super(name),
data(data)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeByte(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readByte();
}
char getId() const {
return TAG_Byte;
}
std::string toString() const {
return std::string(data, 1);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
return data == ((ByteTag&)rhs).data;
}
return false;
}
//@Override
Tag* copy() const {
return new ByteTag(getName(), data);
}
};
#endif /*COM_MOJANG_NBT__ByteTag_H__*/

242
src/nbt/CompoundTag.h Executable file
View File

@@ -0,0 +1,242 @@
#ifndef COM_MOJANG_NBT__CompoundTag_H__
#define COM_MOJANG_NBT__CompoundTag_H__
//package com.mojang.nbt;
#include "Tag.h"
#include <map>
#include <vector>
#include <iterator>
#include <algorithm>
#include "../util/CollectionUtils.h"
#include "ByteTag.h"
#include "ShortTag.h"
#include "IntTag.h"
#include "LongTag.h"
#include "FloatTag.h"
#include "DoubleTag.h"
#include "ListTag.h"
#include "StringTag.h"
#include "ByteArrayTag.h"
class CompoundTag: public Tag
{
typedef Tag super;
typedef std::map<std::string, Tag*> TagMap;
public:
CompoundTag()
: super("")
{
}
CompoundTag(const std::string& name)
: super(name)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
for (TagMap::iterator it = tags.begin(); it != tags.end(); ++it) {
Tag::writeNamedTag(it->second, dos);
}
dos->writeByte(Tag::TAG_End);
}
void load(IDataInput* dis) /*throws IOException*/ {
tags.clear();
Tag* tag = NULL;
while ((tag = Tag::readNamedTag(dis)) && tag->getId() != Tag::TAG_End) {
tags.insert(std::make_pair(tag->getName(), tag));
}
// <tag> is now of type TAG_End (that's new'ed). Delete it.
delete tag;
}
void getAllTags(std::vector<Tag*>& tags_) const {
//std::transform(tags.begin(), tags.end(), std::back_inserter(tags_), PairValueFunctor());
for (TagMap::const_iterator it = tags.begin(); it != tags.end(); ++it) {
tags_.push_back(it->second);
}
}
char getId() const {
return TAG_Compound;
}
void put(const std::string& name, Tag* tag) {
tags.insert(std::make_pair(name, tag->setName(name)));
}
void putByte(const std::string& name, char value) {
tags.insert(std::make_pair(name, new ByteTag(name, value)));
}
void putShort(const std::string& name, short value) {
tags.insert(std::make_pair(name, new ShortTag(name, value)));
}
void putInt(const std::string& name, int value) {
tags.insert(std::make_pair(name, new IntTag(name, value)));
}
void putLong(const std::string& name, long value) {
tags.insert(std::make_pair(name, new LongTag(name, value)));
}
void putFloat(const std::string& name, float value) {
tags.insert(std::make_pair(name, new FloatTag(name, value)));
}
void putDouble(const std::string& name, float value) {
tags.insert(std::make_pair(name, new DoubleTag(name, value)));
}
void putString(const std::string& name, const std::string& value) {
tags.insert(std::make_pair(name, new StringTag(name, value)));
}
void putByteArray(const std::string& name, TagMemoryChunk mem) {
tags.insert(std::make_pair(name, new ByteArrayTag(name, mem)));
}
void putCompound(const std::string& name, CompoundTag* value) {
tags.insert(std::make_pair(name, value->setName(name)));
}
void putBoolean(const std::string& string, bool val) {
putByte(string, val ? (char) 1 : 0);
}
Tag* get(const std::string& name) const {
TagMap::const_iterator it = tags.find(name);
if (it == tags.end())
return NULL;
return it->second;
}
__inline bool contains(const std::string& name) const {
return tags.find(name) != tags.end();
}
bool contains(const std::string& name, int type) const {
Tag* tag = get(name);
return tag && tag->getId() == type;
}
char getByte(const std::string& name) const {
if (!contains(name, TAG_Byte)) return (char) 0;
return ((ByteTag*) get(name))->data;
}
short getShort(const std::string& name) const {
if (!contains(name, TAG_Short)) return (short) 0;
return ((ShortTag*) get(name))->data;
}
int getInt(const std::string& name) const {
if (!contains(name, TAG_Int)) return (int) 0;
return ((IntTag*) get(name))->data;
}
long long getLong(const std::string& name) const {
if (!contains(name, TAG_Long)) return (long long) 0;
return ((LongTag*) get(name))->data;
}
float getFloat(const std::string& name) const {
if (!contains(name, TAG_Float)) return (float) 0;
return ((FloatTag*) get(name))->data;
}
double getDouble(const std::string& name) const {
if (!contains(name, TAG_Double)) return (double) 0;
return ((DoubleTag*) get(name))->data;
}
std::string getString(const std::string& name) const {
if (!contains(name, TAG_String)) return "";
return ((StringTag*) get(name))->data;
}
TagMemoryChunk getByteArray(const std::string& name) const {
if (!contains(name, TAG_Byte_Array)) return TagMemoryChunk();
return ((ByteArrayTag*) get(name))->data;
}
CompoundTag* getCompound(const std::string& name) const {
if (!contains(name, TAG_Compound)) return new CompoundTag(name);
return (CompoundTag*) get(name);
}
ListTag* getList(const std::string& name) const {
if (!contains(name, TAG_List)) return new ListTag(name);
return (ListTag*) get(name);
}
bool getBoolean(const std::string& string) const {
return getByte(string) != 0;
}
std::string toString() const {
std::stringstream ss;
ss << tags.size() << " entries";
return ss.str();
}
void print(const std::string& prefix_, PrintStream& out) const {
super::print(prefix_, out);
std::string prefix = prefix_;
out.print(prefix); out.println("{");
prefix += " ";
for (TagMap::const_iterator it = tags.begin(); it != tags.end(); ++it) {
(it->second)->print(prefix, out);
}
out.print(prefix_);
out.println("}");
}
bool isEmpty() const {
return tags.empty();
}
Tag* copy() const {
CompoundTag* tag = new CompoundTag(getName());
for (TagMap::const_iterator it = tags.begin(); it != tags.end(); ++it) {
//tag->put(it->first, get(it->first)->copy());
tag->put(it->first, it->second->copy());
}
return tag;
}
//@Override
bool equals(const Tag& obj) const {
if (super::equals(obj)) {
CompoundTag& o = (CompoundTag&) obj;
if (tags.size() != o.tags.size())
return false;
for (TagMap::const_iterator it = tags.begin(), jt = o.tags.begin(); it != tags.end(); ++it, ++jt) {
if (it->first != jt->first) return false;
if (!it->second->equals(*jt->second)) return false;
}
return true;
}
return false;
}
void deleteChildren() {
TagMap::iterator it = tags.begin();
for (; it != tags.end(); ++it) {
if (!it->second)
continue;
it->second->deleteChildren();
delete it->second;
}
}
private:
TagMap tags;
};
#endif /*COM_MOJANG_NBT__CompoundTag_H__*/

57
src/nbt/DoubleTag.h Executable file
View File

@@ -0,0 +1,57 @@
#ifndef COM_MOJANG_NBT__DoubleTag_H__
#define COM_MOJANG_NBT__DoubleTag_H__
//package com.mojang.nbt;
/* import java.io.* */
#include "Tag.h"
#include <sstream>
class DoubleTag: public Tag {
typedef Tag super;
public:
double data;
DoubleTag(const std::string& name)
: super(name)
{}
DoubleTag(const std::string& name, double data)
: super(name),
data(data)
{}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeDouble(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readDouble();
}
char getId() const {
return TAG_Double;
}
std::string toString() const {
std::stringstream ss;
ss << data;
return ss.str();
}
//@Override
Tag* copy() const {
return new DoubleTag(getName(), data);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
return data == ((DoubleTag&)rhs).data;
}
return false;
}
};
#endif /*COM_MOJANG_NBT__DoubleTag_H__*/

41
src/nbt/EndTag.h Executable file
View File

@@ -0,0 +1,41 @@
#ifndef COM_MOJANG_NBT__EndTag_H__
#define COM_MOJANG_NBT__EndTag_H__
//package com.mojang.nbt;
/* import java.io.* */
class EndTag: public Tag {
typedef Tag super;
public:
EndTag()
: super("")
{
}
void load(IDataInput* dis) /*throws IOException*/ {
}
void write(IDataOutput* dos) /*throws IOException*/ {
}
char getId() const {
return TAG_End;
}
std::string toString() const {
return "END";
}
//@Override
Tag* copy() const {
return new EndTag();
}
//@Override
bool equals(const Tag& rhs) const {
return super::equals(rhs);
}
};
#endif /*COM_MOJANG_NBT__EndTag_H__*/

59
src/nbt/FloatTag.h Executable file
View File

@@ -0,0 +1,59 @@
#ifndef COM_MOJANG_NBT__FloatTag_H__
#define COM_MOJANG_NBT__FloatTag_H__
//package com.mojang.nbt;
/* import java.io.* */
#include "Tag.h"
#include <sstream>
class FloatTag: public Tag {
typedef Tag super;
public:
float data;
FloatTag(const std::string& name)
: super(name)
{
}
FloatTag(const std::string& name, float data)
: super(name),
data(data)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeFloat(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readFloat();
}
char getId() const {
return TAG_Float;
}
std::string toString() const {
std::stringstream ss;
ss << data;
return ss.str();
}
//@Override
Tag* copy() const {
return new FloatTag(getName(), data);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
return data == ((FloatTag&)rhs).data;
}
return false;
}
};
#endif /*COM_MOJANG_NBT__FloatTag_H__*/

58
src/nbt/IntTag.h Executable file
View File

@@ -0,0 +1,58 @@
#ifndef COM_MOJANG_NBT__IntTag_H__
#define COM_MOJANG_NBT__IntTag_H__
//package com.mojang.nbt;
#include "Tag.h"
#include <sstream>
/* import java.io.* */
class IntTag: public Tag {
typedef Tag super;
public:
int data;
IntTag(const std::string& name)
: super(name)
{
}
IntTag(const std::string& name, int data)
: super(name),
data(data)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeInt(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readInt();
}
char getId() const {
return TAG_Int;
}
std::string toString() const {
std::stringstream ss;
ss << data;
return ss.str();
}
//@Override
Tag* copy() const {
return new IntTag(getName(), data);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
return data == ((IntTag&)rhs).data;
}
return false;
}
};
#endif /*COM_MOJANG_NBT__IntTag_H__*/

171
src/nbt/ListTag.h Executable file
View File

@@ -0,0 +1,171 @@
#ifndef COM_MOJANG_NBT__ListTag_H__
#define COM_MOJANG_NBT__ListTag_H__
//package com.mojang.nbt;
#include "Tag.h"
#include <vector>
//template <class T>
class ListTag: public Tag
{
typedef Tag super;
typedef Tag* T;
typedef std::vector<T> List;
public:
ListTag()
: super("")
{
}
ListTag(const std::string& name)
: super(name)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
if (list.size() > 0) type = list.front()->getId();
else type = TAG_Byte;
dos->writeByte(type);
dos->writeInt(list.size());
for (List::iterator it = list.begin(); it != list.end(); ++it) {
(*it)->write(dos);
}
}
//@SuppressWarnings("unchecked")
void load(IDataInput* dis) /*throws IOException*/ {
type = dis->readByte();
int size = dis->readInt();
list.clear();// = List();
for (int i = 0; i < size; i++) {
Tag* tag = Tag::newTag(type, NullString);
tag->load(dis);
list.insert(list.end(), tag);
}
}
char getId() const {
return TAG_List;
}
std::string toString() const {
std::stringstream ss;
ss << list.size() << " entries of type " << Tag::getTagName(type);
return ss.str();
}
void print(const std::string& prefix_, PrintStream& out) const {
super::print(prefix_, out);
std::string prefix = prefix_;
out.print(prefix); out.println("{");
prefix += " ";
for (List::const_iterator it = list.begin(); it != list.end(); ++it) {
(*it)->print(prefix, out);
}
out.print(prefix_); out.println("}");
}
void add(T tag) {
type = tag->getId();
list.insert(list.end(), tag);
}
T get(int index) const {
if (index >= size()) {
errorState |= TAGERR_OUT_OF_BOUNDS;
return NULL;
}
return *(list.begin() + index);
}
float getFloat(int index) {
T tag = get(index);
if (!tag)
return 0;
if (tag->getId() != TAG_Float) {
errorState |= TAGERR_BAD_TYPE;
return 0;
}
return ((FloatTag*)tag)->data;
}
int size() const {
return list.size();
}
//@Override
Tag* copy() const {
ListTag* res = new ListTag(getName());
res->type = type;
for (List::const_iterator it = list.begin(); it != list.end(); ++it) {
T copy = (*it)->copy();
res->list.insert(res->list.end(), copy);
}
return res;
}
//@SuppressWarnings("rawtypes")
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
ListTag& o = (ListTag&) rhs;
if (type == o.type && list.size() == o.list.size()) {
for (List::const_iterator it = list.begin(), jt = o.list.begin(); it != list.end(); ++it, ++jt) {
if ((*it)->equals(**jt))
return false;
}
return true;
}
}
return false;
}
void deleteChildren() {
for (List::iterator it = list.begin(); it != list.end(); ++it) {
if (*it) {
(*it)->deleteChildren();
delete (*it);
}
}
}
private:
List list;
char type;
};
class ListTagFloatAdder {
public:
ListTagFloatAdder()
: tag(NULL)
{}
ListTagFloatAdder(float f)
: tag(NULL)
{
operator() (f);
}
ListTagFloatAdder(ListTag* tag)
: tag(tag)
{}
ListTagFloatAdder& operator() (const std::string& name, float f) {
if (!tag) tag = new ListTag();
tag->add( new FloatTag(name, f) );
return *this;
}
ListTagFloatAdder& operator() (float f) {
return operator() ("", f);
}
ListTag* tag;
};
#endif /*COM_MOJANG_NBT__ListTag_H__*/

56
src/nbt/LongTag.h Executable file
View File

@@ -0,0 +1,56 @@
#ifndef COM_MOJANG_NBT__LongTag_H__
#define COM_MOJANG_NBT__LongTag_H__
//package com.mojang.nbt;
#include "Tag.h"
#include <sstream>
class LongTag: public Tag {
typedef Tag super;
public:
long long data;
LongTag(const std::string& name)
: super(name)
{
}
LongTag(const std::string& name, long long data)
: super(name),
data(data)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeLongLong(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readLongLong();
}
char getId() const {
return TAG_Long;
}
std::string toString() const {
std::stringstream ss;
ss << data;
return ss.str();
}
//@Override
Tag* copy() const {
return new LongTag(getName(), data);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
return data == ((LongTag&)rhs).data;
}
return false;
}
};
#endif /*COM_MOJANG_NBT__LongTag_H__*/

26
src/nbt/NbtIo.h Executable file
View File

@@ -0,0 +1,26 @@
#ifndef COM_MOJANG_NBT__NbtIo_H__
#define COM_MOJANG_NBT__NbtIo_H__
//package com.mojang.nbt;
#include "CompoundTag.h"
#include "../util/DataIO.h"
class NbtIo
{
public:
static CompoundTag* read(IDataInput* dis) {
Tag *tag = Tag::readNamedTag(dis);
if (tag && tag->getId() == Tag::TAG_Compound)
return (CompoundTag*) tag;
return NULL;
}
static bool write(CompoundTag* tag, IDataOutput* dos) {
if (!tag) return false;
Tag::writeNamedTag(tag, dos);
return false;
}
};
#endif /*COM_MOJANG_NBT__NbtIo_H__*/

59
src/nbt/ShortTag.h Executable file
View File

@@ -0,0 +1,59 @@
#ifndef COM_MOJANG_NBT__ShortTag_H__
#define COM_MOJANG_NBT__ShortTag_H__
//package com.mojang.nbt;
/* import java.io.* */
#include "Tag.h"
#include <sstream>
class ShortTag: public Tag {
typedef Tag super;
public:
short data;
ShortTag(const std::string& name)
: super(name)
{
}
ShortTag(const std::string& name, short data)
: super(name),
data(data)
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeShort(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readShort();
}
char getId() const {
return TAG_Short;
}
std::string toString() const {
std::stringstream ss;
ss << data;
return ss.str();
}
//@Override
Tag* copy() const {
return new ShortTag(getName(), data);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
return data == ((ShortTag&)rhs).data;
}
return false;
}
};
#endif /*COM_MOJANG_NBT__ShortTag_H__*/

62
src/nbt/StringTag.h Executable file
View File

@@ -0,0 +1,62 @@
#ifndef COM_MOJANG_NBT__StringTag_H__
#define COM_MOJANG_NBT__StringTag_H__
//package com.mojang.nbt;
#include "Tag.h"
#include <sstream>
class StringTag: public Tag
{
typedef Tag super;
public:
std::string data;
int len;
StringTag(const std::string& name)
: super(name),
len(name.length())
{
}
StringTag(const std::string& name, const std::string& data)
: super(name),
data(data),
len(name.length())
{
}
void write(IDataOutput* dos) /*throws IOException*/ {
dos->writeString(data);
}
void load(IDataInput* dis) /*throws IOException*/ {
data = dis->readString(); // just a tiny bit slower, but safer
}
char getId() const {
return TAG_String;
}
std::string toString() const {
std::stringstream ss;
ss << data;
return ss.str();
}
//@Override
Tag* copy() const {
return new StringTag(getName(), data);
}
//@Override
bool equals(const Tag& rhs) const {
if (super::equals(rhs)) {
StringTag& o = (StringTag&) rhs;
return data == o.data;
}
return false;
}
};
#endif /*COM_MOJANG_NBT__StringTag_H__*/

139
src/nbt/Tag.cpp Executable file
View File

@@ -0,0 +1,139 @@
#include "Tag.h"
#include "EndTag.h"
#include "ByteTag.h"
#include "ShortTag.h"
#include "IntTag.h"
#include "LongTag.h"
#include "FloatTag.h"
#include "DoubleTag.h"
#include "ByteArrayTag.h"
#include "StringTag.h"
#include "ListTag.h"
#include "CompoundTag.h"
/*static*/ const std::string Tag::NullString = "";
Tag::Tag(const std::string& name)
: name(name),
errorState(0)
{
}
/*virtual*/
bool Tag::equals(const Tag& rhs) const {
return getId() == rhs.getId()
&& name == rhs.name;
}
/*virtual*/
void Tag::print(PrintStream& out) const {
print("", out);
}
/*virtual*/
void Tag::print(const std::string& prefix, PrintStream& out) const {
std::string name = getName();
out.print(prefix);
out.print(getTagName(getId()));
if (name.length() > 0) {
out.print("(\"" + name + "\")");
}
out.print(": ");
out.println(toString());
}
/*virtual*/
Tag* Tag::setName(const std::string& name) {
this->name = name;
return this;
}
/*virtual*/
std::string Tag::getName() const {
return name;
}
/*static*/
Tag* Tag::readNamedTag(IDataInput* dis) /*throws IOException*/ {
char type = dis->readByte();
if (type == Tag::TAG_End) return new EndTag();
Tag* tag = newTag(type, dis->readString());
if (!tag)
return NULL;
tag->load(dis);
return tag;
}
/*static*/
void Tag::writeNamedTag(Tag* tag, IDataOutput* dos) /*throws IOException*/ {
dos->writeByte(tag->getId());
if (tag->getId() == Tag::TAG_End) return;
dos->writeString(tag->getName());
tag->write(dos);
}
/*static*/
Tag* Tag::newTag(char type, const std::string& name)
{
switch (type) {
case TAG_End:
return new EndTag();
case TAG_Byte:
return new ByteTag(name);
case TAG_Short:
return new ShortTag(name);
case TAG_Int:
return new IntTag(name);
case TAG_Long:
return new LongTag(name);
case TAG_Float:
return new FloatTag(name);
case TAG_Double:
return new DoubleTag(name);
case TAG_Byte_Array:
return new ByteArrayTag(name);
case TAG_String:
return new StringTag(name);
case TAG_List:
return new ListTag(name);
case TAG_Compound:
return new CompoundTag(name);
}
return NULL;
}
/*static*/
std::string Tag::getTagName(char type) {
switch (type) {
case TAG_End:
return "TAG_End";
case TAG_Byte:
return "TAG_Byte";
case TAG_Short:
return "TAG_Short";
case TAG_Int:
return "TAG_Int";
case TAG_Long:
return "TAG_Long";
case TAG_Float:
return "TAG_Float";
case TAG_Double:
return "TAG_Double";
case TAG_Byte_Array:
return "TAG_Byte_Array";
case TAG_String:
return "TAG_String";
case TAG_List:
return "TAG_List";
case TAG_Compound:
return "TAG_Compound";
}
return "UNKNOWN";
}

65
src/nbt/Tag.h Executable file
View File

@@ -0,0 +1,65 @@
#ifndef COM_MOJANG_NBT__Tag_H__
#define COM_MOJANG_NBT__Tag_H__
//package com.mojang.nbt;
/* import java.io.* */
#include "../util/DataIO.h"
#include <string>
class Tag
{
public:
virtual ~Tag() {}
virtual void deleteChildren() {}
static const char TAG_End = 0;
static const char TAG_Byte = 1;
static const char TAG_Short = 2;
static const char TAG_Int = 3;
static const char TAG_Long = 4;
static const char TAG_Float = 5;
static const char TAG_Double = 6;
static const char TAG_Byte_Array= 7;
static const char TAG_String = 8;
static const char TAG_List = 9;
static const char TAG_Compound = 10;
static const std::string NullString;
virtual void write(IDataOutput* dos) = 0; ///*throws IOException*/;
virtual void load(IDataInput* dis) = 0; ///*throws IOException*/;
virtual std::string toString() const = 0;
virtual char getId() const = 0;
virtual bool equals(const Tag& rhs) const;
virtual void print(PrintStream& out) const;
virtual void print(const std::string& prefix, PrintStream& out) const;
virtual Tag* setName(const std::string& name);
virtual std::string getName() const;
static Tag* readNamedTag(IDataInput* dis);
static void writeNamedTag(Tag* tag, IDataOutput* dos);
static Tag* newTag(char type, const std::string& name);
static std::string getTagName(char type);
virtual Tag* copy() const = 0;
mutable int errorState;
static const int TAGERR_OUT_OF_BOUNDS = 1;
static const int TAGERR_BAD_TYPE = 2;
protected:
Tag(const std::string& name);
private:
std::string name;
};
#endif /*COM_MOJANG_NBT__Tag_H__*/