Solve compile error: Move helpers to their own class
This commit is contained in:
parent
b42899cde7
commit
3063bc0151
4 changed files with 244 additions and 208 deletions
185
src/nbt/Tag.cpp
185
src/nbt/Tag.cpp
|
@ -283,190 +283,5 @@ namespace nbt
|
|||
return ret;
|
||||
}
|
||||
|
||||
ByteTag Tag::asByte() const
|
||||
{
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ByteTag *TagPtr = dynamic_cast<const ByteTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ByteTag(0); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayTag Tag::asByteArray() const
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ByteArrayTag *TagPtr = dynamic_cast<const ByteArrayTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ByteArrayTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag Tag::asCompound() const
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const CompoundTag *TagPtr = dynamic_cast<const CompoundTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return CompoundTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
DoubleTag Tag::asDouble() const
|
||||
{
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const DoubleTag *TagPtr = dynamic_cast<const DoubleTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return DoubleTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
FloatTag Tag::asFloat() const
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const FloatTag *TagPtr = dynamic_cast<const FloatTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return FloatTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
IntArrayTag Tag::asIntArray() const
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const IntArrayTag *TagPtr = dynamic_cast<const IntArrayTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return IntArrayTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
IntTag Tag::asInt() const
|
||||
{
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const IntTag *TagPtr = dynamic_cast<const IntTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return IntTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
LongArrayTag Tag::asLongArray() const {
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const LongArrayTag *TagPtr = dynamic_cast<const LongArrayTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return LongArrayTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
LongTag Tag::asLong() const {
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const LongTag *TagPtr = dynamic_cast<const LongTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return LongTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
ShortTag Tag::asShort() const {
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ShortTag *TagPtr = dynamic_cast<const ShortTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ShortTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
ListTag Tag::asList() const {
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ListTag *TagPtr = dynamic_cast<const ListTag *>(this);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ListTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -5,18 +5,6 @@
|
|||
#include <vector>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include "EndTag.h"
|
||||
#include "ByteTag.h"
|
||||
#include "ByteArrayTag.h"
|
||||
#include "DoubleTag.h"
|
||||
#include "FloatTag.h"
|
||||
#include "CompoundTag.h"
|
||||
#include "IntArrayTag.h"
|
||||
#include "IntTag.h"
|
||||
#include "ListTag.h"
|
||||
#include "LongArrayTag.h"
|
||||
#include "LongTag.h"
|
||||
#include "ShortTag.h"
|
||||
#include "../utils/ByteLayer.h"
|
||||
#include "../utils/StringBuilder.h"
|
||||
#include "../utils/StringReader.h"
|
||||
|
@ -129,17 +117,6 @@ namespace nbt
|
|||
bool shouldQuoteName();
|
||||
static bool shouldQuote(const string &value);
|
||||
|
||||
ByteTag asByte() const;
|
||||
ByteArrayTag asByteArray() const;
|
||||
CompoundTag asCompound() const;
|
||||
DoubleTag asDouble() const;
|
||||
FloatTag asFloat() const;
|
||||
IntArrayTag asIntArray() const;
|
||||
IntTag asInt() const;
|
||||
LongArrayTag asLongArray() const;
|
||||
LongTag asLong() const;
|
||||
ShortTag asShort() const;
|
||||
ListTag asList() const;
|
||||
|
||||
protected:
|
||||
Tag *_parentTag;
|
||||
|
|
206
src/nbt/TagHelper.cpp
Normal file
206
src/nbt/TagHelper.cpp
Normal file
|
@ -0,0 +1,206 @@
|
|||
#include "TagHelper.h"
|
||||
|
||||
#include "EndTag.h"
|
||||
#include "ByteTag.h"
|
||||
#include "ByteArrayTag.h"
|
||||
#include "DoubleTag.h"
|
||||
#include "FloatTag.h"
|
||||
#include "CompoundTag.h"
|
||||
#include "IntArrayTag.h"
|
||||
#include "IntTag.h"
|
||||
#include "ListTag.h"
|
||||
#include "LongArrayTag.h"
|
||||
#include "LongTag.h"
|
||||
#include "ShortTag.h"
|
||||
|
||||
namespace nbt
|
||||
{
|
||||
ByteTag TagHelper::asByte(Tag* tag)
|
||||
{
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ByteTag *TagPtr = dynamic_cast<const ByteTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ByteTag(0); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayTag TagHelper::asByteArray(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ByteArrayTag *TagPtr = dynamic_cast<const ByteArrayTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ByteArrayTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag TagHelper::asCompound(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const CompoundTag *TagPtr = dynamic_cast<const CompoundTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return CompoundTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
DoubleTag TagHelper::asDouble(Tag* tag)
|
||||
{
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const DoubleTag *TagPtr = dynamic_cast<const DoubleTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return DoubleTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
FloatTag TagHelper::asFloat(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const FloatTag *TagPtr = dynamic_cast<const FloatTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return FloatTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
IntArrayTag TagHelper::asIntArray(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const IntArrayTag *TagPtr = dynamic_cast<const IntArrayTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return IntArrayTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
IntTag TagHelper::asInt(Tag* tag)
|
||||
{
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const IntTag *TagPtr = dynamic_cast<const IntTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return IntTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
LongArrayTag TagHelper::asLongArray(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const LongArrayTag *TagPtr = dynamic_cast<const LongArrayTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return LongArrayTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
LongTag TagHelper::asLong(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const LongTag *TagPtr = dynamic_cast<const LongTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return LongTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
ShortTag TagHelper::asShort(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ShortTag *TagPtr = dynamic_cast<const ShortTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ShortTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
|
||||
ListTag TagHelper::asList(Tag* tag)
|
||||
{
|
||||
|
||||
// Use dynamic_cast to safely cast to Tag
|
||||
const ListTag *TagPtr = dynamic_cast<const ListTag *>(tag);
|
||||
|
||||
if (TagPtr != nullptr)
|
||||
{
|
||||
// If the cast was successful, return the Tag object
|
||||
return *TagPtr;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle the case where the cast fails; return a default Tag
|
||||
return ListTag(); // You should handle this appropriately based on your design
|
||||
}
|
||||
}
|
||||
}
|
38
src/nbt/TagHelper.h
Normal file
38
src/nbt/TagHelper.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef TAG_HELPER_H
|
||||
#define TAG_HELPER_H
|
||||
|
||||
#include "Tag.h"
|
||||
#include "EndTag.h"
|
||||
#include "ByteTag.h"
|
||||
#include "ByteArrayTag.h"
|
||||
#include "DoubleTag.h"
|
||||
#include "FloatTag.h"
|
||||
#include "CompoundTag.h"
|
||||
#include "IntArrayTag.h"
|
||||
#include "IntTag.h"
|
||||
#include "ListTag.h"
|
||||
#include "LongArrayTag.h"
|
||||
#include "LongTag.h"
|
||||
#include "ShortTag.h"
|
||||
|
||||
namespace nbt
|
||||
{
|
||||
|
||||
class TagHelper
|
||||
{
|
||||
public:
|
||||
static ByteTag asByte(Tag* tag);
|
||||
static ByteArrayTag asByteArray(Tag* tag);
|
||||
static CompoundTag asCompound(Tag* tag);
|
||||
static DoubleTag asDouble(Tag* tag);
|
||||
static FloatTag asFloat(Tag* tag);
|
||||
static IntArrayTag asIntArray(Tag* tag);
|
||||
static IntTag asInt(Tag* tag);
|
||||
static LongArrayTag asLongArray(Tag* tag);
|
||||
static LongTag asLong(Tag* tag);
|
||||
static ShortTag asShort(Tag* tag);
|
||||
static ListTag asList(Tag* tag);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue