Kajetan Johannes Hammerle 2 月之前
父節點
當前提交
0a9f3b8879
共有 100 個文件被更改,包括 368 次插入1838 次删除
  1. 3 0
      .clangd
  2. 3 1
      CMakeLists.txt
  3. 1 8
      include/core/AlignedData.hpp
  4. 0 0
      include/core/Array.hpp
  5. 4 8
      include/core/File.hpp
  6. 206 125
      include/core/List.hpp
  7. 8 6
      include/core/Math.hpp
  8. 6 0
      include/core/Meta.hpp
  9. 43 30
      include/core/Test.hpp
  10. 33 4
      include/core/ToString.hpp
  11. 9 12
      include/core/Types.hpp
  12. 1 1
      include/core/UniquePointer.hpp
  13. 51 66
      include/core/Utility.hpp
  14. 0 0
      old/ArrayList.hpp
  15. 0 0
      old/ArrayListTests.cpp
  16. 0 0
      old/ArrayString.cpp
  17. 0 0
      old/ArrayString.hpp
  18. 0 0
      old/ArrayStringTests.cpp
  19. 0 0
      old/ArrayTests.cpp
  20. 0 0
      old/BitArray.cpp
  21. 0 0
      old/BitArray.hpp
  22. 0 0
      old/BitArrayTests.cpp
  23. 0 0
      old/Box.cpp
  24. 0 0
      old/Box.hpp
  25. 0 0
      old/BoxTests.cpp
  26. 0 0
      old/Buffer.cpp
  27. 0 0
      old/Buffer.hpp
  28. 0 0
      old/BufferTests.cpp
  29. 0 0
      old/BufferedValue.hpp
  30. 0 0
      old/BufferedValueTests.cpp
  31. 0 248
      old/CMakeLists.txt
  32. 0 0
      old/Clock.cpp
  33. 0 0
      old/Clock.hpp
  34. 0 0
      old/ClockTests.cpp
  35. 0 0
      old/Color.hpp
  36. 0 0
      old/ColorTests.cpp
  37. 0 0
      old/Components.hpp
  38. 0 0
      old/ComponentsTests.cpp
  39. 0 0
      old/ErrorSimulator.cpp
  40. 0 0
      old/ErrorSimulator.hpp
  41. 0 0
      old/Frustum.cpp
  42. 0 0
      old/Frustum.hpp
  43. 0 0
      old/FrustumTests.cpp
  44. 0 0
      old/HashCode.hpp
  45. 0 0
      old/HashMap.hpp
  46. 0 0
      old/HashMapTests.cpp
  47. 0 0
      old/HashedString.hpp
  48. 0 0
      old/HashedStringTests.cpp
  49. 0 0
      old/MathTests.cpp
  50. 0 0
      old/Matrix.cpp
  51. 0 0
      old/Matrix.hpp
  52. 0 0
      old/MatrixStack.hpp
  53. 0 0
      old/MatrixStackTests.cpp
  54. 0 0
      old/MatrixTests.cpp
  55. 0 0
      old/Mutex.cpp
  56. 0 0
      old/Mutex.hpp
  57. 0 0
      old/Plane.cpp
  58. 0 0
      old/Plane.hpp
  59. 0 0
      old/PlaneTests.cpp
  60. 0 0
      old/ProbingHashMap.hpp
  61. 0 0
      old/Quaternion.cpp
  62. 0 0
      old/Quaternion.hpp
  63. 0 0
      old/QuaternionTests.cpp
  64. 0 0
      old/Random.cpp
  65. 0 0
      old/Random.hpp
  66. 0 0
      old/RandomTests.cpp
  67. 0 0
      old/RingBuffer.hpp
  68. 0 0
      old/RingBufferTests.cpp
  69. 0 0
      old/SpinLock.cpp
  70. 0 0
      old/SpinLock.hpp
  71. 0 0
      old/Stack.hpp
  72. 0 0
      old/StackTests.cpp
  73. 0 0
      old/Thread.cpp
  74. 0 0
      old/Thread.hpp
  75. 0 0
      old/ThreadTests.cpp
  76. 0 0
      old/Vector.cpp
  77. 0 0
      old/Vector.hpp
  78. 0 0
      old/VectorTests.cpp
  79. 0 0
      old/View.cpp
  80. 0 0
      old/View.hpp
  81. 0 0
      old/ViewTests.cpp
  82. 0 179
      old/include/core/data/LinkedList.hpp
  83. 0 203
      old/include/core/data/List.hpp
  84. 0 12
      old/include/core/io/File.hpp
  85. 0 29
      old/include/core/io/FileReader.hpp
  86. 0 24
      old/include/core/utils/Check.hpp
  87. 0 79
      old/include/core/utils/Error.hpp
  88. 0 80
      old/include/core/utils/Logger.hpp
  89. 0 19
      old/include/core/utils/New.hpp
  90. 0 17
      old/include/core/utils/Types.hpp
  91. 0 48
      old/include/core/utils/Utility.hpp
  92. 0 20
      old/src/Error.cpp
  93. 0 73
      old/src/FileReader.cpp
  94. 0 14
      old/src/Logger.cpp
  95. 0 33
      old/src/New.cpp
  96. 0 120
      old/src/Utility.cpp
  97. 0 189
      old/tasks
  98. 0 69
      old/test/Main.cpp
  99. 0 27
      old/test/Test.cpp
  100. 0 94
      old/test/Test.hpp

+ 3 - 0
.clangd

@@ -1,3 +1,6 @@
 CompileFlags:
   Add: [-ferror-limit=0, -DERROR_SIMULATOR=true]
   CompilationDatabase: ./build_debug/
+Diagnostics:
+  Includes:
+    IgnoreHeader: "new"

+ 3 - 1
CMakeLists.txt

