Add short tag
This commit is contained in:
parent
09e0c5b9fa
commit
422f428fce
5 changed files with 101 additions and 2 deletions
|
@ -9,7 +9,7 @@ using namespace std;
|
|||
namespace nbt
|
||||
{
|
||||
|
||||
IntTag::IntTag() : Tag(), value(0.0)
|
||||
IntTag::IntTag() : Tag(), value(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ using namespace std;
|
|||
namespace nbt
|
||||
{
|
||||
|
||||
LongTag::LongTag() : Tag(), value(0.0)
|
||||
LongTag::LongTag() : Tag(), value(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
62
src/nbt/ShortTag.cpp
Normal file
62
src/nbt/ShortTag.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "ShortTag.h"
|
||||
|
||||
using namespace libac;
|
||||
using namespace std;
|
||||
|
||||
namespace nbt
|
||||
{
|
||||
|
||||
ShortTag::ShortTag() : Tag(), value(0)
|
||||
{
|
||||
}
|
||||
|
||||
ShortTag::ShortTag(short val) : Tag(), value(val)
|
||||
{
|
||||
}
|
||||
|
||||
void ShortTag::readValue(ByteLayer &data)
|
||||
{
|
||||
value = data.readShort();
|
||||
}
|
||||
|
||||
void ShortTag::writeValue(ByteLayer &data) const
|
||||
{
|
||||
data.writeShort(value);
|
||||
}
|
||||
|
||||
TagType ShortTag::getTagType() const
|
||||
{
|
||||
return TagType::Short;
|
||||
}
|
||||
|
||||
dynamic ShortTag::getValue() const
|
||||
{
|
||||
return dynamic(value);
|
||||
}
|
||||
|
||||
void ShortTag::setValue(const dynamic &val)
|
||||
{
|
||||
value = val.get<short>();
|
||||
}
|
||||
|
||||
void ShortTag::prettyPrint(int indent, bool recurse) const
|
||||
{
|
||||
cout << setw(indent) << setfill('\t') << Tag::getCanonicalName(getTagType()) << ": " << value;
|
||||
}
|
||||
|
||||
void ShortTag::writeStringifiedValue(StringBuilder &builder, int indent, bool isList) const
|
||||
{
|
||||
builder << (isList ? std::string(indent, '\t') : "") << value << "l";
|
||||
}
|
||||
|
||||
void ShortTag::readStringifiedValue(StringReader &reader)
|
||||
{
|
||||
float val = stoi(reader.readNumber());
|
||||
value = val;
|
||||
|
||||
reader.expect('s');
|
||||
}
|
||||
}
|
34
src/nbt/ShortTag.h
Normal file
34
src/nbt/ShortTag.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef SHORT_TAG_H
|
||||
#define SHORT_TAG_H
|
||||
|
||||
#include "Tag.h"
|
||||
#include "../utils/ByteLayer.h"
|
||||
#include "../utils/StringBuilder.h"
|
||||
#include "../utils/StringReader.h"
|
||||
#include "../types/dynamic.h"
|
||||
|
||||
namespace nbt
|
||||
{
|
||||
class ShortTag : public Tag
|
||||
{
|
||||
public:
|
||||
ShortTag();
|
||||
ShortTag(short val);
|
||||
~ShortTag();
|
||||
|
||||
// Function overrides
|
||||
void readValue(ByteLayer &data) override;
|
||||
void writeValue(ByteLayer &data) const override;
|
||||
TagType getTagType() const override;
|
||||
dynamic getValue() const override;
|
||||
void setValue(const dynamic &val) override;
|
||||
void prettyPrint(int indent, bool recurse) const override;
|
||||
void writeStringifiedValue(StringBuilder &builder, int indent, bool isList) const override;
|
||||
void readStringifiedValue(StringReader &reader) override;
|
||||
|
||||
private:
|
||||
short value;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -10,6 +10,7 @@
|
|||
#include "ListTag.h"
|
||||
#include "LongArrayTag.h"
|
||||
#include "LongTag.h"
|
||||
#include "ShortTag.h"
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -49,6 +50,8 @@ namespace nbt
|
|||
return new LongArrayTag();
|
||||
case TagType::Long:
|
||||
return new LongTag();
|
||||
case TagType::Short:
|
||||
return new ShortTag();
|
||||
default:
|
||||
// default handling
|
||||
return nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue