Fixes compile errors

This commit is contained in:
zontreck 2024-07-31 00:18:15 -07:00
parent baf7e47c25
commit 09e0c5b9fa
5 changed files with 25 additions and 11 deletions

View file

@ -8,7 +8,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_CXX_STANDARD_REQUIRED True)
# Add source files # Add source files
file(GLOB SOURCES "src/utils/*.cpp" "src/types/*.cpp") file(GLOB SOURCES "src/utils/*.cpp" "src/types/*.cpp" "src/nbt/*.cpp")
# Add an shared library target # Add an shared library target
add_library(ac SHARED ${SOURCES}) add_library(ac SHARED ${SOURCES})

View file

@ -9,7 +9,7 @@ all: clean build
build: build:
mkdir build mkdir build
cd build && cmake .. && make && mv libac.so .. cd build && cmake .. && make && mv libac.so .. && cd ..
# Clean up build artifacts # Clean up build artifacts
clean: clean:

View file

@ -81,8 +81,7 @@ namespace nbt
_parentTagType = type; _parentTagType = type;
} }
virtual void writeValue(ByteLayer &data) const = 0; virtual void readValue(ByteLayer &data);
virtual void readValue(ByteLayer &data) = 0;
std::string getKey() const std::string getKey() const
{ {
@ -95,7 +94,6 @@ namespace nbt
} }
virtual void writeStringifiedValue(StringBuilder &stream, int indent, bool isList) const = 0; virtual void writeStringifiedValue(StringBuilder &stream, int indent, bool isList) const = 0;
virtual void readStringifiedValue(StringReader &reader) = 0;
virtual void writeValue(ByteLayer &data) const; virtual void writeValue(ByteLayer &data) const;
virtual void setValue(const dynamic &val); virtual void setValue(const dynamic &val);
virtual void prettyPrint(int indent, bool recurse) const; virtual void prettyPrint(int indent, bool recurse) const;

View file

@ -7,8 +7,22 @@ using namespace std;
namespace libac namespace libac
{ {
dynamic::~dynamic()
{
// Properly destroy the union members if needed.
if (Type == 8)
{ // Assuming type 8 is std::string
x.str.~basic_string();
}
else if (Type == 9)
{ // Assuming type 9 is std::vector<uint8_t>
x.u8l.~vector();
}
}
template <class T> template <class T>
dynamic::dynamic(T y) dynamic::dynamic(T y) : Type(0)
{ {
if constexpr (std::is_same_v<T, char>) if constexpr (std::is_same_v<T, char>)
{ {
@ -55,15 +69,11 @@ namespace libac
Type = 9; Type = 9;
x.u8 = y; x.u8 = y;
} }
else if constexpr (std::is_same_v < T, vector<uint8_t>) else if constexpr (std::is_same_v<T, vector<uint8_t>>)
{ {
Type = 10; Type = 10;
x.u8l = y; x.u8l = y;
} }
else
{
static_assert(!std::is_same_v<T, T>, "Unsupported type for dynamic");
}
} }
template <class T> template <class T>
@ -115,6 +125,7 @@ namespace libac
} }
} }
/*
template dynamic::dynamic(char); template dynamic::dynamic(char);
template dynamic::dynamic(unsigned char); template dynamic::dynamic(unsigned char);
template dynamic::dynamic(short); template dynamic::dynamic(short);
@ -136,4 +147,6 @@ namespace libac
template std::string dynamic::get<std::string>() const; template std::string dynamic::get<std::string>() const;
template uint8_t dynamic::get<uint8_t>() const; template uint8_t dynamic::get<uint8_t>() const;
template vector<uint8_t> dynamic::get<vector<uint8_t>>() const; template vector<uint8_t> dynamic::get<vector<uint8_t>>() const;
*/
} }

View file

@ -23,6 +23,9 @@ namespace libac
string str; string str;
uint8_t u8; uint8_t u8;
vector<uint8_t> u8l; vector<uint8_t> u8l;
all() {} // Default constructor
~all() {} // Default destructor
}; };
class dynamic class dynamic