@@ -51,6 +51,8 @@ set(SRC_TESTS
     "test/modules/UtilityTests.cpp"
     #"test/modules/VectorTests.cpp"
     #"test/modules/ViewTests.cpp"
+    "test/modules/ListTests.cpp"
+    "test/modules/UniquePointerTests.cpp"
 )
 
 set(SRC_PERFORMANCE
@@ -61,7 +63,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
     set(COMPILE_OPTIONS "")
     set(LINK_OPTIONS "")
     set(LOG_LEVEL 2)
-    set(DEFINITIONS CHECK_MEMORY)
+    #set(DEFINITIONS CHECK_MEMORY)
 else()
     set(DEFINITIONS ERROR_SIMULATOR CHECK_MEMORY)
     if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")

+ 1 - 8
old/include/core/utils/AlignedData.hpp → include/core/AlignedData.hpp

@@ -1,14 +1,7 @@
 #ifndef CORE_ALIGNED_DATA_HPP
 #define CORE_ALIGNED_DATA_HPP
 
-#include "core/utils/Types.hpp"
-
-#define CORE_ASSERT_ALIGNED_DATA(var, type)                                    \
-    static_assert(sizeof(var) == sizeof(type), "aligned data size missmatch"); \
-    static_assert(decltype(var)::getSize() >= decltype(var)::getAlignment(),   \
-                  "size >= alignment");                                        \
-    static_assert(alignof(decltype(var)) == alignof(type),                     \
-                  "aligned data alignment missmatch");
+#include <cstddef>
 
 namespace Core {
     template<size_t SIZE, size_t ALIGNMENT>

+ 0 - 0
old/include/core/data/Array.hpp → include/core/Array.hpp


+ 4 - 8
include/core/File.hpp

@@ -1,14 +1,10 @@
 #ifndef CORE_FILE_H
 #define CORE_FILE_H
 
-#include <cstddef>
+#include "core/List.hpp"
 
-struct FileContent {
-    char* data;
-    size_t length;
-};
-
-bool readFile(FileContent* f, const char* path);
-void destroyFileContent(FileContent* f);
+namespace Core {
+    bool readFile(List<char>& content, const char* path);
+}
 
 #endif

+ 206 - 125
include/core/List.hpp

@@ -1,131 +1,212 @@
-#ifndef CORE_LIST_H
-#define CORE_LIST_H
+#ifndef CORE_LIST_HPP
+#define CORE_LIST_HPP
 
-#include <assert.h>
+#include <cassert>
+#include <new>
 
-#include "core/ToString.hpp"
-#include "core/Types.hpp"
+#include "core/AlignedData.hpp"
+#include "core/Math.hpp"
+#include "core/Meta.hpp"
 #include "core/Utility.hpp"
 
-#define LIST(T, N)                                                        \
-    struct ListT##N {                                                     \
-        size_t length;                                                    \
-        size_t capacity;                                                  \
-        T* data;                                                          \
-    };                                                                    \
-    typedef struct ListT##N List##N;                                      \
-                                                                          \
-    void initList##N(List##N* l);                                         \
-    void destroyList##N(List##N* l);                                      \
-    void reserveListEntries##N(List##N* l, size_t n);                     \
-    void addListData##N(List##N* l, T data);                              \
-    void addLastListData##N(List##N* l);                                  \
-    T* addEmptyListData##N(List##N* l);                                   \
-    T* getListIndex##N(const List##N* l, size_t index);                   \
-    T* getListLast##N(const List##N* l);                                  \
-    void clearList##N(List##N* l);                                        \
-    void removeListIndexBySwap##N(List##N* l, size_t index);              \
-    void removeListIndex##N(List##N* l, size_t index);                    \
-    void removeListLast##N(List##N* l);                                   \
-    T* getListStart##N(const List##N* l);                                 \
-    T* getListEnd##N(const List##N* l);                                   \
-    typedef size_t (*ToString##N)(const T* data, char* buffer, size_t n); \
-    size_t toStringList##N(                                               \
-        const List##N* l, char* buffer, size_t n, ToString##N c);
-
-#define LIST_SOURCE(T, N)                                              \
-    void initList##N(List##N* l) {                                     \
-        *l = (List##N){0, 0, nullptr};                                 \
-    }                                                                  \
-                                                                       \
-    void destroyList##N(List##N* l) {                                  \
-        coreFree(l->data);                                             \
-        *l = (List##N){0};                                             \
-    }                                                                  \
-                                                                       \
-    void reserveListEntries##N(List##N* l, size_t n) {                 \
-        if(n > l->capacity) {                                          \
-            l->capacity = n;                                           \
-            l->data = coreReallocate(l->data, sizeof(T) * n);          \
-        }                                                              \
-    }                                                                  \
-                                                                       \
-    void addListData##N(List##N* l, T data) {                          \
-        *addEmptyListData##N(l) = data;                                \
-    }                                                                  \
-                                                                       \
-    void addLastListData##N(List##N* l) {                              \
-        addListData##N(l, *getListLast##N(l));                         \
-    }                                                                  \
-                                                                       \
-    T* addEmptyListData##N(List##N* l) {                               \
-        if(l->length >= l->capacity) {                                 \
-            reserveListEntries##N(                                     \
-                l, l->capacity + maxSize(4lu, l->capacity / 4));       \
-        }                                                              \
-        return l->data + l->length++;                                  \
-    }                                                                  \
-                                                                       \
-    T* getListIndex##N(const List##N* l, size_t index) {               \
-        assert(index < l->length);                                     \
-        return l->data + index;                                        \
-    }                                                                  \
-                                                                       \
-    T* getListLast##N(const List##N* l) {                              \
-        return getListIndex##N(l, l->length - 1);                      \
-    }                                                                  \
-                                                                       \
-    void clearList##N(List##N* l) {                                    \
-        l->length = 0;                                                 \
-    }                                                                  \
-                                                                       \
-    void removeListIndexBySwap##N(List##N* l, size_t index) {          \
-        assert(index < l->length);                                     \
-        size_t length = l->length - 1;                                 \
-        if(index != length) {                                          \
-            l->data[index] = l->data[length];                          \
-        }                                                              \
-        l->length = length;                                            \
-    }                                                                  \
-                                                                       \
-    void removeListIndex##N(List##N* l, size_t index) {                \
-        assert(index < l->length);                                     \
-        l->length--;                                                   \
-        T* p = l->data + index;                                        \
-        T* end = getListEnd##N(l);                                     \
-        while(p != end) {                                              \
-            *p = *(p + 1);                                             \
-            p++;                                                       \
-        }                                                              \
-    }                                                                  \
-                                                                       \
-    void removeListLast##N(List##N* l) {                               \
-        removeListIndexBySwap##N(l, l->length - 1);                    \
-    }                                                                  \
-                                                                       \
-    T* getListStart##N(const List##N* l) {                             \
-        return l->data;                                                \
-    }                                                                  \
-                                                                       \
-    T* getListEnd##N(const List##N* l) {                               \
-        return l->data + l->length;                                    \
-    }                                                                  \
-                                                                       \
-    size_t toStringList##N(                                            \
-        const List##N* l, char* buffer, size_t n, ToString##N c) {     \
-        size_t w = 0;                                                  \
-        stringAdd(&w, &buffer, &n, toString(buffer, n, "["));          \
-        T* end = getListEnd##N(l);                                     \
-        T* p = getListStart##N(l);                                     \
-        while(p != end) {                                              \
-            stringAdd(&w, &buffer, &n, c(p, buffer, n));               \
-            p++;                                                       \
-            if(p != end) {                                             \
-                stringAdd(&w, &buffer, &n, toString(buffer, n, ", ")); \
-            }                                                          \
-        }                                                              \
-        stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));          \
-        return w;                                                      \
-    }
+namespace Core {
+    template<typename T>
+    class List final {
+        size_t length;
+        size_t capacity;
+        T* data;
+
+    public:
+        List() : length(0), capacity(0), data(nullptr) {
+        }
+
+        List(const List& other) :
+            length(0), capacity(other.capacity),
+            data(allocate(other.capacity)) {
+            for(const T& t : other) {
+                unsafeAdd(t);
+            }
+        }
+
+        List(List&& other) : List() {
+            swap(other);
+        }
+
+        ~List() {
+            clear();
+            delete[] reinterpret_cast<AlignedType<T>*>(data);
+        }
+
+        List& operator=(List other) {
+            swap(other);
+            return *this;
+        }
+
+        T* begin() {
+            return data;
+        }
+
+        T* end() {
+            return data + length;
+        }
+
+        const T* begin() const {
+            return data;
+        }
+
+        const T* end() const {
+            return data + length;
+        }
+
+        void reserve(size_t n) {
+            if(n > capacity) {
+                setSize(n);
+            }
+        }
+
+        void shrink() {
+            if(length != capacity) {
+                setSize(length);
+            }
+        }
+
+        void resize(size_t n, const T& t) {
+            if(length < n) {
+                reserve(n);
+                for(size_t i = n - length; i != 0; i--) {
+                    unsafeAdd(t);
+                }
+            } else if(length > n) {
+                for(size_t i = n; i < length; i++) {
+                    data[i].~T();
+                }
+                length = n;
+            }
+        }
+
+        void resize(size_t n) {
+            if(length < n) {
+                reserve(n);
+                for(size_t i = n - length; i != 0; i--) {
+                    unsafeAdd(T());
+                }
+            } else if(length > n) {
+                for(size_t i = n; i < length; i++) {
+                    data[i].~T();
+                }
+                length = n;
+            }
+        }
+
+        template<typename... Args>
+        T& put(Args&&... args) {
+            ensureCapacity();
+            return *unsafeAdd(Core::forward<Args>(args)...);
+        }
+
+        template<typename... Args>
+        List& add(Args&&... args) {
+            put(Core::forward<Args>(args)...);
+            return *this;
+        }
+
+        T& operator[](size_t index) {
+            assert(index < length);
+            return data[index];
+        }
+
+        const T& operator[](size_t index) const {
+            assert(index < length);
+            return data[index];
+        }
+
+        T& getLast() {
+            assert(length > 0);
+            return data[length - 1];
+        }
+
+        const T& getLast() const {
+            assert(length > 0);
+            return data[length - 1];
+        }
+
+        size_t getLength() const {
+            return length;
+        }
+
+        size_t getCapacity() const {
+            return capacity;
+        }
+
+        void clear() {
+            for(T& t : *this) {
+                t.~T();
+            }
+            length = 0;
+        }
+
+        void removeBySwap(size_t index) {
+            assert(index < length);
+            length--;
+            if(index != length) {
+                data[index] = Core::move(data[length]);
+            }
+            data[length].~T();
+        }
+
+        void remove(size_t index) {
+            assert(index < length);
+            length--;
+            T* currentT = begin() + index;
+            T* endT = end();
+            while(currentT != endT) {
+                T* nextT = currentT + 1;
+                *currentT = Core::move(*nextT);
+                currentT = nextT;
+            }
+            endT->~T();
+        }
+
+        void removeLast() {
+            removeBySwap(length - 1);
+        }
+
+        void swap(List& other) {
+            Core::swap(length, other.length);
+            Core::swap(capacity, other.capacity);
+            Core::swap(data, other.data);
+        }
+
+    private:
+        static T* allocate(size_t n) {
+            if(n <= 0) {
+                return nullptr;
+            }
+            return reinterpret_cast<T*>(coreNewN(AlignedType<T>, n));
+        }
+
+        void ensureCapacity() {
+            if(length >= capacity) {
+                reserve(capacity + Core::max(4lu, capacity / 4));
+            }
+        }
+
+        // does not check for capacity
+        template<typename... Args>
+        T* unsafeAdd(Args&&... args) {
+            return new(data + length++) T(Core::forward<Args>(args)...);
+        }
+
+        void setSize(size_t n) {
+            List copy;
+            copy.data = allocate(n);
+            copy.capacity = n;
+            for(size_t i = 0; i < length; i++) {
+                copy.unsafeAdd(Core::move(data[i]));
+            }
+            swap(copy);
+        }
+    };
+}
 
 #endif

+ 8 - 6
old/include/core/math/Math.hpp → include/core/Math.hpp

@@ -1,9 +1,9 @@
 #ifndef CORE_MATH_HPP
 #define CORE_MATH_HPP
 
-#include "core/utils/Meta.hpp"
+#include "core/Meta.hpp"
 
