BAN: Cleanup includes

This commit is contained in:
Bananymous 2023-01-17 11:38:16 +02:00
parent a7a55cd0fb
commit cf63552b2a
9 changed files with 75 additions and 65 deletions

13
BAN/BAN/Memory.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <BAN/Memory.h>
namespace std { enum class align_val_t : size_t {}; }
void* operator new(size_t size) { return BAN::allocator(size); }
void* operator new[](size_t size) { return BAN::allocator(size); }
void* operator new(size_t size, std::align_val_t align) { return BAN::allocator_align(size, (size_t)align); }
void* operator new[](size_t size, std::align_val_t align) { return BAN::allocator_align(size, (size_t)align); }
void operator delete(void* addr) { BAN::deallocator(addr); }
void operator delete[](void* addr) { BAN::deallocator(addr); }
void operator delete(void* addr, size_t) { BAN::deallocator(addr); }
void operator delete[](void* addr, size_t) { BAN::deallocator(addr); }

View File

@ -1,5 +1,6 @@
#include <BAN/Errors.h> #include <BAN/Errors.h>
#include <BAN/Math.h> #include <BAN/Math.h>
#include <BAN/Memory.h>
#include <BAN/Move.h> #include <BAN/Move.h>
#include <BAN/String.h> #include <BAN/String.h>
#include <BAN/StringView.h> #include <BAN/StringView.h>

View File

@ -31,6 +31,7 @@ BUILDDIR=$(abspath build)
FREEOBJS= \ FREEOBJS= \
$(ARCH_FREEOBJS) \ $(ARCH_FREEOBJS) \
BAN/Memory.o \
BAN/String.o \ BAN/String.o \
BAN/StringView.o \ BAN/StringView.o \

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <BAN/Formatter.h> #include <BAN/Formatter.h>
#include <BAN/Memory.h>
#include <string.h> #include <string.h>
@ -15,10 +14,12 @@
#define TRY(error) ({ auto e = error; if (e.IsError()) return e; e.Value(); }) #define TRY(error) ({ auto e = error; if (e.IsError()) return e; e.Value(); })
namespace BAN
class Error
{ {
public:
class Error
{
public:
static Error FromString(const char* message) static Error FromString(const char* message)
{ {
Error result; Error result;
@ -31,15 +32,15 @@ public:
uint8_t GetErrorCode() const { return m_error_code; } uint8_t GetErrorCode() const { return m_error_code; }
const char* GetMessage() const { return m_message; } const char* GetMessage() const { return m_message; }
private: private:
char m_message[128]; char m_message[128];
uint8_t m_error_code; uint8_t m_error_code;
}; };
template<typename T> template<typename T>
class ErrorOr class ErrorOr
{ {
public: public:
ErrorOr(const T& value) : m_has_error(false) { m_data = (void*)new T(value); } ErrorOr(const T& value) : m_has_error(false) { m_data = (void*)new T(value); }
ErrorOr(const Error& error) : m_has_error(true) { m_data = (void*)new Error(error); } ErrorOr(const Error& error) : m_has_error(true) { m_data = (void*)new Error(error); }
template<typename S> ErrorOr(const ErrorOr<S>& other) : ErrorOr(other.GetError()) {} template<typename S> ErrorOr(const ErrorOr<S>& other) : ErrorOr(other.GetError()) {}
@ -49,15 +50,15 @@ public:
const Error& GetError() const { return *reinterpret_cast<Error*>(m_data); } const Error& GetError() const { return *reinterpret_cast<Error*>(m_data); }
T& Value() { return *reinterpret_cast<T*>(m_data); } T& Value() { return *reinterpret_cast<T*>(m_data); }
private: private:
bool m_has_error = false; bool m_has_error = false;
void* m_data = nullptr; void* m_data = nullptr;
}; };
template<> template<>
class ErrorOr<void> class ErrorOr<void>
{ {
public: public:
ErrorOr() { } ErrorOr() { }
ErrorOr(const Error& error) : m_error(error) { } ErrorOr(const Error& error) : m_error(error) { }
~ErrorOr() { } ~ErrorOr() { }
@ -66,11 +67,12 @@ public:
const Error& GetError() const { return m_error; } const Error& GetError() const { return m_error; }
void Value() { } void Value() { }
private: private:
Error m_error; Error m_error;
bool m_has_error = false; bool m_has_error = false;
}; };
}
namespace BAN::Formatter namespace BAN::Formatter
{ {

View File

@ -1,14 +1,17 @@
#pragma once #pragma once
template<typename T> class ErrorOr; #include <stddef.h>
namespace BAN namespace BAN
{ {
template<typename, size_t> class Array;
template<typename> class ErrorOr;
template<typename> class Function;
template<typename> class Queue;
class String; class String;
class StringView; class StringView;
template<typename> class Vector;
template<typename T> class Vector;
template<typename T> class Queue;
} }

View File

@ -38,16 +38,5 @@ namespace BAN
} }
namespace std { enum class align_val_t : size_t {}; }
inline void* operator new(size_t size) { return BAN::allocator(size); }
inline void* operator new[](size_t size) { return BAN::allocator(size); }
inline void* operator new(size_t size, std::align_val_t align) { return BAN::allocator_align(size, (size_t)align); }
inline void* operator new[](size_t size, std::align_val_t align) { return BAN::allocator_align(size, (size_t)align); }
inline void* operator new(size_t, void* addr) { return addr; } inline void* operator new(size_t, void* addr) { return addr; }
inline void* operator new[](size_t, void* addr) { return addr; } inline void* operator new[](size_t, void* addr) { return addr; }
inline void operator delete(void* addr) { BAN::deallocator(addr); }
inline void operator delete[](void* addr) { BAN::deallocator(addr); }
inline void operator delete(void* addr, size_t) { BAN::deallocator(addr); }
inline void operator delete[](void* addr, size_t) { BAN::deallocator(addr); }

View File

@ -2,6 +2,7 @@
#include <BAN/Errors.h> #include <BAN/Errors.h>
#include <BAN/Math.h> #include <BAN/Math.h>
#include <BAN/Memory.h>
#include <BAN/Move.h> #include <BAN/Move.h>
namespace BAN namespace BAN

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <BAN/Errors.h>
#include <BAN/ForwardList.h> #include <BAN/ForwardList.h>
#include <BAN/Formatter.h> #include <BAN/Formatter.h>

View File

@ -2,6 +2,7 @@
#include <BAN/Errors.h> #include <BAN/Errors.h>
#include <BAN/Math.h> #include <BAN/Math.h>
#include <BAN/Memory.h>
#include <BAN/Move.h> #include <BAN/Move.h>
namespace BAN namespace BAN