-namespace Core::Math {
+namespace Core {
     template<typename T>
     T interpolate(const T& a, const T& b, float f) {
         return a * (1.0f - f) + b * f;
@@ -56,12 +56,14 @@ namespace Core::Math {
 
     constexpr float PI = 3.14159265358979323846f;
 
-    constexpr float radianToDegree(float radians) {
-        return radians * (180.0f / PI);
+    template<typename T>
+    constexpr T radianToDegree(const T& radians) {
+        return radians * static_cast<T>(180.0f / PI);
     }
 
-    constexpr float degreeToRadian(float degrees) {
-        return degrees * (PI / 180.0f);
+    template<typename T>
+    constexpr T degreeToRadian(const T& radians) {
+        return radians * static_cast<T>(PI / 180.0f);
     }
 }
 

+ 6 - 0
include/core/Meta.hpp

@@ -49,6 +49,12 @@ namespace Core {
         };
     }
 
+    template<typename T>
+    concept Iterable = requires(T& t) {
+        t.begin();
+        t.end();
+    };
+
     template<typename T>
     using RemovePointer = Internal::BaseRemovePointer<T>::Type;
 

+ 43 - 30
include/core/Test.hpp

@@ -2,43 +2,56 @@
 #define CORE_TEST_H
 
 #include "core/Logger.hpp"
-#include "core/Types.hpp"
+#include "core/Meta.hpp"
+
+namespace Core {
+    void finalizeTests(void);
+    bool addTestResult(const char* file, bool comparison);
+
+    template<typename T>
+    bool testEqual(
+        const char* file, int line, const T& wanted, const T& actual) {
+        file = getShortFileName(file);
+        if(addTestResult(file, wanted == actual)) {
+            return true;
+        }
+        char buffer[512];
+        formatBuffer(
+            buffer, sizeof(buffer),
+            TERMINAL_RED "#:# - expected '#' got '#'" TERMINAL_RESET, file,
+            line, wanted, actual);
+        puts(buffer);
+        return false;
+    }
 
-void finalizeTests(void);
-bool addToResult(const char* file, bool comparison);
+    bool testString(
+        const char* file, int line, const char* wanted, const char* actual);
 
-template<typename T>
-bool testEqual(const char* file, int line, const T& wanted, const T& actual) {
-    file = getShortFileName(file);
-    if(addToResult(file, wanted == actual)) {
-        return true;
+    template<typename T>
+    bool testString(
+        const char* file, int line, const char* wanted, const T& t) {
+        char buffer[512];
+        toString(t, buffer, sizeof(buffer));
+        return testString(file, line, wanted, static_cast<const char*>(buffer));
     }
-    char buffer[512];
-    formatBuffer(
-        buffer, sizeof(buffer),
-        TERMINAL_RED "#:# - expected '#' got '#'" TERMINAL_RESET, file, line,
-        wanted, actual);
-    puts(buffer);
-    return false;
-}
 
-#define TEST_ARGS const char *file, int line
+    bool testFloat(
+        const char* file, int line, float wanted, float actual, float error);
+    bool testNull(const char* file, int line, const void* p);
+    bool testNotNull(const char* file, int line, const void* p);
 
-bool testString(TEST_ARGS, const char* wanted, const char* actual);
-bool testFloat(TEST_ARGS, float wanted, float actual, float error);
-bool testNull(TEST_ARGS, const void* p);
-bool testNotNull(TEST_ARGS, const void* p);
+#define TEST_FLOAT(wanted, actual, error)                      \
+    Core::testFloat(__FILE__, __LINE__, wanted, actual, error)
 
-#define TEST_FLOAT(wanted, actual, error)                \
-    testFloat(__FILE__, __LINE__, wanted, actual, error)
-
-#define TEST(wanted, actual)                                        \
-    testEqual<decltype(wanted)>(__FILE__, __LINE__, wanted, actual)
-#define TEST_STRING(wanted, actual)                \
-    testString(__FILE__, __LINE__, wanted, actual)
+#define TEST(wanted, actual)                                  \
+    Core::testEqual<Core::RemoveReference<decltype(actual)>>( \
+        __FILE__, __LINE__, wanted, actual)
+#define TEST_STRING(wanted, actual)                      \
+    Core::testString(__FILE__, __LINE__, wanted, actual)
 #define TEST_FALSE(actual) TEST(false, actual)
 #define TEST_TRUE(actual) TEST(true, actual)
-#define TEST_NULL(actual) testNull(__FILE__, __LINE__, actual)
-#define TEST_NOT_NULL(actual) testNotNull(__FILE__, __LINE__, actual)
+#define TEST_NULL(actual) Core::testNull(__FILE__, __LINE__, actual)
+#define TEST_NOT_NULL(actual) Core::testNotNull(__FILE__, __LINE__, actual)
+}
 
 #endif

+ 33 - 4
include/core/ToString.hpp

@@ -4,7 +4,8 @@
 #include <cstdio>
 #include <cstring>
 
-#include "core/Utility.hpp"
+#include "core/Math.hpp"
+#include "core/Meta.hpp"
 
 size_t toString(int v, char* s, size_t n);
 size_t toString(long v, char* s, size_t n);
@@ -13,11 +14,39 @@ size_t toString(unsigned int v, char* s, size_t n);
 size_t toString(unsigned long v, char* s, size_t n);
 size_t toString(unsigned long long v, char* s, size_t n);
 size_t toString(const char* v, char* s, size_t n);
+size_t toString(char* v, char* s, size_t n);
 size_t toString(bool v, char* s, size_t n);
 
+template<typename T>
+void addString(const T& t, char*& s, size_t& n, size_t& total) {
+    size_t w = toString(t, s, n);
+    total += w;
+    w = Core::min(n, w);
+    s += w;
+    n -= w;
+}
+
 template<typename T>
 size_t toString(const T& t, char* s, size_t n) {
-    return t.toString(s, n);
+    if constexpr(Core::Iterable<T>) {
+        size_t total = 0;
+        addString("[", s, n, total);
+        auto current = t.begin();
+        auto end = t.end();
+        if(current != end) {
+            addString(*current, s, n, total);
+            ++current;
+        }
+        while(current != end) {
+            addString(", ", s, n, total);
+            addString(*current, s, n, total);
+            ++current;
+        }
+        addString("]", s, n, total);
+        return total;
+    } else {
+        return t.toString(s, n);
+    }
 }
 
 void copyFormatUntil(const char*& format, char*& s, size_t& n);
@@ -28,7 +57,7 @@ void formatR(
     const char*& format, char*& s, size_t& n, const T& t, Args&&... args) {
     copyFormatUntil(format, s, n);
     if(n > 1) {
-        size_t w = min(toString(t, s, n - 1), n - 1);
+        size_t w = Core::min(toString(t, s, n - 1), n - 1);
         s += w;
         n -= w;
     }
@@ -44,7 +73,7 @@ size_t formatBuffer(char* s, size_t n, const char* format, Args&&... args) {
         formatR(format, s, n, Core::forward<Args>(args)...);
         copyFormat(format, s, n);
     } else {
-        memcpy(s, format, min(n, strlen(format)));
+        memcpy(s, format, Core::min(n, strlen(format)));
         s[n - (n > 0)] = 0;
     }
     return 0;

+ 9 - 12
include/core/Types.hpp

@@ -1,19 +1,16 @@
 #ifndef CORE_TYPES_HPP
 #define CORE_TYPES_HPP
 
-#include <cstddef>
 #include <cstdint>
 
-typedef int64_t i64;
-typedef int32_t i32;
-typedef int16_t i16;
-typedef int8_t i8;
-typedef uint64_t u64;
-typedef uint32_t u32;
-typedef uint16_t u16;
-typedef uint8_t u8;
-#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*array))
-
-typedef size_t (*ToString)(const void* data, char* buffer, size_t n);
+using i64 = int64_t;
+using i32 = int32_t;
+using i16 = int16_t;
+using i8 = int8_t;
+using u64 = uint64_t;
+using u32 = uint32_t;
+using u16 = uint16_t;
+using u8 = uint8_t;
+using size_t = decltype(sizeof(int));
 
 #endif

+ 1 - 1
old/include/core/utils/UniquePointer.hpp → include/core/UniquePointer.hpp

@@ -51,4 +51,4 @@ namespace Core {
     };
 }
 
-#endif
+#endif

+ 51 - 66
include/core/Utility.hpp

@@ -4,90 +4,75 @@
 #include "core/Meta.hpp"
 #include "core/Types.hpp"
 
-size_t popCount(u64 u);
-
-template<typename T>
-inline T interpolate(const T& a, const T& b, float factor) {
-    return a * (1.0f - factor) + b * factor;
-}
-
-static constexpr float PI = 3.14159265358979323846f;
-
-template<typename T>
-inline T radianToDegree(const T& radians) {
-    return radians * static_cast<T>(180.0f / PI);
-}
-
-template<typename T>
-inline T degreeToRadian(const T& radians) {
-    return radians * static_cast<T>(PI / 180.0f);
-}
-
-template<typename T>
-inline T max(const T& a, const T& b) {
-    return a > b ? a : b;
-}
+#ifdef CHECK_MEMORY
+void* operator new(size_t count, const char* file, int line);
+void* operator new[](size_t count, const char* file, int line);
+#endif
 
-template<typename T>
-inline T min(const T& a, const T& b) {
-    return a < b ? a : b;
-}
+namespace Core {
+    inline void nothing() {
+    }
 
-template<typename T>
-inline T clamp(const T& t, const T& from, const T& to) {
-    return max(min(t, to), from);
-}
+    template<typename T, typename C = int>
+    C popCount(const T& t) {
+        static constexpr C map[16] = {0, 1, 1, 2, 1, 2, 2, 3,
+                                      1, 2, 2, 3, 2, 3, 3, 4};
+        C sum = 0;
+        for(size_t i = 0; i < sizeof(T) * 8; i += 4) {
+            sum += map[(t >> i) & 0xF];
+        }
+        return sum;
+    }
 
-using ExitHandler = void (*)(int, void*);
-[[noreturn]] void exitWithHandler(const char* file, int line, int value);
-void setExitHandler(ExitHandler h, void* data);
-#define EXIT(exitValue) exitWithHandler(__FILE__, __LINE__, exitValue)
+    using ExitHandler = void (*)(int, void*);
+    [[noreturn]] void exitWithHandler(const char* file, int line, int value);
+    void setExitHandler(ExitHandler h, void* data);
+#define EXIT(exitValue) Core::exitWithHandler(__FILE__, __LINE__, exitValue)
 
-using OutOfMemoryHandler = void (*)(void*);
-void setOutOfMemoryHandler(OutOfMemoryHandler h, void* data);
+    using OutOfMemoryHandler = void (*)(void*);
+    void setOutOfMemoryHandler(OutOfMemoryHandler h, void* data);
 
 #ifdef CHECK_MEMORY
-void* coreDebugAllocate(const char* file, int line, size_t n);
-void* coreDebugZeroAllocate(const char* file, int line, size_t n);
-void* coreDebugReallocate(const char* file, int line, void* p, size_t n);
-void coreFreeDebug(void* p);
-void printMemoryReport(void);
-#define coreAllocate(n) coreDebugAllocate(__FILE__, __LINE__, n)
-#define coreZeroAllocate(n) coreDebugZeroAllocate(__FILE__, __LINE__, n)
-#define coreReallocate(p, n) coreDebugReallocate(__FILE__, __LINE__, p, n)
-#define coreFree(p) coreFreeDebug(p)
-void* operator new(size_t count, const char* file, int line);
-void* operator new[](size_t count, const char* file, int line);
+    void* debugAllocateRaw(const char* file, int line, size_t n);
+    void* debugZeroAllocateRaw(const char* file, int line, size_t n);
+    void* debugReallocateRaw(const char* file, int line, void* p, size_t n);
+    void debugDeallocateRaw(void* p);
+    void printMemoryReport(void);
+#define allocateRaw(n) debugAllocateRaw(__FILE__, __LINE__, n)
+#define zeroAllocateRaw(n) debugZeroAllocateRaw(__FILE__, __LINE__, n)
+#define reallocateRaw(p, n) debugReallocateRaw(__FILE__, __LINE__, p, n)
+#define deallocateRaw(p) debugDeallocateRaw(p)
 #define coreNew(type, ...) new(__FILE__, __LINE__) type(__VA_ARGS__)
 #define coreNewN(type, n) new(__FILE__, __LINE__) type[n]
 #define coreDelete(p) delete(p)
 #define coreDeleteN(p) delete[](p)
 #else
-void* coreAllocate(size_t n);
-void* coreZeroAllocate(size_t n);
-void* coreReallocate(void* p, size_t n);
-void coreFree(void* p);
-#define printMemoryReport()
+    void* allocateRaw(size_t n);
+    void* zeroAllocateRaw(size_t n);
+    void* reallocateRaw(void* p, size_t n);
+    void deallocateRaw(void* p);
+#define printMemoryReport() nothing()
 #define coreNew(type, ...) new type(__VA_ARGS__)
 #define coreNewN(type, n) new type[n]
 #define coreDelete(p) delete(p)
 #define coreDeleteN(p) delete[](p)
 #endif
 
-bool sleepMillis(i64 millis);
-bool sleepNanos(i64 nanos);
-i64 getNanos(void);
+    bool sleepMillis(i64 millis);
+    bool sleepNanos(i64 nanos);
+    i64 getNanos(void);
 
-template<typename T>
-void bubbleSort(T* data, size_t n) {
-    bool swapped = true;
-    while(swapped && n > 0) {
-        swapped = false;
-        n--;
-        for(size_t i = 0; i < n; i++) {
-            if(data[i] > data[i + 1]) {
-                Core::swap(data[i], data[i + 1]);
-                swapped = true;
+    template<typename T>
+    void bubbleSort(T* data, size_t n) {
+        bool swapped = true;
+        while(swapped && n > 0) {
+            swapped = false;
+            n--;
+            for(size_t i = 0; i < n; i++) {
+                if(data[i] > data[i + 1]) {
+                    swap(data[i], data[i + 1]);
+                    swapped = true;
+                }
             }
         }
     }

+ 0 - 0
old/include/core/data/ArrayList.hpp → old/ArrayList.hpp


+ 0 - 0
old/test/modules/ArrayListTests.cpp → old/ArrayListTests.cpp


+ 0 - 0
old/src/ArrayString.cpp → old/ArrayString.cpp


+ 0 - 0
old/include/core/utils/ArrayString.hpp → old/ArrayString.hpp


+ 0 - 0
old/test/modules/ArrayStringTests.cpp → old/ArrayStringTests.cpp


+ 0 - 0
old/test/modules/ArrayTests.cpp → old/ArrayTests.cpp


+ 0 - 0
old/src/BitArray.cpp → old/BitArray.cpp


+ 0 - 0
old/include/core/data/BitArray.hpp → old/BitArray.hpp


+ 0 - 0
old/test/modules/BitArrayTests.cpp → old/BitArrayTests.cpp


+ 0 - 0
old/src/Box.cpp → old/Box.cpp


+ 0 - 0
old/include/core/math/Box.hpp → old/Box.hpp


+ 0 - 0
old/test/modules/BoxTests.cpp → old/BoxTests.cpp


+ 0 - 0
old/src/Buffer.cpp → old/Buffer.cpp


+ 0 - 0
old/include/core/utils/Buffer.hpp → old/Buffer.hpp


+ 0 - 0
old/test/modules/BufferTests.cpp → old/BufferTests.cpp


+ 0 - 0
old/include/core/math/BufferedValue.hpp → old/BufferedValue.hpp


+ 0 - 0
old/test/modules/BufferedValueTests.cpp → old/BufferedValueTests.cpp


+ 0 - 248
old/CMakeLists.txt

@@ -1,248 +0,0 @@
-cmake_minimum_required(VERSION 3.25)
-project(core)
-
-set(CMAKE_CXX_STANDARD 20)
-
-set(SRC
-    "src/Logger.cpp"
-    "src/Utility.cpp"
-    "src/Error.cpp"
-    "src/New.cpp"
-    "src/Buffer.cpp"
-    "src/Clock.cpp"
-    "src/Random.cpp"
-    "src/BitArray.cpp"
-    "src/Vector.cpp"
-    "src/Quaternion.cpp"
-    "src/Matrix.cpp"
-    "src/Box.cpp"
-    "src/Plane.cpp"
-    "src/Frustum.cpp"
-    "src/View.cpp"
-    "src/Thread.cpp"
-    "src/Mutex.cpp"
-    "src/SpinLock.cpp"
-    "src/FileReader.cpp"
-    "src/ErrorSimulator.cpp"
-    "src/ArrayString.cpp"
-)
-
-set(SRC_TESTS
-    "test/Main.cpp"
-    "test/Test.cpp"
-    "test/modules/ArrayTests.cpp"
-    "test/modules/ArrayStringTests.cpp"
-    "test/modules/UtilityTests.cpp"
-    "test/modules/ArrayListTests.cpp"
-    "test/modules/BitArrayTests.cpp"
-    "test/modules/MathTests.cpp"
-    "test/modules/ListTests.cpp"
-    "test/modules/LinkedListTests.cpp"
-    "test/modules/UniquePointerTests.cpp"
-    "test/modules/HashMapTests.cpp"
-    "test/modules/StackTests.cpp"
-    "test/modules/RingBufferTests.cpp"
-    "test/modules/ComponentsTests.cpp"
-    "test/modules/VectorTests.cpp"
-    "test/modules/QuaternionTests.cpp"
-    "test/modules/MatrixTests.cpp"
-    "test/modules/BoxTests.cpp"
-    "test/modules/BufferedValueTests.cpp"
-    "test/modules/PlaneTests.cpp"
-    "test/modules/FrustumTests.cpp"
-    "test/modules/ViewTests.cpp"
-    "test/modules/MatrixStackTests.cpp"
-    "test/modules/ColorTests.cpp"
-    "test/modules/BufferTests.cpp"
-    "test/modules/ClockTests.cpp"
-    "test/modules/RandomTests.cpp"
-    "test/modules/ThreadTests.cpp"
-    "test/modules/FileReaderTests.cpp"
-    "test/modules/ErrorTests.cpp"
-    "test/modules/NewTests.cpp"
-    "test/modules/HashedStringTests.cpp"
-)
-
-set(SRC_PERFORMANCE
-    "performance/Main.cpp"
-    "test/Test.cpp"
-)
-
-if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
-    set(COMPILE_OPTIONS -flto)
-    set(LINK_OPTIONS -flto)
-    set(LOG_LEVEL 2)
-    set(ERROR_SIMULATOR "")
-else()
-    if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-        set(COMPILE_OPTIONS --coverage)
-    endif()
-    set(LINK_OPTIONS gcov)
-    set(LOG_LEVEL 4)
-    set(ERROR_SIMULATOR "ERROR_SIMULATOR")
-endif()
-
-if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
-    set(MORE_WARNINGS
-        -Waligned-new=all
-        -Walloc-zero
-        -Wanalyzer-too-complex
-        -Warith-conversion
-        -Warray-bounds=2
-        -Wattribute-alias=2
-        -Wbidi-chars=any
-        -Wcast-align=strict
-        -Wcatch-value=3
-        -Wcomma-subscript
-        -Wconditionally-supported
-        -Wduplicated-branches
-        -Wduplicated-cond
-        -Wformat-overflow=2
-        -Wformat-signedness
-        -Wformat-truncation=2
-        -Wimplicit-fallthrough=5
-        -Winvalid-imported-macros
-        -Wlogical-op
-        -Wmultiple-inheritance
-        -Wnoexcept
-        -Wnormalized=nfkc
-        -Wplacement-new=2
-        -Wredundant-tags
-        -Wshift-overflow=2
-        -Wstack-usage=8388608
-        -Wstrict-null-sentinel
-        -Wstringop-overflow=4
-        -Wsuggest-final-methods
-        -Wsuggest-final-types
-        -Wtrampolines
-        -Wtrivial-auto-var-init
-        -Wunused-const-variable=2
-        -Wuse-after-free=3
-        -Wvirtual-inheritance
-        -Wvolatile
-    )
-endif()
-
-add_library(core STATIC ${SRC})
-target_compile_options(core PUBLIC
-    ${COMPILE_OPTIONS}
-    -fdiagnostics-color=always
-    -fno-exceptions
-    -fno-rtti
-    -fno-threadsafe-statics
-    # deactivated due to the need for <atomic>
-    #-nostdinc++
-    -pedantic
-    -pedantic-errors
-    -Wall
-    -Walloca
-    -Warray-parameter
-    -Wcast-qual
-    -Wconversion
-    -Wctad-maybe-unsupported
-    -Wctor-dtor-privacy
-    -Wdate-time
-    -Wdeprecated-copy-dtor
-    -Wdeprecated-enum-enum-conversion
-    -Wdeprecated-enum-float-conversion
-    -Wdisabled-optimization
-    -Wdouble-promotion
-    -Weffc++
-    -Wenum-compare
-    -Wenum-conversion
-    -Werror
-    -Wextra
-    -Wextra-semi
-    -Wfloat-equal
-    -Wformat=2
-    -Wframe-larger-than=8388608
-    -Winfinite-recursion
-    -Winit-self
-    -Winvalid-pch
-    -Wlarger-than=1073741824
-    -Wmismatched-tags
-    -Wmissing-braces
-    -Wmissing-declarations
-    -Wmissing-include-dirs
-    -Wmultichar
-    -Wnon-virtual-dtor
-    -Wnull-dereference
-    -Wold-style-cast
-    -Woverlength-strings
-    -Woverloaded-virtual
-    -Wredundant-decls
-    -Wregister
-    -Wshadow
-    -Wsign-conversion
-    -Wsign-promo
-    -Wstack-protector
-    -Wstrict-overflow=2
-    -Wsuggest-override
-    -Wswitch-enum
-    -Wsynth
-    -Wundef
-    -Wunreachable-code
-    -Wvla
-    -Wwrite-strings
-    -Wzero-as-null-pointer-constant
-    ${MORE_WARNINGS}
-)
-target_compile_definitions(core 
-    PUBLIC CORE_LOG_LEVEL=${LOG_LEVEL}
-    PRIVATE ${ERROR_SIMULATOR}
-)
-target_link_libraries(core 
-    PUBLIC -nodefaultlibs c m
-    PRIVATE ${LINK_OPTIONS}
-)
-target_sources(core PUBLIC 
-    FILE_SET HEADERS
-    BASE_DIRS include
-    FILES 
-        ./include/core/data/Stack.hpp
-        ./include/core/data/HashMap.hpp
-        ./include/core/data/Components.hpp
-        ./include/core/data/ArrayList.hpp
-        ./include/core/data/ProbingHashMap.hpp
-        ./include/core/data/List.hpp
-        ./include/core/data/LinkedList.hpp
-        ./include/core/data/BitArray.hpp
-        ./include/core/data/Array.hpp
-        ./include/core/data/RingBuffer.hpp
-        ./include/core/thread/Thread.hpp
-        ./include/core/utils/HashCode.hpp
-        ./include/core/utils/New.hpp
-        ./include/core/utils/Check.hpp
-        ./include/core/utils/Buffer.hpp
-        ./include/core/utils/Random.hpp
-        ./include/core/utils/UniquePointer.hpp
-        ./include/core/utils/Types.hpp
-        ./include/core/utils/Color.hpp
-        ./include/core/utils/Logger.hpp
-        ./include/core/utils/ArrayString.hpp
-        ./include/core/utils/Utility.hpp
-        ./include/core/utils/Meta.hpp
-        ./include/core/utils/AlignedData.hpp
-        ./include/core/utils/Clock.hpp
-        ./include/core/utils/Error.hpp
-        ./include/core/math/Quaternion.hpp
-        ./include/core/math/Box.hpp
-        ./include/core/math/Frustum.hpp
-        ./include/core/math/Vector.hpp
-        ./include/core/math/Matrix.hpp
-        ./include/core/math/View.hpp
-        ./include/core/math/BufferedValue.hpp
-        ./include/core/math/Plane.hpp
-        ./include/core/math/MatrixStack.hpp
-        ./include/core/math/Math.hpp
-        ./include/core/io/File.hpp
-        ./include/core/io/FileReader.hpp
-)
-install(TARGETS core FILE_SET HEADERS)
-
-add_executable(test ${SRC_TESTS})
-target_link_libraries(test PRIVATE core)
-target_compile_definitions(test PRIVATE ${ERROR_SIMULATOR})
-
-add_executable(performance ${SRC_PERFORMANCE})
-target_link_libraries(performance PRIVATE core)

+ 0 - 0
old/src/Clock.cpp → old/Clock.cpp


+ 0 - 0
old/include/core/utils/Clock.hpp → old/Clock.hpp


+ 0 - 0
old/test/modules/ClockTests.cpp → old/ClockTests.cpp


+ 0 - 0
old/include/core/utils/Color.hpp → old/Color.hpp


+ 0 - 0
old/test/modules/ColorTests.cpp → old/ColorTests.cpp


+ 0 - 0
old/include/core/data/Components.hpp → old/Components.hpp


+ 0 - 0
old/test/modules/ComponentsTests.cpp → old/ComponentsTests.cpp


+ 0 - 0
old/src/ErrorSimulator.cpp → old/ErrorSimulator.cpp


+ 0 - 0
old/src/ErrorSimulator.hpp → old/ErrorSimulator.hpp


+ 0 - 0
old/src/Frustum.cpp → old/Frustum.cpp


+ 0 - 0
old/include/core/math/Frustum.hpp → old/Frustum.hpp


+ 0 - 0
old/test/modules/FrustumTests.cpp → old/FrustumTests.cpp


+ 0 - 0
old/include/core/utils/HashCode.hpp → old/HashCode.hpp


+ 0 - 0
old/include/core/data/HashMap.hpp → old/HashMap.hpp


+ 0 - 0
old/test/modules/HashMapTests.cpp → old/HashMapTests.cpp


+ 0 - 0
old/include/core/utils/HashedString.hpp → old/HashedString.hpp


+ 0 - 0
old/test/modules/HashedStringTests.cpp → old/HashedStringTests.cpp


+ 0 - 0
old/test/modules/MathTests.cpp → old/MathTests.cpp


+ 0 - 0
old/src/Matrix.cpp → old/Matrix.cpp


+ 0 - 0
old/include/core/math/Matrix.hpp → old/Matrix.hpp


+ 0 - 0
old/include/core/math/MatrixStack.hpp → old/MatrixStack.hpp


+ 0 - 0
old/test/modules/MatrixStackTests.cpp → old/MatrixStackTests.cpp


+ 0 - 0
old/test/modules/MatrixTests.cpp → old/MatrixTests.cpp


+ 0 - 0
old/src/Mutex.cpp → old/Mutex.cpp


+ 0 - 0
old/include/core/thread/Mutex.hpp → old/Mutex.hpp


+ 0 - 0
old/src/Plane.cpp → old/Plane.cpp


+ 0 - 0
old/include/core/math/Plane.hpp → old/Plane.hpp


+ 0 - 0
old/test/modules/PlaneTests.cpp → old/PlaneTests.cpp


+ 0 - 0
old/include/core/data/ProbingHashMap.hpp → old/ProbingHashMap.hpp


+ 0 - 0
old/src/Quaternion.cpp → old/Quaternion.cpp


+ 0 - 0
old/include/core/math/Quaternion.hpp → old/Quaternion.hpp


+ 0 - 0
old/test/modules/QuaternionTests.cpp → old/QuaternionTests.cpp


+ 0 - 0
old/src/Random.cpp → old/Random.cpp


+ 0 - 0
old/include/core/utils/Random.hpp → old/Random.hpp


+ 0 - 0
old/test/modules/RandomTests.cpp → old/RandomTests.cpp


+ 0 - 0
old/include/core/data/RingBuffer.hpp → old/RingBuffer.hpp


+ 0 - 0
old/test/modules/RingBufferTests.cpp → old/RingBufferTests.cpp


+ 0 - 0
old/src/SpinLock.cpp → old/SpinLock.cpp


+ 0 - 0
old/include/core/thread/SpinLock.hpp → old/SpinLock.hpp


+ 0 - 0
old/include/core/data/Stack.hpp → old/Stack.hpp


+ 0 - 0
old/test/modules/StackTests.cpp → old/StackTests.cpp


+ 0 - 0
old/src/Thread.cpp → old/Thread.cpp


+ 0 - 0
old/include/core/thread/Thread.hpp → old/Thread.hpp


+ 0 - 0
old/test/modules/ThreadTests.cpp → old/ThreadTests.cpp


+ 0 - 0
old/src/Vector.cpp → old/Vector.cpp


+ 0 - 0
old/include/core/math/Vector.hpp → old/Vector.hpp


+ 0 - 0
old/test/modules/VectorTests.cpp → old/VectorTests.cpp


+ 0 - 0
old/src/View.cpp → old/View.cpp


+ 0 - 0
old/include/core/math/View.hpp → old/View.hpp


+ 0 - 0
old/test/modules/ViewTests.cpp → old/ViewTests.cpp


+ 0 - 179
old/include/core/data/LinkedList.hpp

@@ -1,179 +0,0 @@
-#ifndef CORE_LINKED_LIST_HPP
-#define CORE_LINKED_LIST_HPP
-
-#include "core/utils/ArrayString.hpp"
-#include "core/utils/New.hpp"
-
-namespace Core {
-    template<typename T>
-    struct LinkedList final {
-        class Node final {
-            friend LinkedList;
-
-            Node* next;
-            Node* previous;
-
-        public:
-            T data;
-
-            template<typename... Args>
-            Node(Args&&... args)
-                : next(nullptr), previous(nullptr),
-                  data(Core::forward<Args>(args)...) {
-            }
-        };
-
-        template<typename NT, typename R>
-        struct IteratorBase final {
-            NT* current;
-
-        public:
-            IteratorBase& operator++() {
-                current = current->next;
-                return *this;
-            }
-
-            bool operator!=(const IteratorBase& other) const {
-                return current != other.current;
-            }
-
-            R& operator*() const {
-                return current->data;
-            }
-        };
-
-        using Iterator = IteratorBase<Node, T>;
-        using ConstIterator = IteratorBase<const Node, const T>;
-
-    private:
-        Node* first;
-        Node* last;
-        size_t length;
-
-    public:
-        LinkedList() : first(nullptr), last(nullptr), length(0) {
-        }
-
-        LinkedList(const LinkedList& other) : LinkedList() {
-            for(const T& t : other) {
-                add(t);
-            }
-        }
-
-        LinkedList(LinkedList&& other) : LinkedList() {
-            swap(other);
-        }
-
-        ~LinkedList() {
-            clear();
-        }
-
-        LinkedList& operator=(LinkedList other) {
-            swap(other);
-            return *this;
-        }
-
-        template<typename... Args>
-        Node* put(Args&&... args) {
-            Node* n = new(noThrow) Node(Core::forward<Args>(args)...);
-            length++;
-            if(first == nullptr) {
-                first = n;
-                last = n;
-                return n;
-            }
-            last->next = n;
-            n->previous = last;
-            last = n;
-            return n;
-        }
-
-        template<typename... Args>
-        LinkedList& add(Args&&... args) {
-            put(Core::forward<Args>(args)...);
-            return *this;
-        }
-
-        Iterator begin() {
-            return {first};
-        }
-
-        Iterator end() {
-            return {nullptr};
-        }
-
-        ConstIterator begin() const {
-            return {first};
-        }
-
-        ConstIterator end() const {
-            return {nullptr};
-        }
-
-        size_t getLength() const {
-            return length;
-        }
-
-        void clear() {
-            Node* n = first;
-            while(n != nullptr) {
-                Node* next = n->next;
-                delete n;
-                n = next;
-            }
-            length = 0;
-            first = nullptr;
-            last = nullptr;
-        }
-
-        void toString(BufferString& s) const {
-            Core::toString(s, *this);
-        }
-
-        void remove(Node*& n) {
-            if(n == nullptr) {
-                return;
-            }
-            if(n == first) {
-                if(first->next != nullptr) {
-                    first->next->previous = nullptr;
-                }
-                first = first->next;
-            }
-            if(n == last) {
-                if(last->previous != nullptr) {
-                    last->previous->next = nullptr;
-                }
-                last = last->previous;
-            }
-            if(n->previous != nullptr) {
-                n->previous->next = n->next;
-            }
-            if(n->next != nullptr) {
-                n->next->previous = n->previous;
-            }
-            length--;
-            delete n;
-            n = nullptr;
-        }
-
-        void removeFirst() {
-            Node* n = first; // prevent first from becoming null
-            remove(n);
-        }
-
-        void removeLast() {
-            Node* n = last; // prevent last from becoming null
-            remove(n);
-        }
-
-        void swap(LinkedList& other) {
-            Core::swap(first, other.first);
-            Core::swap(last, other.last);
-            Core::swap(length, other.length);
-        }
-    };
-
-}
-
-#endif

+ 0 - 203
old/include/core/data/List.hpp

@@ -1,203 +0,0 @@
-#ifndef CORE_LIST_HPP
-#define CORE_LIST_HPP
-
-#include <assert.h>
-
-#include "core/math/Math.hpp"
-#include "core/utils/AlignedData.hpp"
-#include "core/utils/ArrayString.hpp"
-#include "core/utils/New.hpp"
-
-namespace Core {
-    template<typename T>
-    class List final {
-        size_t length;
-        size_t capacity;
-        T* data;
-
-    public:
-        List() : length(0), capacity(0), data(nullptr) {
-        }
-
-        List(const List& other)
-            : length(0), capacity(other.capacity),
-              data(allocate(other.capacity)) {
-            for(const T& t : other) {
-                unsafeAdd(t);
-            }
-        }
-
-        List(List&& other) : List() {
-            swap(other);
-        }
-
-        ~List() {
-            clear();
-            delete[] reinterpret_cast<AlignedType<T>*>(data);
-        }
-
-        List& operator=(List other) {
-            swap(other);
-            return *this;
-        }
-
-        T* begin() {
-            return data;
-        }
-
-        T* end() {
-            return data + length;
-        }
-
-        const T* begin() const {
-            return data;
-        }
-
-        const T* end() const {
-            return data + length;
-        }
-
-        void reserve(size_t n) {
-            if(n > capacity) {
-                setSize(n);
-            }
-        }
-
-        void shrink() {
-            if(length != capacity) {
-                setSize(length);
-            }
-        }
-
-        void resize(size_t n, const T& t) {
-            if(length < n) {
-                reserve(n);
-                for(size_t i = n - length; i != 0; i--) {
-                    unsafeAdd(t);
-                }
-            } else if(length > n) {
-                for(size_t i = n; i < length; i++) {
-                    data[i].~T();
-                }
-                length = n;
-            }
-        }
-
-        void resize(size_t n) {
-            if(length < n) {
-                reserve(n);
-                for(size_t i = n - length; i != 0; i--) {
-                    unsafeAdd(T());
-                }
-            } else if(length > n) {
-                for(size_t i = n; i < length; i++) {
-                    data[i].~T();
-                }
-                length = n;
-            }
-        }
-
-        template<typename... Args>
-        T& put(Args&&... args) {
-            ensureCapacity();
-            return *unsafeAdd(Core::forward<Args>(args)...);
-        }
-
-        template<typename... Args>
-        List& add(Args&&... args) {
-            put(Core::forward<Args>(args)...);
-            return *this;
-        }
-
-        T& operator[](size_t index) {
-            return data[index];
-        }
-
-        const T& operator[](size_t index) const {
-            return data[index];
-        }
-
-        size_t getLength() const {
-            return length;
-        }
-
-        size_t getCapacity() const {
-            return capacity;
-        }
-
-        void clear() {
-            for(size_t i = 0; i < length; i++) {
-                data[i].~T();
-            }
-            length = 0;
-        }
-
-        void removeBySwap(size_t index) {
-            assert(index < length);
-            length--;
-            if(index != length) {
-                data[index] = Core::move(data[length]);
-            }
-            data[length].~T();
-        }
-
-        void remove(size_t index) {
-            assert(index < length);
-            length--;
-            T* currentT = begin() + index;
-            T* endT = end();
-            while(currentT != endT) {
-                T* nextT = currentT + 1;
-                *currentT = Core::move(*nextT);
-                currentT = nextT;
-            }
-            endT->~T();
-        }
-
-        void removeLast() {
-            removeBySwap(length - 1);
-        }
-
-        void toString(BufferString& s) const {
-            Core::toString(s, *this);
-        }
-
-        void swap(List& other) {
-            Core::swap(length, other.length);
-            Core::swap(capacity, other.capacity);
-            Core::swap(data, other.data);
-        }
-
-    private:
-        static T* allocate(size_t n) {
-            if(n <= 0) {
-                return nullptr;
-            }
-            return reinterpret_cast<T*>(new(noThrow) AlignedType<T>[n]);
-        }
-
-        void ensureCapacity() {
-            if(length >= capacity) {
-                reserve(capacity + Math::max(4lu, capacity / 4));
-            }
-        }
-
-        // does not check for capacity
-        template<typename... Args>
-        T* unsafeAdd(Args&&... args) {
-            return new(data + length++) T(Core::forward<Args>(args)...);
-        }
-
-        void setSize(size_t n) {
-            List copy;
-            copy.data = allocate(n);
-            copy.capacity = n;
-            for(size_t i = 0; i < length; i++) {
-                copy.unsafeAdd(Core::move(data[i]));
-            }
-            swap(copy);
-        }
-    };
-}
-
-#endif

+ 0 - 12
old/include/core/io/File.hpp

@@ -1,12 +0,0 @@
-#ifndef CORE_FILE_HPP
-#define CORE_FILE_HPP
-
-#include <limits.h>
-
-#include "core/utils/ArrayString.hpp"
-
-namespace Core {
-    using Path = ArrayString<PATH_MAX>;
-}
-
-#endif

+ 0 - 29
old/include/core/io/FileReader.hpp

@@ -1,29 +0,0 @@
-#ifndef CORE_FILE_READER_HPP
-#define CORE_FILE_READER_HPP
-
-#include <stdio.h>
-
-#include "core/io/File.hpp"
-
-namespace Core {
-    class FileReader final {
-        FILE* file;
-        Path path;
-
-    public:
-        FileReader();
-        FileReader(const FileReader& other) = delete;
-        FileReader(FileReader&& other);
-        ~FileReader();
-        FileReader& operator=(const FileReader& other) = delete;
-        FileReader& operator=(FileReader&& other);
-        const Path& getPath() const;
-        Error open(const Path& path);
-        Error open(const char* path);
-        Error readChar(int& c);
-        Error readChars(char* buffer, size_t bufferSize);
-        void swap(FileReader& other);
-    };
-}
-
-#endif

+ 0 - 24
old/include/core/utils/Check.hpp

@@ -1,24 +0,0 @@
-#ifndef CORE_CHECK_HPP
-#define CORE_CHECK_HPP
-
-#if defined(__cplusplus) && __cplusplus > 201700L
-#define check_return [[nodiscard]]
-#elif defined(__STDC_VERSION__) && __STDC_VERSION__ > 202300L
-#define check_return [[nodiscard]]
-#elif defined(__GNUC__)
-#define check_return __attribute__((warn_unused_result))
-#else
-#error "please add a 'check_return' option"
-#endif
-
-#if defined(__GNUC__)
-#define check_format(format_index, arg_start_index)                            \
-    __attribute__((format(printf, format_index, arg_start_index)))
-#else
-#error "please add a 'check_format' option"
-#endif
-
-#define CError check_return Core::Error
-#define cbool check_return bool
-
-#endif

+ 0 - 79
old/include/core/utils/Error.hpp

@@ -1,79 +0,0 @@
-#ifndef CORE_ERROR_HPP
-#define CORE_ERROR_HPP
-
-#include "core/utils/Check.hpp"
-#include "core/utils/Types.hpp"
-
-namespace Core {
-    struct Error {
-        using Code = unsigned int;
-        static_assert(sizeof(Code) >= 4, "error code too small");
-        Code code;
-
-        constexpr Error(Code c) : code(c) {
-        }
-
-        bool check() const {
-            return code != 0;
-        }
-
-        bool contains(Error e) const {
-            return code & e.code;
-        }
-
-        bool operator==(Error e) const {
-            return code == e.code;
-        }
-
-        bool operator!=(Error e) const {
-            return !(*this == e);
-        }
-
-        Error& operator|=(Error e) {
-            code |= e.code;
-            return *this;
-        }
-
-        Error operator|(Error e) const {
-            e |= *this;
-            return e;
-        }
-    };
-
-    namespace ErrorCode {
-        static constexpr Error NONE = 0;
-        static constexpr Error ERROR = 1 << 0;
-        static constexpr Error NEGATIVE_ARGUMENT = 1 << 1;
-        static constexpr Error CAPACITY_REACHED = 1 << 2;
-        static constexpr Error BLOCKED_STDOUT = 1 << 3;
-        static constexpr Error OUT_OF_MEMORY = 1 << 4;
-        static constexpr Error INVALID_CHAR = 1 << 5;
-        static constexpr Error NOT_FOUND = 1 << 6;
-        static constexpr Error INVALID_STATE = 1 << 7;
-        static constexpr Error INVALID_INDEX = 1 << 8;
-        static constexpr Error INVALID_ARGUMENT = 1 << 9;
-        static constexpr Error TIME_NOT_AVAILABLE = 1 << 10;
-        static constexpr Error SLEEP_INTERRUPTED = 1 << 11;
-        static constexpr Error THREAD_ERROR = 1 << 12;
-        static constexpr Error MUTEX_ERROR = 1 << 13;
-        static constexpr Error EXISTING_KEY = 1 << 14;
-        static constexpr Error CANNOT_OPEN_FILE = 1 << 15;
-        static constexpr Error END_OF_FILE = 1 << 16;
-    }
-
-    size_t toString(Error e, char* buffer, size_t size);
-
-    inline bool checkError(Error& storage, Error e) {
-        return (storage = e).check();
-    }
-
-#define CORE_RETURN_ERROR(checked)                                             \
-    {                                                                          \
-        Core::Error error = Core::ErrorCode::NONE;                             \
-        if(checkError(error, checked)) [[unlikely]] {                          \
-            return error;                                                      \
-        }                                                                      \
-    }
-}
-
-#endif

+ 0 - 80
old/include/core/utils/Logger.hpp

@@ -1,80 +0,0 @@
-#ifndef CORE_LOGGER_HPP
-#define CORE_LOGGER_HPP
-
-#include "core/utils/ArrayString.hpp"
-
-namespace Core::Logger {
-    enum class Level { ERROR, WARNING, INFO, DEBUG };
-    extern Level level;
-
-    [[maybe_unused]] static constexpr const char* COLOR_RED = "\33[1;31m";
-    [[maybe_unused]] static constexpr const char* COLOR_YELLOW = "\33[1;33m";
-    [[maybe_unused]] static constexpr const char* COLOR_GRAY = "\33[1;37m";
-    [[maybe_unused]] static constexpr const char* COLOR_GREEN = "\33[1;32m";
-    [[maybe_unused]] static constexpr const char* COLOR_RESET = "\33[0m";
-
-    const char* getFileName(const char* path);
-
-    // aborts on critical logging failure
-    template<typename... Args>
-    void log(Level l, const char* file, int line, const char* prefix,
-             const char* tag, const char* format, Args&&... args) {
-        if(Core::Logger::level < l) {
-            return;
-        }
-        file = getFileName(file);
-        Core::ArrayString<2048> s;
-        s.append(prefix).append(tag).append("#:# | ");
-        s.format(file, line);
-        s.append(format);
-        s.format(Core::forward<Args>(args)...);
-        s.append(COLOR_RESET);
-        s.printLine();
-    }
-
-    template<typename... Args>
-    void log(const char* prefix, const char* format, Args&&... args) {
-        Core::ArrayString<2048> s;
-        s.append(prefix).append(format);
-        s.format(Core::forward<Args>(args)...);
-        s.append(COLOR_RESET).printLine();
-    }
-}
-
-#if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 1
-#define CORE_LOG_ERROR(format, ...)                                            \
-    log(Core::Logger::Level::ERROR, __FILE__, __LINE__,                        \
-        Core::Logger::COLOR_RED, "[ERROR] ",                                   \
-        format __VA_OPT__(, ) __VA_ARGS__);
-#else
-#define CORE_LOG_ERROR(format, ...)
-#endif
-
-#if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 2
-#define CORE_LOG_WARNING(format, ...)                                          \
-    log(Core::Logger::Level::WARNING, __FILE__, __LINE__,                      \
-        Core::Logger::COLOR_YELLOW, "[WARNING] ",                              \
-        format __VA_OPT__(, ) __VA_ARGS__);
-#else
-#define CORE_LOG_WARNING(format, ...)
-#endif
-
-#if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 3
-#define CORE_LOG_INFO(format, ...)                                             \
-    log(Core::Logger::Level::INFO, __FILE__, __LINE__,                         \
-        Core::Logger::COLOR_GRAY, "[INFO] ",                                   \
-        format __VA_OPT__(, ) __VA_ARGS__);
-#else
-#define CORE_LOG_INFO(format, ...)
-#endif
-
-#if defined(CORE_LOG_LEVEL) && CORE_LOG_LEVEL >= 4
-#define CORE_LOG_DEBUG(format, ...)                                            \
-    log(Core::Logger::Level::DEBUG, __FILE__, __LINE__,                        \
-        Core::Logger::COLOR_GREEN, "[DEBUG] ",                                 \
-        format __VA_OPT__(, ) __VA_ARGS__);
-#else
-#define CORE_LOG_DEBUG(format, ...)
-#endif
-
-#endif

+ 0 - 19
old/include/core/utils/New.hpp

@@ -1,19 +0,0 @@
-#ifndef CORE_NEW_HPP
-#define CORE_NEW_HPP
-
-using size_t = decltype(sizeof(0));
-
-struct NoThrow {
-    explicit NoThrow() = default;
-};
-[[maybe_unused]] static constexpr NoThrow noThrow;
-
-void* operator new(size_t bytes, const NoThrow&) noexcept;
-void* operator new[](size_t bytes, const NoThrow&) noexcept;
-void operator delete(void* p) noexcept;
-void operator delete[](void* p) noexcept;
-void operator delete(void* p, size_t bytes) noexcept;
-void operator delete[](void* p, size_t bytes) noexcept;
-void* operator new(size_t bytes, void* p) noexcept;
-
-#endif

+ 0 - 17
old/include/core/utils/Types.hpp

@@ -1,17 +0,0 @@
-#ifndef CORE_TYPES_HPP
-#define CORE_TYPES_HPP
-
-#include <stdint.h>
-
-using i64 = int64_t;
-using i32 = int32_t;
-using i16 = int16_t;
-using i8 = int8_t;
-using u64 = uint64_t;
-using u32 = uint32_t;
-using u16 = uint16_t;
-using u8 = uint8_t;
-using c32 = char32_t;
-using size_t = decltype(sizeof(int));
-
-#endif

+ 0 - 48
old/include/core/utils/Utility.hpp

@@ -1,48 +0,0 @@
-#ifndef CORE_UTILITY_HPP
-#define CORE_UTILITY_HPP
-
-#include "core/utils/Check.hpp"
-#include "core/utils/Error.hpp"
-#include "core/utils/Types.hpp"
-
-namespace Core {
-    template<typename T, typename C = int>
-    C popCount(const T& t) {
-        static constexpr C map[16] = {0, 1, 1, 2, 1, 2, 2, 3,
-                                      1, 2, 2, 3, 2, 3, 3, 4};
-        C sum = 0;
-        for(size_t i = 0; i < sizeof(T) * 8; i += 4) {
-            sum += map[(t >> i) & 0xF];
-        }
-        return sum;
-    }
-
-    using ExitHandler = void (*)(int, void*);
-    void exitWithHandler(const char* file, int line, int value);
-    void setExitHandler(ExitHandler eh, void* data);
-#define CORE_EXIT(exitValue)                                                   \
-    Core::exitWithHandler(__FILE__, __LINE__, exitValue)
-
-    size_t toString(signed short s, char* buffer, size_t size);
-    size_t toString(unsigned short s, char* buffer, size_t size);
-    size_t toString(signed int i, char* buffer, size_t size);
-    size_t toString(unsigned int i, char* buffer, size_t size);
-    size_t toString(signed long l, char* buffer, size_t size);
-    size_t toString(unsigned long l, char* buffer, size_t size);
-    size_t toString(signed long long ll, char* buffer, size_t size);
-    size_t toString(unsigned long long ll, char* buffer, size_t size);
-    size_t toString(float f, char* buffer, size_t size);
-    size_t toString(double d, char* buffer, size_t size);
-    size_t toString(long double ld, char* buffer, size_t size);
-
-    void print(int c);
-    void print(const char* s);
-    void printLine(const char* s);
-
-    using OutOfMemoryHandler = void (*)(void*);
-    void setOutOfMemoryHandler(OutOfMemoryHandler h, void* data);
-    void* allocate(size_t n);
-    void* reallocate(void* p, size_t n);
-}
-
-#endif

+ 0 - 20
old/src/Error.cpp

@@ -1,20 +0,0 @@
-#include "core/utils/Error.hpp"
-
-size_t Core::toString(Error e, char* buffer, size_t size) {
-    size_t written = 0;
-    Error::Code c = e.code;
-    for(size_t i = size; i > 1; i--) {
-        *(buffer++) = (c & 1) ? '1' : '0';
-        written++;
-        c >>= 1;
-        if(c == 0) {
-            break;
-        }
-    }
-    *buffer = '\0';
-    while(c != 0) {
-        written++;
-        c >>= 1;
-    }
-    return written;
-}

+ 0 - 73
old/src/FileReader.cpp

@@ -1,73 +0,0 @@
-#include "core/io/FileReader.hpp"
-
-#include "ErrorSimulator.hpp"
-#include "core/utils/Logger.hpp"
-
-Core::FileReader::FileReader() : file(nullptr), path() {
-}
-
-Core::FileReader::FileReader(FileReader&& other) : FileReader() {
-    swap(other);
-}
-
-Core::FileReader::~FileReader() {
-    if(file != nullptr) {
-        int r = fclose(file);
-        if(r != 0 || CORE_FILE_CLOSE_FAIL) {
-            CORE_LOG_WARNING("Cannot close file #: #", path, r);
-        }
-        file = nullptr;
-    }
-}
-
-Core::FileReader& Core::FileReader::operator=(FileReader&& other) {
-    swap(other);
-    return *this;
-}
-
-const Core::Path& Core::FileReader::getPath() const {
-    return path;
-}
-
-Core::Error Core::FileReader::open(const Path& p) {
-    if(file != nullptr) {
-        return ErrorCode::INVALID_STATE;
-    }
-    path = p;
-    file = fopen(path, "rb");
-    return file != nullptr ? ErrorCode::NONE : ErrorCode::CANNOT_OPEN_FILE;
-}
-
-Core::Error Core::FileReader::open(const char* p) {
-    if(file != nullptr) {
-        return ErrorCode::INVALID_STATE;
-    }
-    path.append(p);
-    file = fopen(path, "rb");
-    return file != nullptr ? ErrorCode::NONE : ErrorCode::CANNOT_OPEN_FILE;
-}
-
-Core::Error Core::FileReader::readChar(int& c) {
-    if(file == nullptr) {
-        return ErrorCode::INVALID_STATE;
-    }
-    c = fgetc(file);
-    return c == EOF ? ErrorCode::END_OF_FILE : ErrorCode::NONE;
-}
-
-Core::Error Core::FileReader::readChars(char* buffer, size_t bufferSize) {
-    if(file == nullptr) {
-        return ErrorCode::INVALID_STATE;
-    } else if(bufferSize <= 0) {
-        return ErrorCode::INVALID_ARGUMENT;
-    }
-    size_t size = bufferSize - 1;
-    size_t readBytes = fread(buffer, 1, size, file);
-    buffer[readBytes] = '\0';
-    return readBytes != size ? ErrorCode::END_OF_FILE : ErrorCode::NONE;
-}
-
-void Core::FileReader::swap(FileReader& other) {
-    Core::swap(file, other.file);
-    Core::swap(path, other.path);
-}

+ 0 - 14
old/src/Logger.cpp

@@ -1,14 +0,0 @@
-#include "core/utils/Logger.hpp"
-
-Core::Logger::Level Core::Logger::level = Core::Logger::Level::DEBUG;
-
-const char* Core::Logger::getFileName(const char* path) {
-    int end = 0;
-    while(path[end] != '\0') {
-        end++;
-    }
-    while(end > 0 && path[end - 1] != '/') {
-        end--;
-    }
-    return path + end;
-}

+ 0 - 33
old/src/New.cpp

@@ -1,33 +0,0 @@
-#include "core/utils/New.hpp"
-
-#include <stdlib.h>
-
-#include "core/utils/Utility.hpp"
-
-void* operator new(size_t bytes, const NoThrow&) noexcept {
-    return Core::allocate(bytes);
-}
-
-void* operator new[](size_t bytes, const NoThrow&) noexcept {
-    return Core::allocate(bytes);
-}
-
-void operator delete(void* p) noexcept {
-    free(p);
-}
-
-void operator delete[](void* p) noexcept {
-    free(p);
-}
-
-void operator delete(void* p, size_t) noexcept {
-    operator delete(p);
-}
-
-void operator delete[](void* p, size_t) noexcept {
-    free(p);
-}
-
-void* operator new(size_t, void* p) noexcept {
-    return p;
-}

+ 0 - 120
old/src/Utility.cpp

@@ -1,120 +0,0 @@
-#include "core/utils/Utility.hpp"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "ErrorSimulator.hpp"
-#include "core/utils/Error.hpp"
-#include "core/utils/Logger.hpp"
-
-static Core::ExitHandler exitHandler = nullptr;
-static void* exitData = nullptr;
-static Core::OutOfMemoryHandler outOfMemoryHandler = nullptr;
-static void* outOfMemoryData = nullptr;
-
-void Core::exitWithHandler(const char* file, int line, int value) {
-    if(value != 0) {
-        printf("%sExit from %s:%d with value %d%s\n", Core::Logger::COLOR_RED,
-               Core::Logger::getFileName(file), line, value,
-               Core::Logger::COLOR_RESET);
-    }
-    if(exitHandler != nullptr) {
-        exitHandler(value, exitData);
-    }
-    exit(value);
-}
-
-void Core::setExitHandler(ExitHandler eh, void* data) {
-    exitHandler = eh;
-    exitData = data;
-}
-
-#define CORE_TO_STRING(type, cast, format)                                     \
-    size_t Core::toString(type t, char* buffer, size_t size) {                 \
-        int w = snprintf(buffer, size, format, static_cast<cast>(t));          \
-        return w < 0 ? 0 : static_cast<size_t>(w);                             \
-    }
-
-CORE_TO_STRING(signed short, signed short, "%hd")
-CORE_TO_STRING(unsigned short, unsigned short, "%hu")
-CORE_TO_STRING(signed int, signed int, "%d")
-CORE_TO_STRING(unsigned int, unsigned int, "%u")
-CORE_TO_STRING(signed long, signed long, "%ld")
-CORE_TO_STRING(unsigned long, unsigned long, "%lu")
-CORE_TO_STRING(signed long long, signed long long, "%lld")
-CORE_TO_STRING(unsigned long long, unsigned long long, "%llu")
-CORE_TO_STRING(float, double, "%.2f")
-CORE_TO_STRING(double, double, "%.2lf")
-CORE_TO_STRING(long double, long double, "%.2Lf")
-
-void Core::print(int c) {
-    if(putchar(c) < 0) {
-        CORE_EXIT(ErrorCode::BLOCKED_STDOUT.code); // CoverageIgnore
-    }
-}
-
-void Core::print(const char* s) {
-    if(fputs(s, stdout) < 0) {
-        CORE_EXIT(ErrorCode::BLOCKED_STDOUT.code); // CoverageIgnore
-    }
-}
-
-void Core::printLine(const char* s) {
-    if(puts(s) < 0) {
-        CORE_EXIT(ErrorCode::BLOCKED_STDOUT.code); // CoverageIgnore
-    }
-}
-
-void Core::setOutOfMemoryHandler(OutOfMemoryHandler h, void* data) {
-    outOfMemoryHandler = h;
-    outOfMemoryData = data;
-}
-
-void* Core::allocate(size_t n) {
-    // deny too large allocations instantly
-    // this makes LTO happy
-    if(n >= 1024lu * 1024lu * 1024lu * 64lu) {
-        CORE_EXIT(ErrorCode::OUT_OF_MEMORY.code); // CoverageIgnore
-    }
-    void* p = malloc(n);
-#ifdef ERROR_SIMULATOR
-    if(CORE_ALLOC_FAIL && p != nullptr) {
-        free(p);
-        p = nullptr;
-    }
-#endif
-    while(p == nullptr && outOfMemoryHandler != nullptr) {
-        outOfMemoryHandler(outOfMemoryData);
-        p = malloc(n);
-    }
-    if(p == nullptr) {
-        CORE_EXIT(ErrorCode::OUT_OF_MEMORY.code); // CoverageIgnore
-    }
-    return p;
-}
-
-void* Core::reallocate(void* oldP, size_t n) {
-    if(n <= 0) {
-        free(oldP);
-        return nullptr;
-    }
-    void* p = realloc(oldP, n);
-#ifdef ERROR_SIMULATOR
-    if(CORE_ALLOC_FAIL && p != nullptr) {
-        oldP = p;
-        p = nullptr;
-    }
-#endif
-    // this double check is to prevent the compiler from complaining
-    if(p == nullptr) {
-        while(p == nullptr && outOfMemoryHandler != nullptr) {
-            outOfMemoryHandler(outOfMemoryData);
-            p = realloc(oldP, n);
-        }
-    }
-    if(p == nullptr) {
-        CORE_EXIT(ErrorCode::OUT_OF_MEMORY.code); // CoverageIgnore
-    }
-    return p;
-}

+ 0 - 189
old/tasks

@@ -1,189 +0,0 @@
-#!/bin/bash
-set -e
-clear
-cd $(dirname $0)
-
-compiler="g++"
-if [ -e compiler ]; then
-    compiler=$(cat compiler)
-    echo "compiling with $compiler"
-fi
-
-printHelpExit() {
-    echo "$0 clean           | remove build results"
-    echo "$0 build <type>    | build everything"
-    echo "$0 install         | move build results into the install folder"
-    echo "$0 test <type>     | run the tests"
-    echo "$0 valgrind <type> | run the tests with valgrind"
-    echo "$0 coverage        | generate code coverage"
-    echo "$0 performance     | run the performance tests"
-    echo "$0 final           | find classes / structs which are not final"
-    echo "$0 macro           | find macros without CORE" 
-    echo "$0 include         | find system includes" 
-    echo "$0 time            | check build time"
-    exit 0
-}
-
-task=$1
-if [ -z "$task" ]; then
-    printHelpExit
-fi
-
-# task vars
-build_debug=false
-build_release=false
-
-test_debug=false
-test_release=false
-
-valgrind=""
-performance=false
-time=false
-install=false
-coverage=false
-
-export CMAKE_EXPORT_COMPILE_COMMANDS=true
-
-# parsing
-if [ "$task" = "clean" ]; then
-    rm -rf build_debug build_release install
-elif [ "$task" = "build" ]; then
-    type=$2
-    if [ "$type" = "debug" ]; then
-        build_debug=true
-    elif [ "$type" = "release" ]; then
-        build_release=true
-    elif [ "$type" = "all" ]; then
-        build_debug=true
-        build_release=true
-    else
-        echo "Valid build types are: debug, release, all"
-        printHelpExit
-    fi
-elif [ "$task" = "install" ]; then
-    build_release=true
-    install=true
-elif [ "$task" = "coverage" ]; then
-    build_debug=true
-    test_debug=true
-    coverage=true
-elif [ "$task" = "test" ]; then
-    type=$2
-    if [ "$type" = "debug" ]; then
-        build_debug=true
-        test_debug=true
-    elif [ "$type" = "release" ]; then
-        build_release=true
-        test_release=true
-    elif [ "$type" = "all" ]; then
-        build_debug=true
-        test_debug=true
-        build_release=true
-        test_release=true
-    else
-        echo "Valid test types are: debug, release, all"
-        printHelpExit
-    fi
-elif [ "$task" = "valgrind" ]; then
-    type=$2
-    if [ "$type" = "debug" ]; then
-        build_debug=true
-        test_debug=true
-    elif [ "$type" = "release" ]; then
-        build_release=true
-        test_release=true
-    elif [ "$type" = "all" ]; then
-        build_debug=true
-        test_debug=true
-        build_release=true
-        test_release=true
-    else
-        echo "Valid valgrind types are: debug, release, all"
-        printHelpExit
-    fi
-    valgrind="valgrind"
-elif [ "$task" = "performance" ]; then
-    build_release=true
-    performance=true
-elif [ "$task" = "time" ]; then
-    build_release=true
-    time=true
-elif [ "$task" = "final" ]; then
-    grep -r " class" src include | grep -v -E 'final|enum|.git' || true
-    grep -r " struct" src include | grep -v -E 'final|enum|.git' || true
-    exit 0
-elif [ "$task" = "macro" ]; then
-    grep -r "#define" src include | grep -v " CORE" || true
-    exit 0
-elif [ "$task" = "include" ]; then
-    echo "System includes in header files:"
-    grep -r "#include <" src include | grep "\.hpp" || true
-    echo "-------------------------------------------------" 
-    echo "System includes in source files:"
-    grep -r "#include <" src include | grep "\.cpp" || true
-    exit 0
-else
-    echo "unknown task"
-    printHelpExit
-fi
-
-# task execution
-buildProfile() {
-    folder=$1
-    shift 1
-    if [ ! -e "$folder" ]; then 
-        cmake -B "$folder" -S . -G Ninja -DCMAKE_CXX_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=./install $@
-    fi
-    ninja -C "$folder"
-}
-
-if $build_debug; then
-    buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
-fi
-if $build_release; then
-    buildProfile build_release -DCMAKE_BUILD_TYPE=Release
-fi
-if $install; then
-    ninja -C build_release install
-fi
-if $test_debug; then
-    cd build_debug
-    $valgrind ./test light $valgrind || true
-    cd ..
-fi
-if $test_release; then
-    cd build_release
-    $valgrind ./test light $valgrind || true
-    cd ..
-fi
-if $performance; then
-    cd build_release
-    ./performance
-    cd ..
-fi
-if $time; then
-    lines=$(cat build_release/.ninja_log | grep "^[0-9]")
-
-    startMillis=0
-    endMillis=0
-    name=""
-    i=0
-    output=""
-    for arg in $lines; do
-        if [ $i == 0 ]; then
-            startMillis=$arg
-        elif [ $i == 1 ]; then
-            endMillis=$arg
-        elif [ $i == 3 ]; then
-            name=$arg
-            diff=$(expr $endMillis - $startMillis)
-            output="${output}\n$diff $name"
-        fi
-        i=$(expr $(expr $i + 1) % 5) && true
-    done
-    printf "$output" | sort -n
-fi
-if $coverage; then
-    gcovr -r . build_debug -e test -e performance \
-        --exclude-lines-by-pattern ".*CoverageIgnore.*"
-fi

+ 0 - 69
old/test/Main.cpp

@@ -1,69 +0,0 @@
-#include <locale.h>
-#include <string.h>
-
-#include "../src/ErrorSimulator.hpp"
-#include "Test.hpp"
-#include "Tests.hpp"
-#include "core/utils/ArrayString.hpp"
-#include "core/utils/Utility.hpp"
-
-static void onExit(int code, void* data) {
-    unsigned int i = *static_cast<unsigned int*>(data);
-    Core::ArrayString<1024> s;
-    s.append("Hello from exit #: #");
-    s.format(code, i);
-    s.printLine();
-    Core::print('A');
-    Core::Test::finalize();
-}
-
-int main(int argAmount, const char** args) {
-    setlocale(LC_ALL, "en_US.utf8");
-    bool light = false;
-    for(int i = 0; i < argAmount; i++) {
-        if(strcmp(args[i], "light") == 0) {
-            light = true;
-        }
-    }
-    Core::testArrayList(light);
-    Core::testArrayString();
-    Core::testArray();
-    Core::testBitArray();
-    Core::testBox();
-    Core::testBuffer(light);
-    Core::testBufferedValue();
-    Core::testClock(light);
-    Core::testColor();
-    Core::testComponents();
-    Core::testError();
-    Core::testFileReader();
-    Core::testFrustum();
-    Core::testHashedString();
-    Core::testHashMap(light);
-    Core::testLinkedList(light);
-    Core::testList(light);
-    Core::testMath();
-    Core::testMatrixStack(light);
-    Core::testMatrix();
-    Core::testNew();
-    Core::testPlane();
-    Core::testQuaternion();
-    Core::testRandom(light);
-    Core::testRingBuffer();
-    Core::testStack(light);
-    Core::testThread();
-    Core::testUniquePointer();
-    Core::testUtility();
-    Core::testVector();
-    Core::testView();
-
-    Core::Logger::level = Core::Logger::Level::WARNING;
-    CORE_LOG_DEBUG("You won't see this!");
-    Core::Logger::level = Core::Logger::Level::DEBUG;
-
-    unsigned int data = 123456789;
-    Core::setExitHandler(onExit, &data);
-
-    CORE_EXIT(1);
-    return 0;
-}

+ 0 - 27
old/test/Test.cpp

@@ -1,27 +0,0 @@
-#include "Test.hpp"
-
-namespace Internal = Core::Test::Internal;
-
-Core::HashMap<Internal::FileName, Internal::Result> Internal::results;
-
-void Internal::warn(const char* file, int line, Error e) {
-    Logger::log("#:# | #", Logger::getFileName(file), line, e);
-}
-
-bool Internal::checkFloat(const char* file, int line, float wanted,
-                          float actual, float error) {
-    float diff = wanted - actual;
-    diff = diff < 0.0f ? -diff : diff;
-    return check(file, line, wanted, actual, diff <= error);
-}
-
-void Core::Test::finalize() {
-    for(const auto& e : Internal::results) {
-        const char* color = e.value.successTests == e.value.tests
-                                ? Logger::COLOR_GREEN
-                                : Logger::COLOR_RED;
-        Logger::log(color, "# - # / # tests succeeded", e.getKey(),
-                    e.value.successTests, e.value.tests);
-    }
-    Internal::results.clear();
-}

+ 0 - 94
old/test/Test.hpp

@@ -1,94 +0,0 @@
-#ifndef CORE_TEST_HPP
-#define CORE_TEST_HPP
-
-#include "core/data/HashMap.hpp"
-#include "core/math/Vector.hpp"
-#include "core/utils/HashedString.hpp"
-#include "core/utils/Logger.hpp"
-
-namespace Core::Test {
-    namespace Internal {
-        struct Result final {
-            int tests = 0;
-            int successTests = 0;
-        };
-        using FileName = HashedString<256>;
-        extern HashMap<FileName, Result> results;
-
-        void warn(const char* file, int line, Error e);
-
-        template<typename T>
-        bool check(const char* file, int line, const T& wanted, const T& actual,
-                   bool c) {
-            file = Logger::getFileName(file);
-            Error e = ErrorCode::NONE;
-            FileName fileName(file);
-            Result* result = results.search(fileName);
-            if(result == nullptr && !results.tryEmplace(result, fileName)) {
-                warn(file, line, e);
-                return false;
-            }
-            result->tests++;
-            if(c) {
-                result->successTests++;
-                return true;
-            }
-            Core::Logger::log(Core::Logger::COLOR_RED,
-                              "#:# - expected '#' got '#'", fileName, line,
-                              wanted, actual);
-            return false;
-        }
-
-        template<typename T>
-        bool checkEqual(const char* file, int line, const T& wanted,
-                        const T& actual) {
-            return check(file, line, wanted, actual, wanted == actual);
-        }
-
-        template<typename A, typename B>
-        bool checkString(const char* file, int line, const A& wanted,
-                         const B& actual) {
-            ArrayString<2048> a;
-            a.append(wanted);
-            ArrayString<2048> b;
-            b.append(actual);
-            return checkEqual(file, line, a, b);
-        }
-
-        bool checkFloat(const char* file, int line, float wanted, float actual,
-                        float error);
-
-        template<size_t N, typename T>
-        bool checkVector(const char* file, int line,
-                         const Core::Vector<N, T>& wanted,
-                         const Core::Vector<N, T>& actual, float error) {
-            bool result = true;
-            for(size_t i = 0; i < N; i++) {
-                result &= checkFloat(file, line, static_cast<float>(wanted[i]),
-                                     static_cast<float>(actual[i]), error);
-            }
-            return result;
-        }
-    }
-    void finalize();
-}
-
-#define CORE_TEST_EQUAL(wanted, actual)                                        \
-    Core::Test::Internal::checkEqual<Core::RemoveReference<decltype(actual)>>( \
-        __FILE__, __LINE__, wanted, actual)
-#define CORE_TEST_STRING(wanted, actual)                                       \
-    Core::Test::Internal::checkString(__FILE__, __LINE__, wanted, actual)
-#define CORE_TEST_FALSE(actual) CORE_TEST_EQUAL(false, actual)
-#define CORE_TEST_TRUE(actual) CORE_TEST_EQUAL(true, actual)
-#define CORE_TEST_ERROR(actual) CORE_TEST_EQUAL(Core::ErrorCode::NONE, actual)
-#define CORE_TEST_NULL(actual) CORE_TEST_EQUAL(true, actual == nullptr)
-// double check to make the null check clear for the compiler
-#define CORE_TEST_NOT_NULL(actual)                                             \
-    (CORE_TEST_EQUAL(true, (actual) != nullptr) && (actual) != nullptr)
-#define CORE_TEST_FLOAT(wanted, actual, error)                                 \
-    Core::Test::Internal::checkFloat(__FILE__, __LINE__, wanted, actual, error)
-#define CORE_TEST_VECTOR(wanted, actual)                                       \
-    Core::Test::Internal::checkVector(__FILE__, __LINE__, wanted, actual,      \
-                                      0.0001f)
-
-#endif

部分文件因文件數量過多而無法顯示