From 13a8f07e32cbe27db1c7f4042a84c1ddd17c559f Mon Sep 17 00:00:00 2001 From: Ilusha <63184036+IlyaShurupov@users.noreply.github.com> Date: Fri, 30 Jun 2023 14:02:55 +0000 Subject: [PATCH] Formatting code --- Allocators/private/ChunkAllocator.cpp | 2 +- Allocators/private/HeapAllocator.cpp | 4 +- Allocators/private/HeapAllocatorGlobal.cpp | 2 +- Allocators/public/ChunkAllocator.hpp | 2 +- Allocators/public/HeapAllocatorGlobal.hpp | 2 +- Allocators/tests/Tests.cpp | 433 +++++----- Containers/private/Containers.cpp | 16 +- Containers/public/AvlTree.hpp | 250 +++--- Containers/public/ContainersCommon.hpp | 30 +- Containers/public/List.hpp | 242 +++--- Containers/public/Map.hpp | 453 +++++----- Containers/tests/AvlTest.cpp | 180 ++-- Containers/tests/ListTest.cpp | 92 +- Containers/tests/MapTest.cpp | 162 ++-- Containers/tests/Tests.cpp | 32 +- Containers/tests/Tests.hpp | 86 +- Modules/private/Assert.cpp | 14 +- Modules/private/Common.cpp | 74 +- Modules/private/Environment.cpp | 10 +- Modules/private/Module.cpp | 82 +- Modules/public/Assert.hpp | 2 +- Modules/public/Common.hpp | 78 +- Modules/public/Environment.hpp | 210 ++--- Modules/public/Module.hpp | 36 +- Modules/public/TypeInfo.hpp | 929 ++++++++++----------- Modules/tests/Tests.cpp | 22 +- TODO | 2 - Utils/private/Debugging.cpp | 250 +++--- Utils/private/Testing.cpp | 80 +- Utils/private/Timing.cpp | 106 ++- Utils/private/Utils.cpp | 124 +-- Utils/public/Debugging.hpp | 174 ++-- Utils/public/Sorting.hpp | 8 +- Utils/public/Testing.hpp | 88 +- Utils/public/Timing.hpp | 78 +- Utils/public/Utils.hpp | 108 +-- Utils/tests/Tests.cpp | 60 +- 37 files changed, 2242 insertions(+), 2281 deletions(-) diff --git a/Allocators/private/ChunkAllocator.cpp b/Allocators/private/ChunkAllocator.cpp index 3ab8b28..7040a71 100644 --- a/Allocators/private/ChunkAllocator.cpp +++ b/Allocators/private/ChunkAllocator.cpp @@ -107,7 +107,7 @@ bool ChunkAlloc::isFull() const { return !mNFreeBlocks; } bool ChunkAlloc::isEmpty() const { return mNFreeBlocks == mNBlocks; } ChunkAlloc::~ChunkAlloc() { - // TODO : check for leaks + // TODO : check for leaks if (mOwnBuff) { HeapAllocGlobal::deallocate(mBuff); } diff --git a/Allocators/private/HeapAllocator.cpp b/Allocators/private/HeapAllocator.cpp index c6e73b6..916b4c5 100644 --- a/Allocators/private/HeapAllocator.cpp +++ b/Allocators/private/HeapAllocator.cpp @@ -61,7 +61,7 @@ void HeapAlloc::deallocate(void* aPtr) { } } - HeapAllocGlobal::deallocate(head); + HeapAllocGlobal::deallocate(head); } HeapAlloc::~HeapAlloc() { @@ -69,7 +69,7 @@ HeapAlloc::~HeapAlloc() { DEBUG_BREAK("Destruction of not freed Allocator"); #ifdef MEM_STACK_TRACE - // TODO : log leaks and free them up + // TODO : log leaks and free them up #endif } } diff --git a/Allocators/private/HeapAllocatorGlobal.cpp b/Allocators/private/HeapAllocatorGlobal.cpp index 3a37688..303190a 100644 --- a/Allocators/private/HeapAllocatorGlobal.cpp +++ b/Allocators/private/HeapAllocatorGlobal.cpp @@ -140,7 +140,7 @@ HeapAllocGlobal::~HeapAllocGlobal() { DEBUG_BREAK("Destruction of not freed Allocator"); #ifdef MEM_STACK_TRACE - // TODO: log leaks + // TODO: log leaks #endif } } diff --git a/Allocators/public/ChunkAllocator.hpp b/Allocators/public/ChunkAllocator.hpp index ebc944d..21391e6 100644 --- a/Allocators/public/ChunkAllocator.hpp +++ b/Allocators/public/ChunkAllocator.hpp @@ -15,7 +15,7 @@ namespace tp { void* allocate(); void deallocate(void* aPtr); [[nodiscard]] bool isFull() const; - [[nodiscard]] bool isEmpty() const; + [[nodiscard]] bool isEmpty() const; ~ChunkAlloc(); diff --git a/Allocators/public/HeapAllocatorGlobal.hpp b/Allocators/public/HeapAllocatorGlobal.hpp index 36883cd..fd071d7 100644 --- a/Allocators/public/HeapAllocatorGlobal.hpp +++ b/Allocators/public/HeapAllocatorGlobal.hpp @@ -12,7 +12,7 @@ namespace tp { #endif static void* allocate(ualni aBlockSize); - static void deallocate(void* aPtr); + static void deallocate(void* aPtr); ~HeapAllocGlobal(); }; }; diff --git a/Allocators/tests/Tests.cpp b/Allocators/tests/Tests.cpp index dfcc514..dfd8834 100644 --- a/Allocators/tests/Tests.cpp +++ b/Allocators/tests/Tests.cpp @@ -19,287 +19,284 @@ int main() { } struct test_struct { - tp::alni val = 0; + tp::alni val = 0; - test_struct() { val = 1; } - ~test_struct() { val = -1; } + test_struct() { val = 1; } + ~test_struct() { val = -1; } - bool operator==(const test_struct& in) { return in.val == val; } + bool operator==(const test_struct& in) { return in.val == val; } }; template struct allocator_test { - test_struct data[size]; - bool is_allocated[size]; - tp::alni n_loaded = 0; + test_struct data[size]; + bool is_allocated[size]; + tp::alni n_loaded = 0; - test_struct* allocations[size]; + test_struct* allocations[size]; - tp::AbstractAllocator* alloc; - tp::AbstractAllocator* parent_alloc; - const char* allocator_name = NULL; + tp::AbstractAllocator* alloc; + tp::AbstractAllocator* parent_alloc; + const char* allocator_name = NULL; - tp::alni rand_idx(bool state) { - RAND: + tp::alni rand_idx(bool state) { + RAND: - tp::alni idx = (tp::alni)(tp::randf() * (size + 1)); - CLAMP(idx, 0, size - 1); + tp::alni idx = (tp::alni)(tp::randf() * (size + 1)); + CLAMP(idx, 0, size - 1); - if (state == is_allocated[idx]) { - goto RAND; - } - return idx; - } + if (state == is_allocated[idx]) { + goto RAND; + } + return idx; + } - allocator_test(tp::AbstractAllocator* palloc, const char* pallocator_name, - tp::AbstractAllocator* p_parent_alloc) { - allocator_name = pallocator_name; - parent_alloc = p_parent_alloc; - alloc = palloc; - for (tp::alni i = 0; i < size; i++) { - RAND: - tp::alni val = tp::alni(tp::randf() * (size + 100.f)); - for (tp::alni check_idx = 0; check_idx < size; check_idx++) { - if (data[check_idx].val == val) { - goto RAND; - } - } + allocator_test(tp::AbstractAllocator* palloc, const char* pallocator_name, tp::AbstractAllocator* p_parent_alloc) { + allocator_name = pallocator_name; + parent_alloc = p_parent_alloc; + alloc = palloc; + for (tp::alni i = 0; i < size; i++) { + RAND: + tp::alni val = tp::alni(tp::randf() * (size + 100.f)); + for (tp::alni check_idx = 0; check_idx < size; check_idx++) { + if (data[check_idx].val == val) { + goto RAND; + } + } - data[i].val = val; - is_allocated[i] = false; - allocations[i] = 0; - } - } + data[i].val = val; + is_allocated[i] = false; + allocations[i] = 0; + } + } - void verify_integrity() { - // verify data integrity - for (tp::alni i = 0; i < size; i++) { - if (is_allocated[i]) { - assert(*allocations[i] == data[i] && "data is currupted\n"); - } - } + void verify_integrity() { + // verify data integrity + for (tp::alni i = 0; i < size; i++) { + if (is_allocated[i]) { + assert(*allocations[i] == data[i] && "data is currupted\n"); + } + } - if (alloc->isWrapSupport()) assert(!alloc->isWrapCorrupted()); - if (parent_alloc && parent_alloc->isWrapSupport()) - assert(!parent_alloc->isWrapCorrupted()); + if (alloc->isWrapSupport()) assert(!alloc->isWrapCorrupted()); + if (parent_alloc && parent_alloc->isWrapSupport()) + assert(!parent_alloc->isWrapCorrupted()); - verify_sizes(); - } + verify_sizes(); + } - void verify_sizes() { - return; + void verify_sizes() { + return; #ifdef MEM_TRACE - assert(alloc->sizeInuse() == n_loaded * sizeof(test_struct) && - "invalid inuse size\n"); - assert(alloc->sizeReserved() >= n_loaded * (tp::alni)sizeof(test_struct) && - "invalid reserved size\n"); + assert(alloc->sizeInuse() == n_loaded * sizeof(test_struct) && + "invalid inuse size\n"); + assert(alloc->sizeReserved() >= n_loaded * (tp::alni)sizeof(test_struct) && + "invalid reserved size\n"); #endif - } + } - void load_item(tp::alni idx) { - if (!is_allocated[idx]) { - allocations[idx] = new (alloc) test_struct(); + void load_item(tp::alni idx) { + if (!is_allocated[idx]) { + allocations[idx] = new (alloc) test_struct(); - assert(allocations[idx] && "allocator returned NULL"); + assert(allocations[idx] && "allocator returned NULL"); - allocations[idx]->val = data[idx].val; - is_allocated[idx] = true; - n_loaded++; - verify_integrity(); - } - } + allocations[idx]->val = data[idx].val; + is_allocated[idx] = true; + n_loaded++; + verify_integrity(); + } + } - void unload_item(tp::alni idx) { - if (is_allocated[idx]) { - verify_integrity(); - delete allocations[idx]; - is_allocated[idx] = false; - n_loaded--; - verify_integrity(); - } - } + void unload_item(tp::alni idx) { + if (is_allocated[idx]) { + verify_integrity(); + delete allocations[idx]; + is_allocated[idx] = false; + n_loaded--; + verify_integrity(); + } + } - void change_states(tp::Range rg, bool state, bool reversed = false, - bool random = false) { - for (auto i : rg) { - tp::alni idx = i; + void change_states(tp::Range rg, bool state, bool reversed = false, bool random = false) { + for (auto i : rg) { + tp::alni idx = i; - if (random) { - idx = rand_idx(state); - } - else if (reversed) { - idx = size - i - 1; - } + if (random) { + idx = rand_idx(state); + } + else if (reversed) { + idx = size - i - 1; + } - (state) ? load_item(idx) : unload_item(idx); - } - } + (state) ? load_item(idx) : unload_item(idx); + } + } - // full down-up load then up-down unload - void test1() { - change_states({ 0, size }, 1); - change_states({ 0, size }, 0, true); - } + // full down-up load then up-down unload + void test1() { + change_states({ 0, size }, 1); + change_states({ 0, size }, 0, true); + } - // full down-up load then down-up unload - void test2() { - change_states({ 0, size }, 1); - change_states({ 0, size }, 0); - } + // full down-up load then down-up unload + void test2() { + change_states({ 0, size }, 1); + change_states({ 0, size }, 0); + } - // full random load then random unload - void test3() { - change_states({ 0, size }, 1, 0, 1); - change_states({ 0, size }, 0, 0, 1); - } + // full random load then random unload + void test3() { + change_states({ 0, size }, 1, 0, 1); + change_states({ 0, size }, 0, 0, 1); + } - // multipul tests 1-3 - void test4() { - test1(); - test1(); + // multipul tests 1-3 + void test4() { + test1(); + test1(); - test2(); - test2(); + test2(); + test2(); - test3(); - test3(); - } + test3(); + test3(); + } - static tp::alnf sineupf(tp::alnf asize, tp::alnf x, bool reverse) { - tp::alnf end = 4 * PI; - tp::alnf a = (2 / 7.f) * asize; - tp::alnf b = end / asize; + static tp::alnf sineupf(tp::alnf asize, tp::alnf x, bool reverse) { + tp::alnf end = 4 * PI; + tp::alnf a = (2 / 7.f) * asize; + tp::alnf b = end / asize; - tp::alni c = ((-1 * reverse) + (1 * !reverse)); - tp::alnf c1 = (x - (end * reverse)) / b; - tp::alnf c2 = (a * sin(x - (end * reverse))); - tp::alnf out = c1 + c2; - return c * out; - } + tp::alni c = ((-1 * reverse) + (1 * !reverse)); + tp::alnf c1 = (x - (end * reverse)) / b; + tp::alnf c2 = (a * sin(x - (end * reverse))); + tp::alnf out = c1 + c2; + return c * out; + } - // sin load & sin unload with ~1/2 drop factor - void test5() { - tp::alnf end = 4 * PI; - tp::alnf step = end / 4.f; + // sin load & sin unload with ~1/2 drop factor + void test5() { + tp::alnf end = 4 * PI; + tp::alnf step = end / 4.f; - for (char i = 0; i < 2; i++) { - for (tp::alnf x = 0; x <= end; x += step) { - tp::alni target_alloc_count = (tp::alni)ceil(sineupf(size, x, i)); - CLAMP(target_alloc_count, 0, size); + for (char i = 0; i < 2; i++) { + for (tp::alnf x = 0; x <= end; x += step) { + tp::alni target_alloc_count = (tp::alni)ceil(sineupf(size, x, i)); + CLAMP(target_alloc_count, 0, size); - while (n_loaded > target_alloc_count) { - unload_item(rand_idx(0)); - } - while (n_loaded < target_alloc_count) { - load_item(rand_idx(1)); - } - } - } - } + while (n_loaded > target_alloc_count) { + unload_item(rand_idx(0)); + } + while (n_loaded < target_alloc_count) { + load_item(rand_idx(1)); + } + } + } + } #ifdef MEM_WRAP - void check_wrap(tp::alni offset, bool after) { - CLAMP(offset, 1, WRAP_LEN); + void check_wrap(tp::alni offset, bool after) { + CLAMP(offset, 1, WRAP_LEN); - test_struct* ts = allocations[rand_idx(0)]; - tp::alni shift = (sizeof(test_struct) * after) + (offset - 1) * after - - offset * (!after); - tp::uint1* address = (((tp::uint1*)ts) + shift); + test_struct* ts = allocations[rand_idx(0)]; + tp::alni shift = (sizeof(test_struct) * after) + (offset - 1) * after - + offset * (!after); + tp::uint1* address = (((tp::uint1*)ts) + shift); - tp::uint1 val = *address; - *address = 5; - assert(alloc->isWrapCorrupted()); - *address = val; + tp::uint1 val = *address; + *address = 5; + assert(alloc->isWrapCorrupted()); + *address = val; +} +#endif + + // mem guards test + void test6() { + change_states({ 0, size }, 1); + +#ifdef MEM_WRAP + for (tp::alni after = 0; after < 2; after++) { + for (tp::alni offset = 1; offset <= WRAP_LEN; offset++) { + check_wrap(offset, after); + } } #endif - // mem guards test - void test6() { - change_states({ 0, size }, 1); + change_states({ 0, size }, 0); + } -#ifdef MEM_WRAP - for (tp::alni after = 0; after < 2; after++) { - for (tp::alni offset = 1; offset <= WRAP_LEN; offset++) { - check_wrap(offset, after); + void run_tests() { + try { + test1(); + test2(); + test3(); + test4(); + test5(); + if (alloc->isWrapSupport()) { + test6(); + } + + printf("%s - passed\n", allocator_name); + if (!alloc->isWrapSupport()) { + printf(" WARNING: %s has no wrap support!! \n", allocator_name); } } -#endif - - change_states({ 0, size }, 0); - } - - void run_tests() { - try { - test1(); - test2(); - test3(); - test4(); - test5(); - if (alloc->isWrapSupport()) { - test6(); - } - - printf("%s - passed\n", allocator_name); - if (!alloc->isWrapSupport()) { - printf(" WARNING: %s has no wrap support!! \n", allocator_name); - } - } - catch (...) { - printf("%s - failed\n", allocator_name); - } - } + catch (...) { + printf("%s - failed\n", allocator_name); + } + } }; void heap_alloc_test() { - tp::alloc_init(); { - try { - allocator_test<150> hatest(tp::heapalloc, "heap allocator", NULL); - hatest.run_tests(); - } - catch (...) { - printf("heap alloc failed\n"); - } - } tp::alloc_uninit(); + tp::alloc_init(); { + try { + allocator_test<150> hatest(tp::heapalloc, "heap allocator", NULL); + hatest.run_tests(); + } + catch (...) { + printf("heap alloc failed\n"); + } + } tp::alloc_uninit(); } void chunk_alloc_test() { - tp::alloc_init(); { - try { - tp::ChunkAlloc calloc(sizeof(test_struct), 50); - allocator_test<50> ca_test(&calloc, "chunk allocator", tp::heapalloc); - ca_test.run_tests(); - } - catch (...) { - printf("chunk alloc failed\n"); - } - } tp::alloc_uninit(); + tp::alloc_init(); { + try { + tp::ChunkAlloc calloc(sizeof(test_struct), 50); + allocator_test<50> ca_test(&calloc, "chunk allocator", tp::heapalloc); + ca_test.run_tests(); + } + catch (...) { + printf("chunk alloc failed\n"); + } + } tp::alloc_uninit(); } void pool_alloc_test() { - tp::alloc_init(); { - try { - tp::PoolAlloc palloc(sizeof(test_struct), 50); - allocator_test<150> pa_test(&palloc, "pool allocator", tp::heapalloc); - pa_test.run_tests(); - } - catch (...) { - printf("chunk alloc failed\n"); - } - } tp::alloc_uninit(); + tp::alloc_init(); { + try { + tp::PoolAlloc palloc(sizeof(test_struct), 50); + allocator_test<150> pa_test(&palloc, "pool allocator", tp::heapalloc); + pa_test.run_tests(); + } + catch (...) { + printf("chunk alloc failed\n"); + } + } tp::alloc_uninit(); } void allocators_test() { + printf("running tests on alocators:\n"); - printf("running tests on alocators:\n"); - - heap_alloc_test(); - chunk_alloc_test(); - pool_alloc_test(); + heap_alloc_test(); + chunk_alloc_test(); + pool_alloc_test(); } CROSSPLATFORM_MAIN; int main(int argc, char* argv[]) { - tp::print_env_info(); - allocators_test(); + tp::print_env_info(); + allocators_test(); } \ No newline at end of file diff --git a/Containers/private/Containers.cpp b/Containers/private/Containers.cpp index fa729a5..b680dc5 100644 --- a/Containers/private/Containers.cpp +++ b/Containers/private/Containers.cpp @@ -5,14 +5,14 @@ namespace tp { - static ModuleManifest* sModuleDependencies[] = { &gModuleBase,nullptr }; - ModuleManifest gModuleContainers = ModuleManifest("Containers", nullptr, nullptr, sModuleDependencies); + static ModuleManifest* sModuleDependencies[] = { &gModuleBase,nullptr }; + ModuleManifest gModuleContainers = ModuleManifest("Containers", nullptr, nullptr, sModuleDependencies); - void* DefaultAllocator::allocate(ualni size) { - return malloc(size); - } + void* DefaultAllocator::allocate(ualni size) { + return malloc(size); + } - void DefaultAllocator::deallocate(void* p) { - free(p); - } + void DefaultAllocator::deallocate(void* p) { + free(p); + } } \ No newline at end of file diff --git a/Containers/public/AvlTree.hpp b/Containers/public/AvlTree.hpp index bde6645..1d80a11 100644 --- a/Containers/public/AvlTree.hpp +++ b/Containers/public/AvlTree.hpp @@ -9,88 +9,88 @@ namespace tp { NumericType val; - AvlNumericKey() = default; - AvlNumericKey(NumericType val) : val(val) {} + AvlNumericKey() = default; + AvlNumericKey(NumericType val) : val(val) {} inline bool descentRight(AvlNumericKey in) const { return in.val > val; } - inline bool descentLeft(AvlNumericKey in) const { return in.val < val; } - inline bool exactNode(AvlNumericKey in) const { return in.val == val; } + inline bool descentLeft(AvlNumericKey in) const { return in.val < val; } + inline bool exactNode(AvlNumericKey in) const { return in.val == val; } - inline AvlNumericKey getFindKey(/**/) const { return *this; } - inline AvlNumericKey keyInRightSubtree(AvlNumericKey in) const { return in; } - inline AvlNumericKey keyInLeftSubtree(AvlNumericKey in) const { return in; } + inline AvlNumericKey getFindKey(/**/) const { return *this; } + inline AvlNumericKey keyInRightSubtree(AvlNumericKey in) const { return in; } + inline AvlNumericKey keyInLeftSubtree(AvlNumericKey in) const { return in; } - inline void updateTreeCacheCallBack() {} + inline void updateTreeCacheCallBack() {} }; template class AvlTree { - typedef SelCopyArg KeyArg; - typedef SelCopyArg DataArg; + typedef SelCopyArg KeyArg; + typedef SelCopyArg DataArg; - public: - class Node { - friend AvlTree; + public: + class Node { + friend AvlTree; - private: - Node(KeyArg aKey, DataArg aData) : key(aKey), data(aData) {} + private: + Node(KeyArg aKey, DataArg aData) : key(aKey), data(aData) {} - public: - Data data; - Key key; + public: + Data data; + Key key; - private: - Node* mLeft = nullptr; - Node* mRight = nullptr; - Node* mParent = nullptr; - ualni mHeight = 0; + private: + Node* mLeft = nullptr; + Node* mRight = nullptr; + Node* mParent = nullptr; + ualni mHeight = 0; - private: - inline bool descentRight(KeyArg aKey) const { return key.descentRight(aKey); } - inline bool descentLeft(KeyArg aKey) const { return key.descentLeft(aKey); } - inline bool exactNode(KeyArg aKey) const { return key.exactNode(aKey); } + private: + inline bool descentRight(KeyArg aKey) const { return key.descentRight(aKey); } + inline bool descentLeft(KeyArg aKey) const { return key.descentLeft(aKey); } + inline bool exactNode(KeyArg aKey) const { return key.exactNode(aKey); } - inline KeyArg getFindKey(const Node* node = nullptr) const { return key.getFindKey(/*node*/); } - inline KeyArg keyInRightSubtree(KeyArg aKey) const { return key.keyInRightSubtree(aKey); } - inline KeyArg keyInLeftSubtree(KeyArg aKey) const { return key.keyInLeftSubtree(aKey); } + inline KeyArg getFindKey(const Node* node = nullptr) const { return key.getFindKey(/*node*/); } + inline KeyArg keyInRightSubtree(KeyArg aKey) const { return key.keyInRightSubtree(aKey); } + inline KeyArg keyInLeftSubtree(KeyArg aKey) const { return key.keyInLeftSubtree(aKey); } - inline void updateTreeCacheCallBack() { key.updateTreeCacheCallBack(); } - }; + inline void updateTreeCacheCallBack() { key.updateTreeCacheCallBack(); } + }; - private: - Node* mRoot = nullptr; - ualni mSize = 0; + private: + Node* mRoot = nullptr; + ualni mSize = 0; Allocator mAlloc; - private: - - inline void deleteNode(Node* node) { - node->~Node(); - mAlloc.deallocate(node); - } + private: + + inline void deleteNode(Node* node) { + node->~Node(); + mAlloc.deallocate(node); + } - inline Node* newNode(KeyArg key, DataArg data) { - return new (mAlloc.allocate(sizeof(Node))) Node(key, data); - } + inline Node* newNode(KeyArg key, DataArg data) { + return new (mAlloc.allocate(sizeof(Node))) Node(key, data); + } - inline void injectNodeInstead(Node* place, Node* inject) { - // TODO : swap instead of copy - place->data = inject->data; - place->key = inject->key; - } + inline void injectNodeInstead(Node* place, Node* inject) { + // TODO : swap instead of copy + place->data = inject->data; + place->key = inject->key; + } inline alni getNodeHeight(const Node* node) const { return node ? node->mHeight : -1; } // returns new head - Node* rotateLeft(Node* pivot) { - DEBUG_ASSERT(pivot); + Node* rotateLeft(Node* pivot) { + DEBUG_ASSERT(pivot); - Node* const head = pivot; - Node* const right = pivot->mRight; - Node* const right_left = right->mLeft; - Node* const parent = pivot->mParent; + Node* const head = pivot; + Node* const right = pivot->mRight; + Node* const right_left = right->mLeft; + Node* const parent = pivot->mParent; // parents if (right_left) right_left->mParent = head; @@ -112,13 +112,13 @@ namespace tp { return right; } - Node* rotateRight(Node* pivot) { - DEBUG_ASSERT(pivot); + Node* rotateRight(Node* pivot) { + DEBUG_ASSERT(pivot); - Node* const head = pivot; - Node* const left = pivot->mLeft; - Node* const left_right = left->mRight; - Node* const parent = pivot->mParent; + Node* const head = pivot; + Node* const left = pivot->mLeft; + Node* const left_right = left->mRight; + Node* const parent = pivot->mParent; // parents if (left_right) left_right->mParent = head; @@ -141,12 +141,12 @@ namespace tp { } // recursively returns valid left or right child or root - Node* insertUtil(Node* head, KeyArg key, DataArg data) { + Node* insertUtil(Node* head, KeyArg key, DataArg data) { - Node* insertedNode; + Node* insertedNode; if (head == nullptr) { - mSize++; + mSize++; Node* out = newNode(key, data); out->updateTreeCacheCallBack(); return out; @@ -155,14 +155,14 @@ namespace tp { return head; } else if (head->descentRight(key)) { - insertedNode = insertUtil(head->mRight, head->keyInRightSubtree(key), data); + insertedNode = insertUtil(head->mRight, head->keyInRightSubtree(key), data); head->mRight = insertedNode; - insertedNode->mParent = head; + insertedNode->mParent = head; } else { - insertedNode = insertUtil(head->mLeft, head->keyInLeftSubtree(key), data); + insertedNode = insertUtil(head->mLeft, head->keyInLeftSubtree(key), data); head->mLeft = insertedNode; - insertedNode->mParent = head; + insertedNode->mParent = head; } // update height @@ -194,31 +194,31 @@ namespace tp { return head; } - Node* removeUtil(Node* head, KeyArg key) { + Node* removeUtil(Node* head, KeyArg key) { if (head == nullptr) return head; if (head->exactNode(key)) { if (head->mRight && head->mLeft) { - Node* min = minNode(head->mRight); - auto const& newKey = min->getFindKey(head->mRight); - injectNodeInstead(head, min); + Node* min = minNode(head->mRight); + auto const& newKey = min->getFindKey(head->mRight); + injectNodeInstead(head, min); head->mRight = removeUtil(head->mRight, newKey); } else if (head->mRight) { - injectNodeInstead(head, head->mRight); + injectNodeInstead(head, head->mRight); deleteNode(head->mRight); head->mRight = nullptr; - mSize--; + mSize--; } else if (head->mLeft) { - injectNodeInstead(head, head->mLeft); - deleteNode(head->mLeft); + injectNodeInstead(head, head->mLeft); + deleteNode(head->mLeft); head->mLeft = nullptr; - mSize--; + mSize--; } else { - deleteNode(head); - mSize--; + deleteNode(head); + mSize--; head = nullptr; } } @@ -229,7 +229,7 @@ namespace tp { head->mLeft = removeUtil(head->mLeft, head->keyInLeftSubtree(key)); } - if (head == nullptr) return head; + if (head == nullptr) return head; head->mHeight = 1 + max(getNodeHeight(head->mRight), getNodeHeight(head->mLeft)); alni balance = getNodeHeight(head->mRight) - getNodeHeight(head->mLeft); @@ -268,7 +268,7 @@ namespace tp { return mSize; } - Node* head() const { + Node* head() const { return this->mRoot; } @@ -282,24 +282,24 @@ namespace tp { if (mRoot) mRoot->mParent = nullptr; } - Node* maxNode(Node* head) const { - if (!head) return nullptr; - while (head->mRight != nullptr) { - head = head->mRight; - } - return head; - } - - Node* minNode(Node* head) const { + Node* maxNode(Node* head) const { if (!head) return nullptr; - while (head->mLeft != nullptr) { - head = head->mLeft; - } + while (head->mRight != nullptr) { + head = head->mRight; + } return head; } - Node* find(KeyArg key) const { - Node* iter = mRoot; + Node* minNode(Node* head) const { + if (!head) return nullptr; + while (head->mLeft != nullptr) { + head = head->mLeft; + } + return head; + } + + Node* find(KeyArg key) const { + Node* iter = mRoot; while (true) { if (!iter) return nullptr; if (iter->exactNode(key)) return iter; @@ -313,61 +313,61 @@ namespace tp { } } - Node* findLessOrEq(KeyArg key) const { - Node* iter = mRoot; - while (true) { - if (!iter) return nullptr; - if (iter->exactNode(key)) return iter; - if (iter->descentLeft(key)) { - if (iter->mLeft) { - key = iter->keyInLeftSubtree(key); - iter = iter->mLeft; - } else { - return iter; - } - } else { - if (iter->mRight) { - key = iter->keyInRightSubtree(key); - iter = iter->mRight; - } else { - return iter; - } - } - } - } + Node* findLessOrEq(KeyArg key) const { + Node* iter = mRoot; + while (true) { + if (!iter) return nullptr; + if (iter->exactNode(key)) return iter; + if (iter->descentLeft(key)) { + if (iter->mLeft) { + key = iter->keyInLeftSubtree(key); + iter = iter->mLeft; + } else { + return iter; + } + } else { + if (iter->mRight) { + key = iter->keyInRightSubtree(key); + iter = iter->mRight; + } else { + return iter; + } + } + } + } // returns first invalid node - const Node* findInvalidNode(const Node* head) const { + const Node* findInvalidNode(const Node* head) const { if (head == nullptr) return nullptr; if (head->mLeft) { // TODO: incomplete test if (!head->descentLeft(head->mLeft->getFindKey(head))) return head; if (head->mLeft->mParent != head) return head; - if (!head->mRight && head->mLeft->mHeight != head->mHeight - 1) return head; + if (!head->mRight && head->mLeft->mHeight != head->mHeight - 1) return head; } if (head->mRight) { if (!head->descentRight(head->mRight->getFindKey(head))) return head; if (head->mRight->mParent != head) return head; - if (!head->mLeft && head->mRight->mHeight != head->mHeight - 1) return head; + if (!head->mLeft && head->mRight->mHeight != head->mHeight - 1) return head; } - if (head->mLeft && head->mRight) { - if (max(head->mLeft->mHeight, head->mRight->mHeight) != head->mHeight - 1) return head; - } + if (head->mLeft && head->mRight) { + if (max(head->mLeft->mHeight, head->mRight->mHeight) != head->mHeight - 1) return head; + } int balance = getNodeHeight(head->mRight) - getNodeHeight(head->mLeft); if (balance > 1 || balance < -1) return head; - const Node* ret = findInvalidNode(head->mRight); + const Node* ret = findInvalidNode(head->mRight); if (ret) return ret; return findInvalidNode(head->mLeft); } - bool isValid() { return findInvalidNode(head()) == nullptr; } + bool isValid() { return findInvalidNode(head()) == nullptr; } }; } \ No newline at end of file diff --git a/Containers/public/ContainersCommon.hpp b/Containers/public/ContainersCommon.hpp index 974c239..43552d8 100644 --- a/Containers/public/ContainersCommon.hpp +++ b/Containers/public/ContainersCommon.hpp @@ -4,23 +4,23 @@ #include "Module.hpp" namespace tp { - extern ModuleManifest gModuleContainers; + extern ModuleManifest gModuleContainers; - class DefaultAllocator { - public: - DefaultAllocator() = default; - static void *allocate(ualni); - static void deallocate(void *); - }; + class DefaultAllocator { + public: + DefaultAllocator() = default; + static void *allocate(ualni); + static void deallocate(void *); + }; - class DefaultSaverLoader { - public: - DefaultSaverLoader() = default; + class DefaultSaverLoader { + public: + DefaultSaverLoader() = default; - template - static void write(const Type&) {} + template + static void write(const Type&) {} - template - static void read(Type&) {} - }; + template + static void read(Type&) {} + }; } \ No newline at end of file diff --git a/Containers/public/List.hpp b/Containers/public/List.hpp index 3db6e81..470781b 100644 --- a/Containers/public/List.hpp +++ b/Containers/public/List.hpp @@ -7,92 +7,92 @@ namespace tp { - template + template class List { - typedef SelCopyArg TypeArg; - typedef ualni Index; + typedef SelCopyArg TypeArg; + typedef ualni Index; - public: + public: - struct Node { - Type data; - Node* next = nullptr; - Node* prev = nullptr; - Node() = default; - explicit Node(TypeArg p_data) : data(p_data) {} - Type& operator->() { return data; } - }; + struct Node { + Type data; + Node* next = nullptr; + Node* prev = nullptr; + Node() = default; + explicit Node(TypeArg p_data) : data(p_data) {} + Type& operator->() { return data; } + }; - class IteratorPointer { - protected: - Node* mIter; - public: - IteratorPointer() = default; - Type& operator->() { return (mIter->data); } - const Type& operator->() const { return (mIter->data); } - }; + class IteratorPointer { + protected: + Node* mIter; + public: + IteratorPointer() = default; + Type& operator->() { return (mIter->data); } + const Type& operator->() const { return (mIter->data); } + }; - class IteratorReference { - protected: - Node* mIter; - public: - IteratorReference() = default; - Type* operator->() { return &(mIter->data); } - const Type* operator->() const { return &(mIter->data); } - }; + class IteratorReference { + protected: + Node* mIter; + public: + IteratorReference() = default; + Type* operator->() { return &(mIter->data); } + const Type* operator->() const { return &(mIter->data); } + }; - class Iterator : public TypeSelect::isPointer, IteratorPointer, IteratorReference>::Result { - public: + class Iterator : public TypeSelect::isPointer, IteratorPointer, IteratorReference>::Result { + public: - explicit Iterator(Node* iter) { this->mIter = iter; } + explicit Iterator(Node* iter) { this->mIter = iter; } - Node* node() { return this->mIter; } - Type& data() { return this->mIter->data; } - const Node* node() const { return this->mIter; } - const Type& data() const { return this->mIter->data; } + Node* node() { return this->mIter; } + Type& data() { return this->mIter->data; } + const Node* node() const { return this->mIter; } + const Type& data() const { return this->mIter->data; } - const Iterator& operator*() const { return *this; } + const Iterator& operator*() const { return *this; } - Iterator& operator++() { - this->mIter = this->mIter->next; - return *this; - } + Iterator& operator++() { + this->mIter = this->mIter->next; + return *this; + } - bool operator==(const Iterator& left) const { return left.mIter == this->mIter; } - bool operator!=(const Iterator& left) const { return left.mIter != this->mIter; } - }; + bool operator==(const Iterator& left) const { return left.mIter == this->mIter; } + bool operator!=(const Iterator& left) const { return left.mIter != this->mIter; } + }; - private: + private: Node* mFirst = nullptr; Node* mLast = nullptr; Index mLength = 0; Allocator mAlloc; - public: + public: List() = default; List(const init_list& list) { operator=(list); } - [[nodiscard]] inline Node* first() const { return mFirst; } - [[nodiscard]] inline Node* last() const { return mLast; } + [[nodiscard]] inline Node* first() const { return mFirst; } + [[nodiscard]] inline Node* last() const { return mLast; } [[nodiscard]] inline Index length() const { return mLength; } - [[nodiscard]] Node* newNode() { return new (mAlloc.allocate(sizeof(Node))) Node(); } - [[nodiscard]] Node* newNode(TypeArg arg) { return new (mAlloc.allocate(sizeof(Node))) Node(arg); } - [[nodiscard]] Node* newNodeNotConstructed() { - auto node = (Node*) mAlloc.allocate(sizeof(Node)); - node->next = node->prev = nullptr; - return node; - } + [[nodiscard]] Node* newNode() { return new (mAlloc.allocate(sizeof(Node))) Node(); } + [[nodiscard]] Node* newNode(TypeArg arg) { return new (mAlloc.allocate(sizeof(Node))) Node(arg); } + [[nodiscard]] Node* newNodeNotConstructed() { + auto node = (Node*) mAlloc.allocate(sizeof(Node)); + node->next = node->prev = nullptr; + return node; + } - [[nodiscard]] const Allocator& getAllocator() const { return mAlloc; } + [[nodiscard]] const Allocator& getAllocator() const { return mAlloc; } - void deleteNode(Node* node) { - node->~Node(); - mAlloc.deallocate(node); - } + void deleteNode(Node* node) { + node->~Node(); + mAlloc.deallocate(node); + } Node* addNodeBack() { auto const out = newNode(); @@ -145,7 +145,7 @@ namespace tp { mLength--; } - [[nodiscard]] Node* findIdx(Index idx) const { + [[nodiscard]] Node* findIdx(Index idx) const { DEBUG_ASSERT(!mFirst || idx > mLength - 1) Node* found = mFirst; for (int i = 0; i != idx; i++) { @@ -154,7 +154,7 @@ namespace tp { return found; } - [[nodiscard]] Node* find(const TypeArg data) const { + [[nodiscard]] Node* find(const TypeArg data) const { Node* found = mFirst; for (alni i = 0; data != found->data; i++) { if (!found->next) { @@ -165,33 +165,33 @@ namespace tp { return found; } - [[nodiscard]] inline const Type& operator[](Index idx) const { + [[nodiscard]] inline const Type& operator[](Index idx) const { DEBUG_ASSERT(idx < mLength) return find(idx)->data; } void pushBack(Node* new_node) { attach(new_node, mLast); } - void pushFront(Node* new_node) { attach(new_node, nullptr); } + void pushFront(Node* new_node) { attach(new_node, nullptr); } void pushBack(TypeArg data) { pushBack(newNode(data)); } void pushFront(TypeArg data) { pushFront(newNode(data)); } void popBack() { - DEBUG_ASSERT(mLast) - detach(mLast); - deleteNode(mLast); + DEBUG_ASSERT(mLast) + detach(mLast); + deleteNode(mLast); } void popFront() { DEBUG_ASSERT(mFirst) - auto temp = mFirst; - detach(mFirst); - deleteNode(temp); + auto temp = mFirst; + detach(mFirst); + deleteNode(temp); } void insert(Node* node, Index idx) { if (!mLength) { - attach(node, mLast); - } else if (idx >= mLength) { + attach(node, mLast); + } else if (idx >= mLength) { attach(node, nullptr); } else { attach(node, find(idx)->prev); @@ -209,11 +209,11 @@ namespace tp { void removeAll() { while (mFirst) { - popFront(); - } + popFront(); + } } - // copies data + // copies data List& operator+=(const List& in) { for (auto node : in) { pushBack(node.data()); @@ -229,38 +229,38 @@ namespace tp { } List& operator=(const List& in) { - if (this == &in) { return *this; } + if (this == &in) { return *this; } removeAll(); - (*this) += in; + (*this) += in; return *this; } List& operator=(const init_list& list) { - removeAll(); + removeAll(); *this += list; return *this; } - [[nodiscard]] bool operator==(const List& in) const { - if (in == *this) { return true; } - if (in.length() != length()) { - return false; - } - Node* left = in.first(); - Node* right = first(); - while (left && right) { - if (left->data != right->data) { - return false; - } - } - if (left != right) { - return false; - } - return true; - } + [[nodiscard]] bool operator==(const List& in) const { + if (in == *this) { return true; } + if (in.length() != length()) { + return false; + } + Node* left = in.first(); + Node* right = first(); + while (left && right) { + if (left->data != right->data) { + return false; + } + } + if (left != right) { + return false; + } + return true; + } template - [[nodiscard]] Node* find(bool (*found)(Node* node, compare_val val), compare_val value) const { + [[nodiscard]] Node* find(bool (*found)(Node* node, compare_val val), compare_val value) const { for (Node* node = mFirst; node; node = node->next) { if (found(node, value)) { return node; @@ -269,12 +269,12 @@ namespace tp { return nullptr; } - [[nodiscard]] Iterator begin() const { + [[nodiscard]] Iterator begin() const { Iterator out(mFirst); return out; } - [[nodiscard]] Iterator end() const { + [[nodiscard]] Iterator end() const { return Iterator(nullptr); } @@ -290,33 +290,33 @@ namespace tp { } void detachAll() { - while (mFirst) { - detach(mFirst); - } + while (mFirst) { + detach(mFirst); + } } - template - void write(Saver& file) const { - file.write(mLength); - for (auto item : *this) { - file.write(item.data()); - } - } + template + void write(Saver& file) const { + file.write(mLength); + for (auto item : *this) { + file.write(item.data()); + } + } - template - void read(Loader& file) { - removeAll(); - ualni len; - file.read(len); - for (auto i = len; i; i--) { - auto node = newNodeNotConstructed(); - file.read(node->data); - pushBack(node); - } - } + template + void read(Loader& file) { + removeAll(); + ualni len; + file.read(len); + for (auto i = len; i; i--) { + auto node = newNodeNotConstructed(); + file.read(node->data); + pushBack(node); + } + } - ~List() { - removeAll(); - } + ~List() { + removeAll(); + } }; } \ No newline at end of file diff --git a/Containers/public/Map.hpp b/Containers/public/Map.hpp index b92e11e..2f6fb88 100644 --- a/Containers/public/Map.hpp +++ b/Containers/public/Map.hpp @@ -11,12 +11,7 @@ namespace tp { return hash(key); } - template< - typename tKey, typename tVal, - class tAllocator = DefaultAllocator, - ualni(*tHashFunc)(SelCopyArg) = DefaultHashFunc, - int tTableInitialSize = 4 - > + template) = DefaultHashFunc, int tTableInitialSize = 4> class Map { enum { @@ -25,23 +20,23 @@ namespace tp { MAP_MAX_LOAD_PERCENTAGE = 66, }; - typedef SelCopyArg KeyArg; - typedef SelCopyArg ValArg; + typedef SelCopyArg KeyArg; + typedef SelCopyArg ValArg; public: class Node { - friend Map; - Node(KeyArg aKey, ValArg aVal) : key(aKey), val(aVal) {} - public: + friend Map; + Node(KeyArg aKey, ValArg aVal) : key(aKey), val(aVal) {} + public: tKey key; tVal val; }; - struct Idx { - alni idx = -1; - operator bool() { return idx != -1; } - }; + struct Idx { + alni idx = -1; + operator bool() { return idx != -1; } + }; private: tAllocator mAlloc; @@ -49,160 +44,160 @@ namespace tp { ualni mNSlots = 0; ualni mNEntries = 0; - private: + private: constexpr halnf maxLoadFactor() { return halnf(MAP_MAX_LOAD_PERCENTAGE) / 100.f; } - inline Node** newTable(const ualni len) { - return new(mAlloc.allocate(sizeof(Node*) * len)) Node*[len](); - } + inline Node** newTable(const ualni len) { + return new(mAlloc.allocate(sizeof(Node*) * len)) Node*[len](); + } - inline Node* newNode(KeyArg key, ValArg val) { - return new(mAlloc.allocate(sizeof(Node))) Node(key, val); - } + inline Node* newNode(KeyArg key, ValArg val) { + return new(mAlloc.allocate(sizeof(Node))) Node(key, val); + } - inline Node* newNodeNotConstructed() { - return (Node*) mAlloc.allocate(sizeof(Node)); - } + inline Node* newNodeNotConstructed() { + return (Node*) mAlloc.allocate(sizeof(Node)); + } - inline void deleteTable(Node** table) { - mAlloc.deallocate(table); - } + inline void deleteTable(Node** table) { + mAlloc.deallocate(table); + } - inline void deleteNode(Node* p) { - p->~Node(); - mAlloc.deallocate(p); - } + inline void deleteNode(Node* p) { + p->~Node(); + mAlloc.deallocate(p); + } - void markDeletedSlot(ualni idx) const { - mTable[idx] = (Node*)-1; - } + void markDeletedSlot(ualni idx) const { + mTable[idx] = (Node*)-1; + } - static bool isDeletedNode(Node* node) { - return node == (Node*)-1; - } + static bool isDeletedNode(Node* node) { + return node == (Node*)-1; + } - void rehash() { - alni nSlotsOld = mNSlots; - Node** tableOld = mTable; + void rehash() { + alni nSlotsOld = mNSlots; + Node** tableOld = mTable; - mNSlots = next2pow((uhalni)((1.f / (maxLoadFactor())) * mNEntries + 1)); - mTable = newTable(mNSlots); - mNEntries = 0; + mNSlots = next2pow((uhalni)((1.f / (maxLoadFactor())) * mNEntries + 1)); + mTable = newTable(mNSlots); + mNEntries = 0; - for (alni i = 0; i < nSlotsOld; i++) { - if (!tableOld[i] || isDeletedNode(tableOld[i])) { - continue; - } + for (alni i = 0; i < nSlotsOld; i++) { + if (!tableOld[i] || isDeletedNode(tableOld[i])) { + continue; + } - alni idx = findSlotWrite(tableOld[i]->key); - mTable[idx] = tableOld[i]; - mNEntries++; - } + alni idx = findSlotWrite(tableOld[i]->key); + mTable[idx] = tableOld[i]; + mNEntries++; + } - deleteTable(tableOld); - } + deleteTable(tableOld); + } - alni findSlotRead(KeyArg key) const { - ualni const hashed_key = tHashFunc(key); - ualni const mask = mNSlots - 1; - ualni const shift = (hashed_key >> MAP_PERTURB_SHIFT) & ~1; - alni idx = hashed_key & mask; - NEXT: - if (isDeletedNode(mTable[idx])) { - goto SKIP; - } - if (!mTable[idx]) { - return -1; - } - if (mTable[idx]->key == key) { - return idx; - } - SKIP: - idx = ((5 * idx) + 1 + shift) & mask; - goto NEXT; - } + alni findSlotRead(KeyArg key) const { + ualni const hashed_key = tHashFunc(key); + ualni const mask = mNSlots - 1; + ualni const shift = (hashed_key >> MAP_PERTURB_SHIFT) & ~1; + alni idx = hashed_key & mask; + NEXT: + if (isDeletedNode(mTable[idx])) { + goto SKIP; + } + if (!mTable[idx]) { + return -1; + } + if (mTable[idx]->key == key) { + return idx; + } + SKIP: + idx = ((5 * idx) + 1 + shift) & mask; + goto NEXT; + } - // compares keys only when collisions occur - alni findSlotReadExisting(KeyArg key) const { - ualni const hashed_key = tHashFunc(key); - ualni const mask = mNSlots - 1; - ualni const shift = (hashed_key >> MAP_PERTURB_SHIFT) & ~1; - alni idx = hashed_key & mask; - NEXT: - if (isDeletedNode(mTable[idx])) { - goto SKIP; - } - if (!mTable[idx]) { - return -1; - } - if (mTable[((5 * idx) + 1 + shift) & mask] == nullptr) { - return idx; - } - if (mTable[idx]->key == key) { - return idx; - } - SKIP: - idx = ((5 * idx) + 1 + shift) & mask; - goto NEXT; - } + // compares keys only when collisions occur + alni findSlotReadExisting(KeyArg key) const { + ualni const hashed_key = tHashFunc(key); + ualni const mask = mNSlots - 1; + ualni const shift = (hashed_key >> MAP_PERTURB_SHIFT) & ~1; + alni idx = hashed_key & mask; + NEXT: + if (isDeletedNode(mTable[idx])) { + goto SKIP; + } + if (!mTable[idx]) { + return -1; + } + if (mTable[((5 * idx) + 1 + shift) & mask] == nullptr) { + return idx; + } + if (mTable[idx]->key == key) { + return idx; + } + SKIP: + idx = ((5 * idx) + 1 + shift) & mask; + goto NEXT; + } - ualni findSlotWrite(KeyArg key) const { - ualni const hashed_key = tHashFunc(key); - ualni const mask = mNSlots - 1; - ualni const shift = (hashed_key >> MAP_PERTURB_SHIFT) & ~1; - ualni idx = hashed_key & mask; - NEXT: - if (isDeletedNode(mTable[idx]) || !mTable[idx]) { - return idx; - } - if (mTable[idx]->key == key) { - return idx; - } - idx = ((5 * idx) + 1 + shift) & mask; - goto NEXT; - } + ualni findSlotWrite(KeyArg key) const { + ualni const hashed_key = tHashFunc(key); + ualni const mask = mNSlots - 1; + ualni const shift = (hashed_key >> MAP_PERTURB_SHIFT) & ~1; + ualni idx = hashed_key & mask; + NEXT: + if (isDeletedNode(mTable[idx]) || !mTable[idx]) { + return idx; + } + if (mTable[idx]->key == key) { + return idx; + } + idx = ((5 * idx) + 1 + shift) & mask; + goto NEXT; + } - void put(Node* node) { - const ualni idx = findSlotWrite(node->key); + void put(Node* node) { + const ualni idx = findSlotWrite(node->key); - if (!mTable[idx] || isDeletedNode(mTable[idx])) { - mNEntries++; - } + if (!mTable[idx] || isDeletedNode(mTable[idx])) { + mNEntries++; + } - mTable[idx] = node; + mTable[idx] = node; - if ((halnf)mNEntries / mNSlots > maxLoadFactor()) { - rehash(); - } - } + if ((halnf)mNEntries / mNSlots > maxLoadFactor()) { + rehash(); + } + } public: - Map() { - MODULE_SANITY_CHECK(gModuleContainers) - mNSlots = next2pow(uhalni(tTableInitialSize - 1)); - mTable = newTable(mNSlots); - } + Map() { + MODULE_SANITY_CHECK(gModuleContainers) + mNSlots = next2pow(uhalni(tTableInitialSize - 1)); + mTable = newTable(mNSlots); + } - Node** buff() const { - return mTable; - } + Node** buff() const { + return mTable; + } - [[nodiscard]] ualni size() const { - return mNEntries; - } + [[nodiscard]] ualni size() const { + return mNEntries; + } - [[nodiscard]] ualni slotsSize() const { - return mNEntries; - } + [[nodiscard]] ualni slotsSize() const { + return mNEntries; + } - [[nodiscard]] const tAllocator& getAllocator() const { - return mAlloc; - } + [[nodiscard]] const tAllocator& getAllocator() const { + return mAlloc; + } void put(KeyArg key, ValArg val) { - const ualni idx = findSlotWrite(key); + const ualni idx = findSlotWrite(key); if (!mTable[idx] || isDeletedNode(mTable[idx])) { mTable[idx] = newNode(key, val); mNEntries++; @@ -215,22 +210,22 @@ namespace tp { // undefined behavior if item is not presents tVal& get(KeyArg key) { - DEBUG_ASSERT(findSlotRead(key) != -1 && "Key Error") + DEBUG_ASSERT(findSlotRead(key) != -1 && "Key Error") return mTable[findSlotReadExisting(key)]->val; } const tVal& get(KeyArg key) const { DEBUG_ASSERT(findSlotRead(key) != -1 && "Key Error") - return mTable[findSlotReadExisting(key)]->val; + return mTable[findSlotReadExisting(key)]->val; } - [[nodiscard]] Idx presents(KeyArg key) const { return { findSlotRead(key) }; } + [[nodiscard]] Idx presents(KeyArg key) const { return { findSlotRead(key) }; } void remove(KeyArg key) { - DEBUG_ASSERT(findSlotRead(key) != -1 && "Key Error") - auto idx = findSlotReadExisting(key); + DEBUG_ASSERT(findSlotRead(key) != -1 && "Key Error") + auto idx = findSlotReadExisting(key); - deleteNode(mTable[idx]); + deleteNode(mTable[idx]); markDeletedSlot(idx); @@ -241,30 +236,30 @@ namespace tp { } const tVal& getSlotVal(ualni slot) const { - DEBUG_ASSERT(slot < mNSlots && (mTable[slot] && !isDeletedNode(mTable[slot])) && "Key Error") - return mTable[slot]->val; - } + DEBUG_ASSERT(slot < mNSlots && (mTable[slot] && !isDeletedNode(mTable[slot])) && "Key Error") + return mTable[slot]->val; + } tVal& getSlotVal(ualni slot) { - DEBUG_ASSERT(slot < mNSlots && (mTable[slot] && !isDeletedNode(mTable[slot])) && "Key Error") - return mTable[slot]->val; - } + DEBUG_ASSERT(slot < mNSlots && (mTable[slot] && !isDeletedNode(mTable[slot])) && "Key Error") + return mTable[slot]->val; + } const tVal& getSlotVal(Idx slot) const { - DEBUG_ASSERT(slot.idx < mNSlots && (mTable[slot.idx] && !isDeletedNode(mTable[slot.idx])) && "Key Error") + DEBUG_ASSERT(slot.idx < mNSlots && (mTable[slot.idx] && !isDeletedNode(mTable[slot.idx])) && "Key Error") return mTable[slot]->val; } tVal& getSlotVal(Idx slot) { - DEBUG_ASSERT(slot.idx < mNSlots && (mTable[slot.idx] && !isDeletedNode(mTable[slot.idx])) && "Key Error") + DEBUG_ASSERT(slot.idx < mNSlots && (mTable[slot.idx] && !isDeletedNode(mTable[slot.idx])) && "Key Error") return mTable[slot.idx]->val; } Map& operator=(const Map& in) { - if (this == &in) { - return *this; - } - removeAll(); + if (this == &in) { + return *this; + } + removeAll(); mNSlots = in.mNSlots; mTable = newTable(mNSlots); for (alni i = 0; i < mNSlots; i++) { @@ -272,31 +267,31 @@ namespace tp { put(in.mTable[i]->key, in.mTable[i]->val); } } - return *this; + return *this; } - [[nodiscard]] bool operator==(const Map& in) const { - if (this == &in) { - return true; - } - if (in.mNEntries != mNEntries) { - return false; - } - for (auto i : in) { - if (!presents(i->key) || get(i->key) != i->val) { - return false; - } - } - return true; - } + [[nodiscard]] bool operator==(const Map& in) const { + if (this == &in) { + return true; + } + if (in.mNEntries != mNEntries) { + return false; + } + for (auto i : in) { + if (!presents(i->key) || get(i->key) != i->val) { + return false; + } + } + return true; + } void removeAll() { for (ualni i = 0; i < mNSlots; i++) { if (mTable[i] && !isDeletedNode(mTable[i])) { - deleteNode(mTable[i]); + deleteNode(mTable[i]); } } - deleteTable(mTable); + deleteTable(mTable); mTable = newTable(tTableInitialSize); mNSlots = tTableInitialSize; mNEntries = 0; @@ -323,74 +318,74 @@ namespace tp { const Node* GetEntry(ualni idx) const { auto slot = slotIdx(idx); - DEBUG_ASSERT(slot != -1 && "Key error") + DEBUG_ASSERT(slot != -1 && "Key error") return mTable[slot]; } - public: + public: - class Iterator { - const Map* map; - Node* mIter; - alni mSlot; - alni mEntry; + class Iterator { + const Map* map; + Node* mIter; + alni mSlot; + alni mEntry; - friend Map; - explicit Iterator(const Map* _map) { - mSlot = -1; - mEntry = -1; - map = _map; - this->operator++(); - } + friend Map; + explicit Iterator(const Map* _map) { + mSlot = -1; + mEntry = -1; + map = _map; + this->operator++(); + } - public: - Node* operator->() { return mIter; } - const Node* operator->() const { return mIter; } - const Iterator& operator*() const { return *this; } + public: + Node* operator->() { return mIter; } + const Node* operator->() const { return mIter; } + const Iterator& operator*() const { return *this; } - bool operator!=(ualni idx) const { return mSlot != idx; } + bool operator!=(ualni idx) const { return mSlot != idx; } - void operator++() { - mSlot++; - while ((map->isDeletedNode(map->mTable[mSlot]) || !map->mTable[mSlot]) && (mSlot != map->mNSlots)) { - mSlot++; - } - if (mSlot != map->mNSlots) { - mIter = map->mTable[mSlot]; - mEntry++; - } - } - }; + void operator++() { + mSlot++; + while ((map->isDeletedNode(map->mTable[mSlot]) || !map->mTable[mSlot]) && (mSlot != map->mNSlots)) { + mSlot++; + } + if (mSlot != map->mNSlots) { + mIter = map->mTable[mSlot]; + mEntry++; + } + } + }; - [[nodiscard]] Iterator begin() const { - return Iterator(this); - } + [[nodiscard]] Iterator begin() const { + return Iterator(this); + } [[nodiscard]] ualni end() const { - return mNSlots; - } + return mNSlots; + } - template - void write(Saver& file) { - file.write(mNEntries); - for (auto item : *this) { - file.write(item->val); - file.write(item->key); - } - } + template + void write(Saver& file) { + file.write(mNEntries); + for (auto item : *this) { + file.write(item->val); + file.write(item->key); + } + } - template - void read(Loader& file) { - removeAll(); - ualni len; - file.read(len); - for (auto i = len; i; i--) { - auto node = newNodeNotConstructed(); - file.read(node->val); - file.read(node->key); - put(node); - } - } + template + void read(Loader& file) { + removeAll(); + ualni len; + file.read(len); + for (auto i = len; i; i--) { + auto node = newNodeNotConstructed(); + file.read(node->val); + file.read(node->key); + put(node); + } + } ~Map() { removeAll(); } }; diff --git a/Containers/tests/AvlTest.cpp b/Containers/tests/AvlTest.cpp index 1aada9d..0b56699 100644 --- a/Containers/tests/AvlTest.cpp +++ b/Containers/tests/AvlTest.cpp @@ -10,122 +10,122 @@ using namespace tp; TEST_DEF_STATIC(Simple) { - AvlTree, TestClass, TestAllocator> tree; + AvlTree, TestClass, TestAllocator> tree; - TEST(tree.size() == 0); - TEST(tree.head() == nullptr); + TEST(tree.size() == 0); + TEST(tree.head() == nullptr); - tree.insert(6, TestClass(6)); - TEST(tree.isValid()); - TEST(tree.size() == 1); - TEST(tree.head()->data == TestClass(6)); + tree.insert(6, TestClass(6)); + TEST(tree.isValid()); + TEST(tree.size() == 1); + TEST(tree.head()->data == TestClass(6)); - tree.remove(6); - TEST(tree.isValid()); - TEST(tree.size() == 0); - TEST(tree.head() == nullptr); + tree.remove(6); + TEST(tree.isValid()); + TEST(tree.size() == 0); + TEST(tree.head() == nullptr); } TEST_DEF_STATIC(Persistance) { - AvlTree, TestClass, TestAllocator> tree; + AvlTree, TestClass, TestAllocator> tree; - const auto size = 1000; + const auto size = 1000; - struct Item { - Item() : data(0) {} - bool presents = false; - TestClass data; - }; + struct Item { + Item() : data(0) {} + bool presents = false; + TestClass data; + }; - Item buff[size]; + Item buff[size]; - for (auto i : Range(size)) { - buff[i].data.setVal(i); - } + for (auto i : Range(size)) { + buff[i].data.setVal(i); + } - // random load - ualni loadSize = 0; - while (loadSize < size / 2) { - ualni idx = rand() % (size - 1); - DEBUG_ASSERT(idx < size) - if (!buff[idx].presents) { - tree.insert((alni) buff[idx].data.getVal(), buff[idx].data); - loadSize++; - buff[idx].presents = true; + // random load + ualni loadSize = 0; + while (loadSize < size / 2) { + ualni idx = rand() % (size - 1); + DEBUG_ASSERT(idx < size) + if (!buff[idx].presents) { + tree.insert((alni) buff[idx].data.getVal(), buff[idx].data); + loadSize++; + buff[idx].presents = true; - TEST(tree.isValid()); - TEST(tree.size() == loadSize); - } - } + TEST(tree.isValid()); + TEST(tree.size() == loadSize); + } + } - for (auto& item : buff) { - if (item.presents) continue; - tree.insert((alni) item.data.getVal(), item.data); - loadSize++; - item.presents = true; + for (auto& item : buff) { + if (item.presents) continue; + tree.insert((alni) item.data.getVal(), item.data); + loadSize++; + item.presents = true; - TEST(tree.isValid()); - TEST(tree.size() == loadSize); - } + TEST(tree.isValid()); + TEST(tree.size() == loadSize); + } - TEST(tree.size() == size); - TEST(tree.maxNode(tree.head())->data.getVal() == size - 1); - TEST(tree.minNode(tree.head())->data.getVal() == 0); + TEST(tree.size() == size); + TEST(tree.maxNode(tree.head())->data.getVal() == size - 1); + TEST(tree.minNode(tree.head())->data.getVal() == 0); - // find - for (auto item : buff) { - auto node = tree.find((alni) item.data.getVal()); - TEST(node); - if (!node) continue; - TEST(node->data.getVal() == item.data.getVal()); - } + // find + for (auto item : buff) { + auto node = tree.find((alni) item.data.getVal()); + TEST(node); + if (!node) continue; + TEST(node->data.getVal() == item.data.getVal()); + } - TEST(!tree.find(size + 1)); - TEST(!tree.find(-1)); + TEST(!tree.find(size + 1)); + TEST(!tree.find(-1)); - // random unload - ualni unloadSize = 0; - while (unloadSize < size / 2) { - ualni idx = rand() % (size - 1); - if (buff[idx].presents) { + // random unload + ualni unloadSize = 0; + while (unloadSize < size / 2) { + ualni idx = rand() % (size - 1); + if (buff[idx].presents) { - tree.remove((alni) buff[idx].data.getVal()); + tree.remove((alni) buff[idx].data.getVal()); - unloadSize++; - buff[idx].presents = false; + unloadSize++; + buff[idx].presents = false; - // find - for (auto item : buff) { - if (!item.presents) continue; - auto node = tree.find((alni) item.data.getVal()); - TEST(node); - if (!node) continue; - TEST(node->data.getVal() == item.data.getVal()); - } + // find + for (auto item : buff) { + if (!item.presents) continue; + auto node = tree.find((alni) item.data.getVal()); + TEST(node); + if (!node) continue; + TEST(node->data.getVal() == item.data.getVal()); + } - TEST(tree.isValid()); - TEST(tree.size() == size - unloadSize); - } - } + TEST(tree.isValid()); + TEST(tree.size() == size - unloadSize); + } + } - for (auto& item : buff) { - if (item.presents) { - tree.remove((alni) item.data.getVal()); - unloadSize++; - item.presents = false; + for (auto& item : buff) { + if (item.presents) { + tree.remove((alni) item.data.getVal()); + unloadSize++; + item.presents = false; - TEST(tree.isValid()); - TEST(tree.size() == size - unloadSize); - } - } + TEST(tree.isValid()); + TEST(tree.size() == size - unloadSize); + } + } - TEST(tree.size() == 0); - TEST(tree.head() == nullptr); - TEST(tree.maxNode(tree.head()) == nullptr); - TEST(tree.minNode(tree.head()) == nullptr); + TEST(tree.size() == 0); + TEST(tree.head() == nullptr); + TEST(tree.maxNode(tree.head()) == nullptr); + TEST(tree.minNode(tree.head()) == nullptr); } TEST_DEF(Avl) { - testSimple(); - testPersistance(); + testSimple(); + testPersistance(); } \ No newline at end of file diff --git a/Containers/tests/ListTest.cpp b/Containers/tests/ListTest.cpp index c33c5f1..44eddba 100644 --- a/Containers/tests/ListTest.cpp +++ b/Containers/tests/ListTest.cpp @@ -7,82 +7,82 @@ using namespace tp; TEST_DEF_STATIC(SimpleReference) { - tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; + tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; - list.pushBack(TestClass(5)); - list.pushFront(TestClass(0)); + list.pushBack(TestClass(5)); + list.pushFront(TestClass(0)); - ualni i = -1; - for (auto iter : list) { - i++; - TEST_EQUAL(iter->getVal(), i); - } + ualni i = -1; + for (auto iter : list) { + i++; + TEST_EQUAL(iter->getVal(), i); + } - TEST(i == 5); + TEST(i == 5); - list.removeAll(); - TEST(list.getAllocator().getAllocationsCount() == 0); + list.removeAll(); + TEST(list.getAllocator().getAllocationsCount() == 0); } TEST_DEF_STATIC(SimplePointer) { - tp::List list = { new TestClass(1), new TestClass(2), new TestClass(3), new TestClass(4) }; + tp::List list = { new TestClass(1), new TestClass(2), new TestClass(3), new TestClass(4) }; - list.pushBack(new TestClass(5)); - list.pushFront(new TestClass(0)); + list.pushBack(new TestClass(5)); + list.pushFront(new TestClass(0)); - ualni i = -1; - for (auto iter : list) { - i++; - TEST_EQUAL(iter->getVal(), i); - } + ualni i = -1; + for (auto iter : list) { + i++; + TEST_EQUAL(iter->getVal(), i); + } - TEST(i == 5); + TEST(i == 5); - list.removeAll(); + list.removeAll(); - TEST(list.getAllocator().getAllocationsCount() == 0); + TEST(list.getAllocator().getAllocationsCount() == 0); } TEST_DEF_STATIC(Copy) { - tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; - tp::List list2 = list; + tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; + tp::List list2 = list; - TEST_EQUAL(list, list2); + TEST_EQUAL(list, list2); - list.removeAll(); - list2.removeAll(); + list.removeAll(); + list2.removeAll(); - TEST(list.getAllocator().getAllocationsCount() == 0); - TEST(list2.getAllocator().getAllocationsCount() == 0); + TEST(list.getAllocator().getAllocationsCount() == 0); + TEST(list2.getAllocator().getAllocationsCount() == 0); } TEST_DEF_STATIC(SaveLoad) { - tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; + tp::List list = { TestClass(1), TestClass(2), TestClass(3), TestClass(4) }; - TestFile file; + TestFile file; - list.write(file); + list.write(file); - list.removeAll(); + list.removeAll(); - file.setAddress(0); + file.setAddress(0); - list.read(file); + list.read(file); - ualni i = 0; - for (auto iter : list) { - i++; - TEST_EQUAL(iter->getVal(), i); - } - TEST(i == 4); + ualni i = 0; + for (auto iter : list) { + i++; + TEST_EQUAL(iter->getVal(), i); + } + TEST(i == 4); - list.removeAll(); + list.removeAll(); - TEST(list.getAllocator().getAllocationsCount() == 0); + TEST(list.getAllocator().getAllocationsCount() == 0); } TEST_DEF(List) { - testSimplePointer(); - testSimpleReference(); - testSaveLoad(); + testSimplePointer(); + testSimpleReference(); + testSaveLoad(); } \ No newline at end of file diff --git a/Containers/tests/MapTest.cpp b/Containers/tests/MapTest.cpp index 1940f22..1ce182e 100644 --- a/Containers/tests/MapTest.cpp +++ b/Containers/tests/MapTest.cpp @@ -9,129 +9,129 @@ using namespace tp; TEST_DEF_STATIC(SimpleReference) { - tp::Map map; + tp::Map map; - for (auto i : Range(1000, 100000)) { - map.put(i, TestClass(i)); - } + for (auto i : Range(1000, 100000)) { + map.put(i, TestClass(i)); + } - for (auto i : Range(1000, 100000)) { - TEST(map.presents(i)); - TEST_EQUAL(map.get(i).getVal(), i); - } + for (auto i : Range(1000, 100000)) { + TEST(map.presents(i)); + TEST_EQUAL(map.get(i).getVal(), i); + } - for (auto i : Range(1000, 100000)) { - map.put(i, TestClass(i)); - } + for (auto i : Range(1000, 100000)) { + map.put(i, TestClass(i)); + } - for (auto i : Range(1000, 2000)) { - TEST(map.presents(i)); - map.remove(i); - TEST(!map.presents(i)); - } + for (auto i : Range(1000, 2000)) { + TEST(map.presents(i)); + map.remove(i); + TEST(!map.presents(i)); + } - for (auto i : Range(2000, 100000)) { - TEST(map.presents(i)); - TEST_EQUAL(map.get(i).getVal(), i); - } + for (auto i : Range(2000, 100000)) { + TEST(map.presents(i)); + TEST_EQUAL(map.get(i).getVal(), i); + } - for (auto i : map) { - i->val.setVal(3); - } + for (auto i : map) { + i->val.setVal(3); + } - map.removeAll(); + map.removeAll(); - TEST(map.getAllocator().getAllocationsCount() == 1); + TEST(map.getAllocator().getAllocationsCount() == 1); } TEST_DEF_STATIC(SimplePointer) { - tp::Map map; + tp::Map map; - for (auto i : Range(1000)) { - map.put(i, new TestClass(i)); - } + for (auto i : Range(1000)) { + map.put(i, new TestClass(i)); + } - for (auto i : Range(1000)) { - TEST(map.presents(i)); - TEST_EQUAL(map.get(i)->getVal(), i); - } + for (auto i : Range(1000)) { + TEST(map.presents(i)); + TEST_EQUAL(map.get(i)->getVal(), i); + } - for (auto i : Range(1000)) { - map.put(i, new TestClass(i)); - } + for (auto i : Range(1000)) { + map.put(i, new TestClass(i)); + } - for (auto i : Range(900, 1000)) { - TEST(map.presents(i)); - map.remove(i); - TEST(!map.presents(i)); - } + for (auto i : Range(900, 1000)) { + TEST(map.presents(i)); + map.remove(i); + TEST(!map.presents(i)); + } - for (auto i : Range(900)) { - TEST(map.presents(i)); - TEST_EQUAL(map.get(i)->getVal(), i); - } + for (auto i : Range(900)) { + TEST(map.presents(i)); + TEST_EQUAL(map.get(i)->getVal(), i); + } - for (auto i : map) { - i->val->setVal(3); - delete i->val; - } + for (auto i : map) { + i->val->setVal(3); + delete i->val; + } - map.removeAll(); + map.removeAll(); - TEST(map.getAllocator().getAllocationsCount() == 1); + TEST(map.getAllocator().getAllocationsCount() == 1); } TEST_DEF_STATIC(Copy) { - tp::Map map; + tp::Map map; - for (auto i : Range(10)) { - map.put(i, TestClass(i)); - } + for (auto i : Range(10)) { + map.put(i, TestClass(i)); + } - tp::Map map2 = map; + tp::Map map2 = map; - TEST_EQUAL(map, map2); + TEST_EQUAL(map, map2); - map.removeAll(); - map2.removeAll(); + map.removeAll(); + map2.removeAll(); - TEST(map.getAllocator().getAllocationsCount() == 1); - TEST(map2.getAllocator().getAllocationsCount() == 1); + TEST(map.getAllocator().getAllocationsCount() == 1); + TEST(map2.getAllocator().getAllocationsCount() == 1); } TEST_DEF_STATIC(SaveLoad) { - tp::Map map; + tp::Map map; - for (auto i : Range(10)) { - map.put(i, TestClass(i)); - } + for (auto i : Range(10)) { + map.put(i, TestClass(i)); + } - TestFile file; + TestFile file; - map.write(file); + map.write(file); - map.removeAll(); + map.removeAll(); - TEST(map.getAllocator().getAllocationsCount() == 1); + TEST(map.getAllocator().getAllocationsCount() == 1); - file.setAddress(0); + file.setAddress(0); - map.read(file); + map.read(file); - TEST(map.getAllocator().getAllocationsCount() == 11); + TEST(map.getAllocator().getAllocationsCount() == 11); - for (auto i : Range(10)) { - TEST(map.presents(i)); - TEST_EQUAL(map.get(i).getVal(), i); - } + for (auto i : Range(10)) { + TEST(map.presents(i)); + TEST_EQUAL(map.get(i).getVal(), i); + } - map.removeAll(); + map.removeAll(); - TEST(map.getAllocator().getAllocationsCount() == 1); + TEST(map.getAllocator().getAllocationsCount() == 1); } TEST_DEF(Map) { - testSimplePointer(); - testSimpleReference(); - testSaveLoad(); + testSimplePointer(); + testSimpleReference(); + testSaveLoad(); } \ No newline at end of file diff --git a/Containers/tests/Tests.cpp b/Containers/tests/Tests.cpp index b5d0fbf..eee13e3 100644 --- a/Containers/tests/Tests.cpp +++ b/Containers/tests/Tests.cpp @@ -6,36 +6,36 @@ #include static bool init(const tp::ModuleManifest* self) { - tp::gTesting.setRootName(self->getName()); - return true; + tp::gTesting.setRootName(self->getName()); + return true; } void* TestAllocator::allocate(tp::ualni size) { - nAllocations++; - return malloc(size); + nAllocations++; + return malloc(size); } void TestAllocator::deallocate(void* p) { - nAllocations--; - free(p); + nAllocations--; + free(p); } tp::ualni TestAllocator::getAllocationsCount() const { - return nAllocations; + return nAllocations; } int main() { - tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; - tp::ModuleManifest testModule("ContainersTest", init, nullptr, deps); + tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; + tp::ModuleManifest testModule("ContainersTest", init, nullptr, deps); - if (!testModule.initialize()) { - return 1; - } + if (!testModule.initialize()) { + return 1; + } - testList(); - testMap(); - testAvl(); + testList(); + testMap(); + testAvl(); - testModule.deinitialize(); + testModule.deinitialize(); } diff --git a/Containers/tests/Tests.hpp b/Containers/tests/Tests.hpp index f4a7cc4..63f3fe3 100644 --- a/Containers/tests/Tests.hpp +++ b/Containers/tests/Tests.hpp @@ -3,69 +3,69 @@ #include "Utils.hpp" class TestClass { - tp::ualni val2 = 0; - tp::ualni val1; + tp::ualni val2 = 0; + tp::ualni val1; public: - explicit TestClass(tp::ualni val) : val1(val) {} + explicit TestClass(tp::ualni val) : val1(val) {} - template - void write(Saver& file) const { - file.write(val1); - } + template + void write(Saver& file) const { + file.write(val1); + } - template - void read(Loader& file) { - file.read(val1); - } + template + void read(Loader& file) { + file.read(val1); + } - [[nodiscard]] bool operator==(const TestClass& in) const { - return in.val1 == val1; - } + [[nodiscard]] bool operator==(const TestClass& in) const { + return in.val1 == val1; + } - [[nodiscard]] tp::ualni getVal() const { return val1; } - void setVal(tp::ualni val) { val1 = val; } + [[nodiscard]] tp::ualni getVal() const { return val1; } + void setVal(tp::ualni val) { val1 = val; } }; class TestAllocator { - tp::ualni nAllocations = 0; + tp::ualni nAllocations = 0; public: - TestAllocator() = default; - void* allocate(tp::ualni size); - void deallocate(void* p); - [[nodiscard]] tp::ualni getAllocationsCount() const; + TestAllocator() = default; + void* allocate(tp::ualni size); + void deallocate(void* p); + [[nodiscard]] tp::ualni getAllocationsCount() const; }; class TestFile { - tp::ualni mem[1024] = { 0 }; - tp::ualni address = 0; + tp::ualni mem[1024] = { 0 }; + tp::ualni address = 0; public: - TestFile() = default; + TestFile() = default; - template - void write(const Type& val) { - val.write(*this); - } + template + void write(const Type& val) { + val.write(*this); + } - template<> - void write(const tp::ualni& val) { - mem[address] = val; - address++; - } + template<> + void write(const tp::ualni& val) { + mem[address] = val; + address++; + } - void setAddress(tp::ualni addr) { address = addr; } + void setAddress(tp::ualni addr) { address = addr; } - template - void read(Type& val) { - val.read(*this); - } + template + void read(Type& val) { + val.read(*this); + } - template<> - void read(tp::ualni& val) { - val = mem[address]; - address++; - } + template<> + void read(tp::ualni& val) { + val = mem[address]; + address++; + } }; void testList(); diff --git a/Modules/private/Assert.cpp b/Modules/private/Assert.cpp index d74b726..6539d66 100644 --- a/Modules/private/Assert.cpp +++ b/Modules/private/Assert.cpp @@ -7,20 +7,20 @@ using namespace tp; void tp::_assert_(const char* exp, const char* file, int line) { - if (!exp) { - exp = "no info"; - } - printf("\nERROR: Assertion Failure - %s -- %s:%i\n", exp, file, line); + if (!exp) { + exp = "no info"; + } + printf("\nERROR: Assertion Failure - %s -- %s:%i\n", exp, file, line); #ifdef ENV_BUILD_DEBUG - DEBUG_BREAK(true); + DEBUG_BREAK(true); #else - exit(1); + exit(1); #endif } void tp::terminate(tp::alni code) { - exit((int)code); + exit((int)code); } \ No newline at end of file diff --git a/Modules/private/Common.cpp b/Modules/private/Common.cpp index 76c4625..b92b59a 100644 --- a/Modules/private/Common.cpp +++ b/Modules/private/Common.cpp @@ -2,45 +2,45 @@ #include "Common.hpp" namespace tp { - ualni next2pow(ualni v) { - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v |= v >> 32; - return v + 1; - } + ualni next2pow(ualni v) { + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v |= v >> 32; + return v + 1; + } - uhalni next2pow(uhalni v) { - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - return v + 1; - } + uhalni next2pow(uhalni v) { + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + return v + 1; + } - ufalni next2pow(ufalni v) { - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - return v + 1; - } + ufalni next2pow(ufalni v) { + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + return v + 1; + } - ualni hash(const char* bytes) { - unsigned long hash = 5381; - int c; - while ((c = *bytes++)) { - hash = ((hash << 5) + hash) + c; - } - return hash; - } + ualni hash(const char* bytes) { + unsigned long hash = 5381; + int c; + while ((c = *bytes++)) { + hash = ((hash << 5) + hash) + c; + } + return hash; + } - ualni hash(alni bytes) { return abs(bytes); } - ualni hash(alnf bytes) { return (alni)(abs(bytes)); } - ualni hash(halni bytes) { return hash(alni(bytes)); } - ualni hash(uhalni bytes) { return hash(alni(bytes)); } - ualni hash(ualni bytes) { return hash(alni(bytes)); } + ualni hash(alni bytes) { return abs(bytes); } + ualni hash(alnf bytes) { return (alni)(abs(bytes)); } + ualni hash(halni bytes) { return hash(alni(bytes)); } + ualni hash(uhalni bytes) { return hash(alni(bytes)); } + ualni hash(ualni bytes) { return hash(alni(bytes)); } } \ No newline at end of file diff --git a/Modules/private/Environment.cpp b/Modules/private/Environment.cpp index 17fe96c..fd78f1e 100644 --- a/Modules/private/Environment.cpp +++ b/Modules/private/Environment.cpp @@ -13,9 +13,9 @@ const char* ArchWidthString[] = { "UNDEF", "X64", "X32" }; const tp::Environment tp::gEnvironment; void tp::Environment::log() const { - std::cout << "ARCH : " << ArchString[(int)mArch] << "\n"; - std::cout << "WIDTH : " << ArchWidthString[(int)mWidth] << "\n"; - std::cout << "CURRENT OS : " << OSString[(int)mOS] << "\n"; - std::cout << "TOOLCHAIN : " << ToolchainString[(int)mToolchain] << "\n"; - std::cout << "BUILD TYPE : " << BuildTypeString[(int)mBuildType] << "\n"; + std::cout << "ARCH : " << ArchString[(int)mArch] << "\n"; + std::cout << "WIDTH : " << ArchWidthString[(int)mWidth] << "\n"; + std::cout << "CURRENT OS : " << OSString[(int)mOS] << "\n"; + std::cout << "TOOLCHAIN : " << ToolchainString[(int)mToolchain] << "\n"; + std::cout << "BUILD TYPE : " << BuildTypeString[(int)mBuildType] << "\n"; } \ No newline at end of file diff --git a/Modules/private/Module.cpp b/Modules/private/Module.cpp index ad5e91e..0a67342 100644 --- a/Modules/private/Module.cpp +++ b/Modules/private/Module.cpp @@ -6,76 +6,76 @@ using namespace tp; static bool init(const ModuleManifest* self) { - gEnvironment.log(); - return true; + gEnvironment.log(); + return true; } static ModuleManifest* deps[] = { nullptr }; ModuleManifest tp::gModuleBase = ModuleManifest("Common", init, nullptr, deps); ModuleManifest::ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies) { - mInit = aInit; - mDeinit = aDeinit; - mDependencies = aDependencies; - mModuleName = aModuleName; + mInit = aInit; + mDeinit = aDeinit; + mDependencies = aDependencies; + mModuleName = aModuleName; } bool ModuleManifest::isInitialized() const { - return mInitialized; + return mInitialized; } bool ModuleManifest::initialize() { - mInitCount++; + mInitCount++; - if (isInitialized()) { - return true; - } + if (isInitialized()) { + return true; + } - mInitialized = true; + mInitialized = true; - for (auto module = mDependencies; module && *module; module++) { - mInitialized &= (*module)->initialize(); - } + for (auto module = mDependencies; module && *module; module++) { + mInitialized &= (*module)->initialize(); + } - std::cout << "====== Initializing \"" << mModuleName << "\"\n"; + std::cout << "====== Initializing \"" << mModuleName << "\"\n"; - if (mInit) mInitialized &= mInit(this); + if (mInit) mInitialized &= mInit(this); - if (!mInitialized) { - std::cout << "Failed to Initialize.\n"; - } + if (!mInitialized) { + std::cout << "Failed to Initialize.\n"; + } - return mInitialized; + return mInitialized; } void ModuleManifest::deinitialize() { - mInitCount--; + mInitCount--; - if (mInitCount > 0) { - return; - } + if (mInitCount > 0) { + return; + } - if (!isInitialized()) { - return; - } + if (!isInitialized()) { + return; + } - if (mDeinit) mDeinit(this); - mInitialized = false; + if (mDeinit) mDeinit(this); + mInitialized = false; - auto len = 0; - for (auto module = mDependencies; module && *module; module++) { - len++; - } + auto len = 0; + for (auto module = mDependencies; module && *module; module++) { + len++; + } - for (auto i = 0; i < len; i++) { - auto module = mDependencies + (len - i - 1); - if ((*module)->isInitialized()) { - (*module)->deinitialize(); - } - } + for (auto i = 0; i < len; i++) { + auto module = mDependencies + (len - i - 1); + if ((*module)->isInitialized()) { + (*module)->deinitialize(); + } + } } const char *ModuleManifest::getName() const { - return mModuleName; + return mModuleName; } diff --git a/Modules/public/Assert.hpp b/Modules/public/Assert.hpp index 6c7af04..c85ac87 100644 --- a/Modules/public/Assert.hpp +++ b/Modules/public/Assert.hpp @@ -5,7 +5,7 @@ namespace tp { void _assert_(const char* exp, const char* file, int line); - void terminate(tp::alni code = 0); + void terminate(tp::alni code = 0); }; #define FAIL(exp) tp::_assert_(#exp, __FILE__, __LINE__); diff --git a/Modules/public/Common.hpp b/Modules/public/Common.hpp index a1821e5..047f964 100644 --- a/Modules/public/Common.hpp +++ b/Modules/public/Common.hpp @@ -6,54 +6,54 @@ #include namespace tp { - template - using init_list = std::initializer_list; + template + using init_list = std::initializer_list; - // Selects whether to pass by constant reference or by value - template - using SelCopyArg = typename TypeSelect<(sizeof(tType) > sizeof(tp::alni)), const tType&, tType>::Result; + // Selects whether to pass by constant reference or by value + template + using SelCopyArg = typename TypeSelect<(sizeof(tType) > sizeof(tp::alni)), const tType&, tType>::Result; - ualni next2pow(ualni v); - uhalni next2pow(uhalni v); - ufalni next2pow(ufalni v); + ualni next2pow(ualni v); + uhalni next2pow(uhalni v); + ufalni next2pow(ufalni v); - ualni hash(const char* bytes); - ualni hash(alni bytes); - ualni hash(halni bytes); - ualni hash(uhalni bytes); - ualni hash(ualni bytes); - ualni hash(alnf bytes); + ualni hash(const char* bytes); + ualni hash(alni bytes); + ualni hash(halni bytes); + ualni hash(uhalni bytes); + ualni hash(ualni bytes); + ualni hash(alnf bytes); - template - [[nodiscard]] T clamp(T v, T l, T u) { if (v < l) { v = l; } else if (v > u) { v = u; } return v; } + template + [[nodiscard]] T clamp(T v, T l, T u) { if (v < l) { v = l; } else if (v > u) { v = u; } return v; } - template - [[nodiscard]] T max(T a, T b) { return (a > b) ? a : b; } + template + [[nodiscard]] T max(T a, T b) { return (a > b) ? a : b; } - template - [[nodiscard]] T min(T a, T b) { return (a < b) ? a : b; } + template + [[nodiscard]] T min(T a, T b) { return (a < b) ? a : b; } - template - [[nodiscard]] T abs(T v) { if (v < 0) { return -v; } return v; } + template + [[nodiscard]] T abs(T v) { if (v < 0) { return -v; } return v; } - template - inline void swap(T& t1, T& t2) { const T tmp = t1; t1 = t2; t2 = tmp; } + template + inline void swap(T& t1, T& t2) { const T tmp = t1; t1 = t2; t2 = tmp; } - // only for x > 0 and y > 0 - template - [[nodiscard]] T ceil_positive(T x, T y) { return T( 1 + ((x - 1) / (tp::alnf)y) ); } + // only for x > 0 and y > 0 + template + [[nodiscard]] T ceil_positive(T x, T y) { return T( 1 + ((x - 1) / (tp::alnf)y) ); } - // power - template - [[nodiscard]] T pow(T x, uhalni n) { - T out = x; for (uhalni i = 0; i < n - 1; i++) { out = out * x; } - return out; - } + // power + template + [[nodiscard]] T pow(T x, uhalni n) { + T out = x; for (uhalni i = 0; i < n - 1; i++) { out = out * x; } + return out; + } - template - halni nDig10(Type val) { - val = abs(val); halni out = 0; - while (val != 0) { val = halni(val / 10); out++; } - return out; - } + template + halni nDig10(Type val) { + val = abs(val); halni out = 0; + while (val != 0) { val = halni(val / 10); out++; } + return out; + } } \ No newline at end of file diff --git a/Modules/public/Environment.hpp b/Modules/public/Environment.hpp index 11a4133..80ad849 100644 --- a/Modules/public/Environment.hpp +++ b/Modules/public/Environment.hpp @@ -6,138 +6,138 @@ namespace tp { - class Environment { - public: + class Environment { + public: - enum class Arch { UNDEF, INTEL, ARM } mArch = Arch::UNDEF; + enum class Arch { UNDEF, INTEL, ARM } mArch = Arch::UNDEF; - // Build Type - #if defined(__DEBUG__) || defined(_DEBUG) || defined(DEBUG) || !defined(NDEBUG) - #define ENV_BUILD_DEBUG - enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::DEBUG; - #else - #define ENV_BUILD_RELEASE - enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::RELEASE; - #endif + // Build Type + #if defined(__DEBUG__) || defined(_DEBUG) || defined(DEBUG) || !defined(NDEBUG) + #define ENV_BUILD_DEBUG + enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::DEBUG; + #else + #define ENV_BUILD_RELEASE + enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::RELEASE; + #endif - // MCVS - #ifdef _MSC_VER - #define ENV_COMPILER_MSVC - enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::MSVC; + // MCVS + #ifdef _MSC_VER + #define ENV_COMPILER_MSVC + enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::MSVC; - // VERSION - // TODO + // VERSION + // TODO - // TARGET OS - #if defined(_WIN32) || defined(_WIN64) - #define ENV_OS_WINDOWS - enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::WINDOWS; - #else - enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::UNDEF; - #error "unexplored compilation to os target" - #endif + // TARGET OS + #if defined(_WIN32) || defined(_WIN64) + #define ENV_OS_WINDOWS + enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::WINDOWS; + #else + enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::UNDEF; + #error "unexplored compilation to os target" + #endif - // TARGET ALIGNED SIZE - #ifdef _WIN64 - enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64; - #define ENV_BITS_64 - #else - enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32; - #define ENV_BITS_32 - #endif + // TARGET ALIGNED SIZE + #ifdef _WIN64 + enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64; + #define ENV_BITS_64 + #else + enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32; + #define ENV_BITS_32 + #endif - #endif + #endif - // GCC - #if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) - #define ENV_COMPILER_GCC - enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::GNU; + // GCC + #if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER) + #define ENV_COMPILER_GCC + enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::GNU; - // VERSION - #if (__GNUC___ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) - // TODO - #endif + // VERSION + #if (__GNUC___ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) + // TODO + #endif - // TARGET OS - #if defined(__linux__) && !defined(__ANDROID__) - #define ENV_OS_LINUX - enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX; - #else - #error "unexplored compilation to os target" - #endif + // TARGET OS + #if defined(__linux__) && !defined(__ANDROID__) + #define ENV_OS_LINUX + enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX; + #else + #error "unexplored compilation to os target" + #endif - // TARGET ALIGNED SIZE - #if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE) - #define ENV_BITS_64 - enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64; - #elif defined(__x86_64__) || defined(i386) - #define ENV_BITS_32 - enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32; - #endif + // TARGET ALIGNED SIZE + #if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE) + #define ENV_BITS_64 + enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64; + #elif defined(__x86_64__) || defined(i386) + #define ENV_BITS_32 + enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32; + #endif - #endif + #endif - // CLANG - #if defined(__clang__) && !defined(ENV_COMPILER_GCC) - #define ENV_COMPILER_CLANG - enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::LLVM; + // CLANG + #if defined(__clang__) && !defined(ENV_COMPILER_GCC) + #define ENV_COMPILER_CLANG + enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::LLVM; - // VERSION - #if (__clang_major__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) - // TODO - #endif + // VERSION + #if (__clang_major__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) + // TODO + #endif - // TARGET OS - #if defined(__linux__) && !defined(__ANDROID__) - #define ENV_OS_LINUX - enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX; - #elif defined(__ANDROID__) - enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::ANDOID; - #define ENV_OS_ANDROID - #else - #error "unexplored compilation to target os" - #endif + // TARGET OS + #if defined(__linux__) && !defined(__ANDROID__) + #define ENV_OS_LINUX + enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX; + #elif defined(__ANDROID__) + enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::ANDOID; + #define ENV_OS_ANDROID + #else + #error "unexplored compilation to target os" + #endif - // TARGET ALIGNED SIZE - #if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE) - #define ENV_BITS_64 - enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64; - #elif defined(__x86_64__) || defined(i386) - #define ENV_BITS_32 - enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32; - #endif + // TARGET ALIGNED SIZE + #if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE) + #define ENV_BITS_64 + enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64; + #elif defined(__x86_64__) || defined(i386) + #define ENV_BITS_32 + enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32; + #endif - #endif + #endif - #if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__MINGW32__) || defined(__MINGW64__) - #error "compiler is not supported" - #else - #if !(defined(ENV_COMPILER_MSVC) || defined(ENV_COMPILER_CLANG) || defined(ENV_COMPILER_GCC)) - // Linux and Linux - derived __linux__ - // Darwin(Mac OS X and iOS) __APPLE__ - // Akaros __ros__ - // NaCL __native_client__ - // AsmJS __asmjs__ - // Fuschia __Fuchsia__ - #error "unknown compiler" - #endif - #endif + #if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__MINGW32__) || defined(__MINGW64__) + #error "compiler is not supported" + #else + #if !(defined(ENV_COMPILER_MSVC) || defined(ENV_COMPILER_CLANG) || defined(ENV_COMPILER_GCC)) + // Linux and Linux - derived __linux__ + // Darwin(Mac OS X and iOS) __APPLE__ + // Akaros __ros__ + // NaCL __native_client__ + // AsmJS __asmjs__ + // Fuschia __Fuchsia__ + #error "unknown compiler" + #endif + #endif - void log() const; - }; + void log() const; + }; - #ifndef ENV_BITS_64 - #error "ERROR - not 64 bit archytectures are out of support" - #endif + #ifndef ENV_BITS_64 + #error "ERROR - not 64 bit archytectures are out of support" + #endif - const extern Environment gEnvironment; + const extern Environment gEnvironment; typedef char int1; typedef unsigned char uint1; typedef short int2; typedef unsigned short uint2; typedef unsigned int uint4; - typedef uint2 ufalni; + typedef uint2 ufalni; typedef uint4 uhalni; typedef int int4; typedef int4 halni; diff --git a/Modules/public/Module.hpp b/Modules/public/Module.hpp index 19ae60b..da2a79c 100644 --- a/Modules/public/Module.hpp +++ b/Modules/public/Module.hpp @@ -8,24 +8,24 @@ namespace tp { - class ModuleManifest { - public: - typedef bool (*ModuleInit)(const ModuleManifest*); - typedef void (*ModuleDeinit)(const ModuleManifest*); + class ModuleManifest { + public: + typedef bool (*ModuleInit)(const ModuleManifest*); + typedef void (*ModuleDeinit)(const ModuleManifest*); - ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies); - [[nodiscard]] bool isInitialized() const; - bool initialize(); - void deinitialize(); - [[nodiscard]] const char* getName() const; - private: - const char* mModuleName = nullptr; - ModuleManifest** mDependencies; // NULL terminated - bool mInitialized = false; - ModuleInit mInit = nullptr; - ModuleDeinit mDeinit = nullptr; - uhalni mInitCount = 0; - }; + ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies); + [[nodiscard]] bool isInitialized() const; + bool initialize(); + void deinitialize(); + [[nodiscard]] const char* getName() const; + private: + const char* mModuleName = nullptr; + ModuleManifest** mDependencies; // NULL terminated + bool mInitialized = false; + ModuleInit mInit = nullptr; + ModuleDeinit mDeinit = nullptr; + uhalni mInitCount = 0; + }; - extern ModuleManifest gModuleBase; + extern ModuleManifest gModuleBase; }; diff --git a/Modules/public/TypeInfo.hpp b/Modules/public/TypeInfo.hpp index 64e1e79..ecf6118 100644 --- a/Modules/public/TypeInfo.hpp +++ b/Modules/public/TypeInfo.hpp @@ -30,14 +30,14 @@ namespace tp { - template - struct TypeSelect { - typedef T Result; - }; - template - struct TypeSelect { - typedef U Result; - }; + template + struct TypeSelect { + typedef T Result; + }; + template + struct TypeSelect { + typedef U Result; + }; } namespace tp { @@ -50,30 +50,30 @@ namespace tp { // Result evaluates to true iff U == T (types equal) //////////////////////////////////////////////////////////////////////////////// - template - struct IsSameType { - enum { value = false }; - }; + template + struct IsSameType { + enum { value = false }; + }; - template - struct IsSameType { - enum { value = true }; - }; + template + struct IsSameType { + enum { value = true }; + }; //////////////////////////////////////////////////////////////////////////////// // Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big) //////////////////////////////////////////////////////////////////////////////// - namespace Private { - template - struct ConversionHelper { - typedef char Small; - struct Big { char dummy[2]; }; - static Big Test(...); - static Small Test(U); - static T MakeT(); - }; - } + namespace Private { + template + struct ConversionHelper { + typedef char Small; + struct Big { char dummy[2]; }; + static Big Test(...); + static Small Test(U); + static T MakeT(); + }; + } //////////////////////////////////////////////////////////////////////////////// // class template Conversion @@ -91,38 +91,38 @@ namespace tp { // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// - template - struct Conversion { - typedef Private::ConversionHelper H; + template + struct Conversion { + typedef Private::ConversionHelper H; #ifndef __MWERKS__ - enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) }; + enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) }; #else - enum { exists = false }; + enum { exists = false }; #endif - enum { exists2Way = exists && Conversion::exists }; - enum { sameType = false }; - }; + enum { exists2Way = exists && Conversion::exists }; + enum { sameType = false }; + }; - template - struct Conversion { - enum { exists = 1, exists2Way = 1, sameType = 1 }; - }; + template + struct Conversion { + enum { exists = 1, exists2Way = 1, sameType = 1 }; + }; - template - struct Conversion { - enum { exists = 0, exists2Way = 0, sameType = 0 }; - }; + template + struct Conversion { + enum { exists = 0, exists2Way = 0, sameType = 0 }; + }; - template - struct Conversion { - enum { exists = 0, exists2Way = 0, sameType = 0 }; - }; + template + struct Conversion { + enum { exists = 0, exists2Way = 0, sameType = 0 }; + }; - template <> - struct Conversion { - public: - enum { exists = 1, exists2Way = 1, sameType = 1 }; - }; + template <> + struct Conversion { + public: + enum { exists = 1, exists2Way = 1, sameType = 1 }; + }; //////////////////////////////////////////////////////////////////////////////// // class template SuperSubclass @@ -133,92 +133,89 @@ namespace tp { // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// - template - struct SuperSubclass { - enum { - value = (::tp::Conversion::exists && - !::tp::Conversion::sameType) - }; + template + struct SuperSubclass { + enum { + value = (::tp::Conversion::exists && !::tp::Conversion::sameType) + }; // Dummy enum to make sure that both classes are fully defined. - enum { dontUseWithIncompleteTypes = (sizeof(T) == sizeof(U)) }; - }; + enum { dontUseWithIncompleteTypes = (sizeof(T) == sizeof(U)) }; + }; - template <> - struct SuperSubclass { - enum { value = false }; - }; + template <> + struct SuperSubclass { + enum { value = false }; + }; - template - struct SuperSubclass { - enum { - value = (::tp::Conversion::exists && - !::tp::Conversion::sameType) - }; + template + struct SuperSubclass { + enum { + value = (::tp::Conversion::exists && !::tp::Conversion::sameType) + }; // Dummy enum to make sure that both classes are fully defined. - enum { dontUseWithIncompleteTypes = (0 == sizeof(U)) }; - }; + enum { dontUseWithIncompleteTypes = (0 == sizeof(U)) }; + }; - template - struct SuperSubclass { - enum { - value = (::tp::Conversion::exists && - !::tp::Conversion::sameType) - }; + template + struct SuperSubclass { + enum { + value = (::tp::Conversion::exists && !::tp::Conversion::sameType) + }; // Dummy enum to make sure that both classes are fully defined. - enum { dontUseWithIncompleteTypes = (sizeof(T) == 0) }; - }; + enum { dontUseWithIncompleteTypes = (sizeof(T) == 0) }; + }; - //////////////////////////////////////////////////////////////////////////////// - // class template SuperSubclassStrict - // Invocation: SuperSubclassStrict::value where B and D are types. - // Returns true if B is a public base of D. - // - // Caveat: might not work if T and U are in a private inheritance hierarchy. - //////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////// + // class template SuperSubclassStrict + // Invocation: SuperSubclassStrict::value where B and D are types. + // Returns true if B is a public base of D. + // + // Caveat: might not work if T and U are in a private inheritance hierarchy. + //////////////////////////////////////////////////////////////////////////////// - template - struct SuperSubclassStrict { - enum { - value = (::tp::Conversion::exists && - !::tp::Conversion::sameType && - !::tp::Conversion::sameType) - }; + template + struct SuperSubclassStrict { + enum { + value = (::tp::Conversion::exists && + !::tp::Conversion::sameType && + !::tp::Conversion::sameType) + }; // Dummy enum to make sure that both classes are fully defined. - enum { dontUseWithIncompleteTypes = (sizeof(T) == sizeof(U)) }; - }; + enum { dontUseWithIncompleteTypes = (sizeof(T) == sizeof(U)) }; + }; - template<> - struct SuperSubclassStrict { - enum { value = false }; - }; + template<> + struct SuperSubclassStrict { + enum { value = false }; + }; - template - struct SuperSubclassStrict { - enum { - value = (::tp::Conversion::exists && - !::tp::Conversion::sameType && - !::tp::Conversion::sameType) - }; + template + struct SuperSubclassStrict { + enum { + value = (::tp::Conversion::exists && + !::tp::Conversion::sameType && + !::tp::Conversion::sameType) + }; // Dummy enum to make sure that both classes are fully defined. - enum { dontUseWithIncompleteTypes = (0 == sizeof(U)) }; - }; + enum { dontUseWithIncompleteTypes = (0 == sizeof(U)) }; + }; - template - struct SuperSubclassStrict { - enum { - value = (::tp::Conversion::exists && - !::tp::Conversion::sameType && - !::tp::Conversion::sameType) - }; + template + struct SuperSubclassStrict { + enum { + value = (::tp::Conversion::exists && + !::tp::Conversion::sameType && + !::tp::Conversion::sameType) + }; // Dummy enum to make sure that both classes are fully defined. - enum { dontUseWithIncompleteTypes = (sizeof(T) == 0) }; - }; + enum { dontUseWithIncompleteTypes = (sizeof(T) == 0) }; + }; } // namespace tp @@ -250,7 +247,7 @@ namespace tp { namespace tp { - struct NullType {}; + struct NullType {}; //////////////////////////////////////////////////////////////////////////////// // class template Typelist @@ -261,15 +258,15 @@ namespace tp { // Tail (second element, can be another typelist) //////////////////////////////////////////////////////////////////////////////// - template - struct Typelist { - typedef T Head; - typedef U Tail; - }; + template + struct Typelist { + typedef T Head; + typedef U Tail; + }; // Typelist utility algorithms - namespace TL { + namespace TL { //////////////////////////////////////////////////////////////////////////////// // class template MakeTypelist @@ -279,36 +276,36 @@ namespace tp { // returns a typelist that is of T1, T2, ... //////////////////////////////////////////////////////////////////////////////// - template - < - typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, - typename T4 = NullType, typename T5 = NullType, typename T6 = NullType, - typename T7 = NullType, typename T8 = NullType, typename T9 = NullType, - typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, - typename T13 = NullType, typename T14 = NullType, typename T15 = NullType, - typename T16 = NullType, typename T17 = NullType, typename T18 = NullType - > - struct MakeTypelist { - private: - typedef typename MakeTypelist - < - T2, T3, T4, - T5, T6, T7, - T8, T9, T10, - T11, T12, T13, - T14, T15, T16, - T17, T18 - > - ::Result TailResult; + template + < + typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, + typename T4 = NullType, typename T5 = NullType, typename T6 = NullType, + typename T7 = NullType, typename T8 = NullType, typename T9 = NullType, + typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, + typename T13 = NullType, typename T14 = NullType, typename T15 = NullType, + typename T16 = NullType, typename T17 = NullType, typename T18 = NullType + > + struct MakeTypelist { + private: + typedef typename MakeTypelist + < + T2, T3, T4, + T5, T6, T7, + T8, T9, T10, + T11, T12, T13, + T14, T15, T16, + T17, T18 + > + ::Result TailResult; - public: - typedef Typelist Result; - }; + public: + typedef Typelist Result; + }; - template<> - struct MakeTypelist<> { - typedef NullType Result; - }; + template<> + struct MakeTypelist<> { + typedef NullType Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template Length @@ -319,15 +316,15 @@ namespace tp { // the end terminator (which by convention is NullType) //////////////////////////////////////////////////////////////////////////////// - template struct Length; - template <> struct Length { - enum { value = 0 }; - }; + template struct Length; + template <> struct Length { + enum { value = 0 }; + }; - template - struct Length< Typelist > { - enum { value = 1 + Length::value }; - }; + template + struct Length< Typelist > { + enum { value = 1 + Length::value }; + }; //////////////////////////////////////////////////////////////////////////////// // class template TypeAt @@ -339,17 +336,17 @@ namespace tp { // If you pass an out-of-bounds index, the result is a compile-time error //////////////////////////////////////////////////////////////////////////////// - template struct TypeAt; + template struct TypeAt; - template - struct TypeAt, 0> { - typedef Head Result; - }; + template + struct TypeAt, 0> { + typedef Head Result; + }; - template - struct TypeAt, i> { - typedef typename TypeAt::Result Result; - }; + template + struct TypeAt, i> { + typedef typename TypeAt::Result Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template TypeAtNonStrict @@ -363,22 +360,22 @@ namespace tp { // returns the type in position 'index' in TList, or D if index is out-of-bounds //////////////////////////////////////////////////////////////////////////////// - template - struct TypeAtNonStrict { - typedef DefaultType Result; - }; + template + struct TypeAtNonStrict { + typedef DefaultType Result; + }; - template - struct TypeAtNonStrict, 0, DefaultType> { - typedef Head Result; - }; + template + struct TypeAtNonStrict, 0, DefaultType> { + typedef Head Result; + }; - template - struct TypeAtNonStrict, i, DefaultType> { - typedef typename - TypeAtNonStrict::Result Result; - }; + template + struct TypeAtNonStrict, i, DefaultType> { + typedef typename + TypeAtNonStrict::Result Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template IndexOf @@ -388,25 +385,25 @@ namespace tp { // returns the position of T in TList, or NullType if T is not found in TList //////////////////////////////////////////////////////////////////////////////// - template struct IndexOf; + template struct IndexOf; - template - struct IndexOf { - enum { value = -1 }; - }; + template + struct IndexOf { + enum { value = -1 }; + }; - template - struct IndexOf, T> { - enum { value = 0 }; - }; + template + struct IndexOf, T> { + enum { value = 0 }; + }; - template - struct IndexOf, T> { - private: - enum { temp = IndexOf::value }; - public: - enum { value = (temp == -1 ? -1 : 1 + temp) }; - }; + template + struct IndexOf, T> { + private: + enum { temp = IndexOf::value }; + public: + enum { value = (temp == -1 ? -1 : 1 + temp) }; + }; //////////////////////////////////////////////////////////////////////////////// // class template Append @@ -416,27 +413,25 @@ namespace tp { // returns a typelist that is TList followed by T and NullType-terminated //////////////////////////////////////////////////////////////////////////////// - template struct Append; + template struct Append; - template <> struct Append { - typedef NullType Result; - }; + template <> struct Append { + typedef NullType Result; + }; - template struct Append { - typedef Typelist Result; - }; + template struct Append { + typedef Typelist Result; + }; - template - struct Append > { - typedef Typelist Result; - }; + template + struct Append > { + typedef Typelist Result; + }; - template - struct Append, T> { - typedef Typelist::Result> - Result; - }; + template + struct Append, T> { + typedef Typelist::Result> Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template Erase @@ -446,24 +441,22 @@ namespace tp { // returns a typelist that is TList without the first occurence of T //////////////////////////////////////////////////////////////////////////////// - template struct Erase; + template struct Erase; - template // Specialization 1 - struct Erase { - typedef NullType Result; - }; + template // Specialization 1 + struct Erase { + typedef NullType Result; + }; - template // Specialization 2 - struct Erase, T> { - typedef Tail Result; - }; + template // Specialization 2 + struct Erase, T> { + typedef Tail Result; + }; - template // Specialization 3 - struct Erase, T> { - typedef Typelist::Result> - Result; - }; + template // Specialization 3 + struct Erase, T> { + typedef Typelist::Result> Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template EraseAll @@ -473,23 +466,21 @@ namespace tp { // returns a typelist that is TList without any occurence of T //////////////////////////////////////////////////////////////////////////////// - template struct EraseAll; - template - struct EraseAll { - typedef NullType Result; - }; - template - struct EraseAll, T> { - // Go all the way down the list removing the type - typedef typename EraseAll::Result Result; - }; - template - struct EraseAll, T> { - // Go all the way down the list removing the type - typedef Typelist::Result> - Result; - }; + template struct EraseAll; + template + struct EraseAll { + typedef NullType Result; + }; + template + struct EraseAll, T> { + // Go all the way down the list removing the type + typedef typename EraseAll::Result Result; + }; + template + struct EraseAll, T> { + // Go all the way down the list removing the type + typedef Typelist::Result> Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template NoDuplicates @@ -498,20 +489,20 @@ namespace tp { // NoDuplicates::Result //////////////////////////////////////////////////////////////////////////////// - template struct NoDuplicates; + template struct NoDuplicates; - template <> struct NoDuplicates { - typedef NullType Result; - }; + template <> struct NoDuplicates { + typedef NullType Result; + }; - template - struct NoDuplicates< Typelist > { - private: - typedef typename NoDuplicates::Result L1; - typedef typename Erase::Result L2; - public: - typedef Typelist Result; - }; + template + struct NoDuplicates< Typelist > { + private: + typedef typename NoDuplicates::Result L1; + typedef typename Erase::Result L2; + public: + typedef Typelist Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template Replace @@ -521,24 +512,22 @@ namespace tp { // returns a typelist in which the first occurence of T is replaced with U //////////////////////////////////////////////////////////////////////////////// - template struct Replace; + template struct Replace; - template - struct Replace { - typedef NullType Result; - }; + template + struct Replace { + typedef NullType Result; + }; - template - struct Replace, T, U> { - typedef Typelist Result; - }; + template + struct Replace, T, U> { + typedef Typelist Result; + }; - template - struct Replace, T, U> { - typedef Typelist::Result> - Result; - }; + template + struct Replace, T, U> { + typedef Typelist::Result> Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template ReplaceAll @@ -548,24 +537,22 @@ namespace tp { // returns a typelist in which all occurences of T is replaced with U //////////////////////////////////////////////////////////////////////////////// - template struct ReplaceAll; + template struct ReplaceAll; - template - struct ReplaceAll { - typedef NullType Result; - }; + template + struct ReplaceAll { + typedef NullType Result; + }; - template - struct ReplaceAll, T, U> { - typedef Typelist::Result> Result; - }; + template + struct ReplaceAll, T, U> { + typedef Typelist::Result> Result; + }; - template - struct ReplaceAll, T, U> { - typedef Typelist::Result> - Result; - }; + template + struct ReplaceAll, T, U> { + typedef Typelist::Result> Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template Reverse @@ -575,18 +562,17 @@ namespace tp { // returns a typelist that is TList reversed //////////////////////////////////////////////////////////////////////////////// - template struct Reverse; + template struct Reverse; - template <> - struct Reverse { - typedef NullType Result; - }; + template <> + struct Reverse { + typedef NullType Result; + }; - template - struct Reverse< Typelist > { - typedef typename Append< - typename Reverse::Result, Head>::Result Result; - }; + template + struct Reverse< Typelist > { + typedef typename Append::Result, Head>::Result Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template MostDerived @@ -596,22 +582,20 @@ namespace tp { // returns the type in TList that's the most derived from T //////////////////////////////////////////////////////////////////////////////// - template struct MostDerived; + template struct MostDerived; - template - struct MostDerived { - typedef T Result; - }; + template + struct MostDerived { + typedef T Result; + }; - template - struct MostDerived, T> { - private: - typedef typename MostDerived::Result Candidate; - public: - typedef typename TypeSelect< - SuperSubclass::value, - Head, Candidate>::Result Result; - }; + template + struct MostDerived, T> { + private: + typedef typename MostDerived::Result Candidate; + public: + typedef typename TypeSelect::value, Head, Candidate>::Result Result; + }; //////////////////////////////////////////////////////////////////////////////// // class template DerivedToFront @@ -621,45 +605,42 @@ namespace tp { // returns the reordered TList //////////////////////////////////////////////////////////////////////////////// - template struct DerivedToFront; + template struct DerivedToFront; - template <> - struct DerivedToFront { - typedef NullType Result; - }; + template <> + struct DerivedToFront { + typedef NullType Result; + }; - template - struct DerivedToFront< Typelist > { - private: - typedef typename MostDerived::Result - TheMostDerived; - typedef typename Replace::Result Temp; - typedef typename DerivedToFront::Result L; - public: - typedef Typelist Result; - }; + template + struct DerivedToFront< Typelist > { + private: + typedef typename MostDerived::Result TheMostDerived; + typedef typename Replace::Result Temp; + typedef typename DerivedToFront::Result L; + public: + typedef Typelist Result; + }; - } // namespace TL + } // namespace TL - template < - class T01 = NullType, class T02 = NullType, class T03 = NullType, class T04 = NullType, class T05 = NullType, - class T06 = NullType, class T07 = NullType, class T08 = NullType, class T09 = NullType, class T10 = NullType, - class T11 = NullType, class T12 = NullType, class T13 = NullType, class T14 = NullType, class T15 = NullType, - class T16 = NullType, class T17 = NullType, class T18 = NullType, class T19 = NullType, class T20 = NullType - > - class Seq { - typedef typename Seq< T02, T03, T04, T05, T06, T07, T08, T09, T10, - T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>::list TailResult; - public: - typedef Typelist list; - }; + template < + class T01 = NullType, class T02 = NullType, class T03 = NullType, class T04 = NullType, class T05 = NullType, + class T06 = NullType, class T07 = NullType, class T08 = NullType, class T09 = NullType, class T10 = NullType, + class T11 = NullType, class T12 = NullType, class T13 = NullType, class T14 = NullType, class T15 = NullType, + class T16 = NullType, class T17 = NullType, class T18 = NullType, class T19 = NullType, class T20 = NullType + > + class Seq { + typedef typename Seq::list TailResult; + public: + typedef Typelist list; + }; - template<> - struct Seq<> { - typedef NullType list; - }; + template<> + struct Seq<> { + typedef NullType list; + }; } // namespace tp @@ -696,10 +677,10 @@ namespace tp { // and define value = 1 in those specializations //////////////////////////////////////////////////////////////////////////////// - template - struct IsCustomUnsignedInt { - enum { value = 0 }; - }; + template + struct IsCustomUnsignedInt { + enum { value = 0 }; + }; //////////////////////////////////////////////////////////////////////////////// // class template IsCustomSignedInt @@ -713,10 +694,10 @@ namespace tp { // and define value = 1 in those specializations //////////////////////////////////////////////////////////////////////////////// - template - struct IsCustomSignedInt { - enum { value = 0 }; - }; + template + struct IsCustomSignedInt { + enum { value = 0 }; + }; //////////////////////////////////////////////////////////////////////////////// // class template IsCustomFloat @@ -729,34 +710,34 @@ namespace tp { // and define value = 1 in those specializations //////////////////////////////////////////////////////////////////////////////// - template - struct IsCustomFloat { - enum { value = 0 }; - }; + template + struct IsCustomFloat { + enum { value = 0 }; + }; //////////////////////////////////////////////////////////////////////////////// // Helper types for class template TypeTraits defined below //////////////////////////////////////////////////////////////////////////////// - namespace Private { + namespace Private { - typedef Seq::list StdUnsignedInts; - typedef Seq::list StdSignedInts; - typedef Seq::list StdOtherInts; - typedef Seq::list StdFloats; + typedef Seq::list StdUnsignedInts; + typedef Seq::list StdSignedInts; + typedef Seq::list StdOtherInts; + typedef Seq::list StdFloats; - template struct AddPointer { typedef U* Result; }; - template struct AddPointer { typedef U* Result; }; + template struct AddPointer { typedef U* Result; }; + template struct AddPointer { typedef U* Result; }; - template struct AddReference { typedef U& Result; }; - template struct AddReference { typedef U& Result; }; - template <> struct AddReference { typedef NullType Result; }; + template struct AddReference { typedef U& Result; }; + template struct AddReference { typedef U& Result; }; + template <> struct AddReference { typedef NullType Result; }; - template struct AddParameterType { typedef const U& Result; }; - template struct AddParameterType { typedef U& Result; }; - template <> struct AddParameterType { typedef NullType Result; }; + template struct AddParameterType { typedef const U& Result; }; + template struct AddParameterType { typedef U& Result; }; + template <> struct AddParameterType { typedef NullType Result; }; - }// namespace Private + }// namespace Private //////////////////////////////////////////////////////////////////////////////// // class template TypeTraits @@ -796,130 +777,124 @@ namespace tp { // //////////////////////////////////////////////////////////////////////////////// - template - class TypeTraits { - private: + template + class TypeTraits { + private: - template struct ReferenceTraits { - enum { result = false }; - typedef U ReferredType; - }; + template struct ReferenceTraits { + enum { result = false }; + typedef U ReferredType; + }; - template struct ReferenceTraits { - enum { result = true }; - typedef U ReferredType; - }; + template struct ReferenceTraits { + enum { result = true }; + typedef U ReferredType; + }; - template struct PointerTraits { - enum { result = false }; - typedef NullType PointeeType; - }; + template struct PointerTraits { + enum { result = false }; + typedef NullType PointeeType; + }; - template struct PointerTraits { - enum { result = true }; - typedef U PointeeType; - }; + template struct PointerTraits { + enum { result = true }; + typedef U PointeeType; + }; - template struct PointerTraits { - enum { result = true }; - typedef U PointeeType; - }; + template struct PointerTraits { + enum { result = true }; + typedef U PointeeType; + }; - template struct PToMTraits { - enum { result = false }; - }; + template struct PToMTraits { + enum { result = false }; + }; - template struct PToMTraits { - enum { result = true }; - }; + template struct PToMTraits { + enum { result = true }; + }; - template struct PToMTraits { - enum { result = true }; - }; + template struct PToMTraits { + enum { result = true }; + }; - template struct UnConst { - typedef U Result; - enum { isConst = 0 }; - }; + template struct UnConst { + typedef U Result; + enum { isConst = 0 }; + }; - template struct UnConst { - typedef U Result; - enum { isConst = 1 }; - }; + template struct UnConst { + typedef U Result; + enum { isConst = 1 }; + }; - template struct UnConst { - typedef U& Result; - enum { isConst = 1 }; - }; + template struct UnConst { + typedef U& Result; + enum { isConst = 1 }; + }; - template struct UnVolatile { - typedef U Result; - enum { isVolatile = 0 }; - }; + template struct UnVolatile { + typedef U Result; + enum { isVolatile = 0 }; + }; - template struct UnVolatile { - typedef U Result; - enum { isVolatile = 1 }; - }; + template struct UnVolatile { + typedef U Result; + enum { isVolatile = 1 }; + }; - template struct UnVolatile { - typedef U& Result; - enum { isVolatile = 1 }; - }; + template struct UnVolatile { + typedef U& Result; + enum { isVolatile = 1 }; + }; - public: - typedef typename UnConst::Result - NonConstType; - typedef typename UnVolatile::Result - NonVolatileType; - typedef typename UnVolatile::Result>::Result - UnqualifiedType; - typedef typename PointerTraits::PointeeType - PointeeType; - typedef typename ReferenceTraits::ReferredType - ReferredType; + public: + typedef typename UnConst::Result NonConstType; + typedef typename UnVolatile::Result NonVolatileType; + typedef typename UnVolatile::Result>::Result UnqualifiedType; + typedef typename PointerTraits::PointeeType PointeeType; + typedef typename ReferenceTraits::ReferredType ReferredType; - enum { isConst = UnConst::isConst }; - enum { isVolatile = UnVolatile::isVolatile }; - enum { isReference = ReferenceTraits::result }; - enum { isMemberPointer = PToMTraits::ReferredType >::result }; - enum { isPointer = PointerTraits::ReferredType >::result }; + enum { isConst = UnConst::isConst }; + enum { isVolatile = UnVolatile::isVolatile }; + enum { isReference = ReferenceTraits::result }; + enum { isMemberPointer = PToMTraits::ReferredType >::result }; + enum { isPointer = PointerTraits::ReferredType >::result }; - enum { - isStdUnsignedInt = TL::IndexOf::value >= 0 || - TL::IndexOf::ReferredType>::value >= 0 - }; - enum { - isStdSignedInt = TL::IndexOf::value >= 0 || - TL::IndexOf::ReferredType>::value >= 0 - }; - enum { - isStdIntegral = isStdUnsignedInt || isStdSignedInt || - TL::IndexOf::value >= 0 || - TL::IndexOf::ReferredType>::value >= 0 - }; - enum { - isStdFloat = TL::IndexOf::value >= 0 || - TL::IndexOf::ReferredType>::value >= 0 - }; + enum { + isStdUnsignedInt = TL::IndexOf::value >= 0 || + TL::IndexOf::ReferredType>::value >= 0 + }; + enum { + isStdSignedInt = TL::IndexOf::value >= 0 || + TL::IndexOf::ReferredType>::value >= 0 + }; + enum { + isStdIntegral = isStdUnsignedInt || isStdSignedInt || + TL::IndexOf::value >= 0 || + TL::IndexOf::ReferredType>::value >= 0 + }; + enum { + isStdFloat = TL::IndexOf::value >= 0 || + TL::IndexOf::ReferredType>::value >= 0 + }; - enum { isStdArith = isStdIntegral || isStdFloat }; - enum { isStdFundamental = isStdArith || isStdFloat || Conversion::sameType }; + enum { isStdArith = isStdIntegral || isStdFloat }; + enum { isStdFundamental = isStdArith || isStdFloat || Conversion::sameType }; - enum { isUnsignedInt = isStdUnsignedInt || IsCustomUnsignedInt::value }; - enum { isSignedInt = isStdSignedInt || IsCustomSignedInt::value }; - enum { isIntegral = isStdIntegral || isUnsignedInt || isSignedInt }; - enum { isFloat = isStdFloat || IsCustomFloat::value }; - enum { isArith = isIntegral || isFloat }; - enum { isFundamental = isStdFundamental || isArith }; + enum { isUnsignedInt = isStdUnsignedInt || IsCustomUnsignedInt::value }; + enum { isSignedInt = isStdSignedInt || IsCustomSignedInt::value }; + enum { isIntegral = isStdIntegral || isUnsignedInt || isSignedInt }; + enum { isFloat = isStdFloat || IsCustomFloat::value }; + enum { isArith = isIntegral || isFloat }; + enum { isFundamental = isStdFundamental || isArith }; - typedef typename TypeSelect::Result>::Result - ParameterType; - }; + typedef typename TypeSelect::Result>::Result ParameterType; + }; } #ifdef _MSC_VER diff --git a/Modules/tests/Tests.cpp b/Modules/tests/Tests.cpp index 4e21c99..5910731 100644 --- a/Modules/tests/Tests.cpp +++ b/Modules/tests/Tests.cpp @@ -4,19 +4,19 @@ #include "Common.hpp" int main() { - tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleBase, nullptr }; - tp::ModuleManifest TestModule("Test", nullptr, nullptr, ModuleDependencies); + tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleBase, nullptr }; + tp::ModuleManifest TestModule("Test", nullptr, nullptr, ModuleDependencies); - if (!TestModule.initialize()) { - return 1; - } + if (!TestModule.initialize()) { + return 1; + } - ASSERT(tp::gEnvironment.mWidth == tp::Environment::ArchWidth::X64); + ASSERT(tp::gEnvironment.mWidth == tp::Environment::ArchWidth::X64); - ASSERT(tp::max(2, 1) == 2); - ASSERT(tp::max(-1, 0) == 0); - ASSERT(tp::max(0, -1) == 0); - ASSERT(tp::min(0, -1) == -1); + ASSERT(tp::max(2, 1) == 2); + ASSERT(tp::max(-1, 0) == 0); + ASSERT(tp::max(0, -1) == 0); + ASSERT(tp::min(0, -1) == -1); - TestModule.deinitialize(); + TestModule.deinitialize(); } \ No newline at end of file diff --git a/TODO b/TODO index 0019b2b..a3f28d1 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -Convert tabs to spaces - Containers: Avl read write ! Add check copy times ! diff --git a/Utils/private/Debugging.cpp b/Utils/private/Debugging.cpp index 7097e55..d0006c2 100644 --- a/Utils/private/Debugging.cpp +++ b/Utils/private/Debugging.cpp @@ -9,103 +9,103 @@ using namespace tp; CallStackCapture* tp::gCSCapture = nullptr; void initializeCallStackCapture() { - gCSCapture = new CallStackCapture(); + gCSCapture = new CallStackCapture(); } void deinitializeCallStackCapture() { - delete gCSCapture; + delete gCSCapture; } ualni CallStackCapture::CallStack::getDepth() const { - ualni len = 0; - for (long long frame : frames) { - if (!frame) { break; } - len++; - } - ualni stripedLen = 0; - for (auto i = FRAMES_TO_SKIP_START; i < len - FRAMES_TO_SKIP_END; i++) { - if (!frames[i]) { break; } - stripedLen++; - } - return stripedLen; + ualni len = 0; + for (long long frame : frames) { + if (!frame) { break; } + len++; + } + ualni stripedLen = 0; + for (auto i = FRAMES_TO_SKIP_START; i < len - FRAMES_TO_SKIP_END; i++) { + if (!frames[i]) { break; } + stripedLen++; + } + return stripedLen; } ualni CallStackCapture::hashCallStack(CallStackKey key) { - auto const cs = key.cs; - ualni out = 0; - for (ualni i = 0; cs->frames[i]; i++) { out += cs->frames[i]; } - return out; + auto const cs = key.cs; + ualni out = 0; + for (ualni i = 0; cs->frames[i]; i++) { out += cs->frames[i]; } + return out; } bool CallStackCapture::CallStackKey::operator==(const CallStackCapture::CallStackKey &in) const { - for (auto i : Range(MAX_CALL_DEPTH_CAPTURE)) { - if (cs->frames[i] != in.cs->frames[i]) { - return false; - } - if (cs->frames[i] == 0 && in.cs->frames[i] == 0) { - return true; - } - } - DEBUG_ASSERT(0 && "Must Not Happen") - return true; + for (auto i : Range(MAX_CALL_DEPTH_CAPTURE)) { + if (cs->frames[i] != in.cs->frames[i]) { + return false; + } + if (cs->frames[i] == 0 && in.cs->frames[i] == 0) { + return true; + } + } + DEBUG_ASSERT(0 && "Must Not Happen") + return true; } CallStackCapture::CallStackCapture() { - static_assert(MAX_CALL_DEPTH_CAPTURE >= 1); - static_assert(MAX_CALL_CAPTURES_MEM_SIZE_MB > 0); - static_assert(MAX_DEBUG_INFO_LEN > sizeof("unresolved")); - static_assert(FRAMES_TO_SKIP_END >= 0 && FRAMES_TO_SKIP_START >= 0); - static_assert(MAX_CALL_DEPTH_CAPTURE > FRAMES_TO_SKIP_START + FRAMES_TO_SKIP_END); - static_assert(MAX_CALL_CAPTURES_MEM_SIZE_MB * 1024 * 1024 > sizeof(CallStack)); + static_assert(MAX_CALL_DEPTH_CAPTURE >= 1); + static_assert(MAX_CALL_CAPTURES_MEM_SIZE_MB > 0); + static_assert(MAX_DEBUG_INFO_LEN > sizeof("unresolved")); + static_assert(FRAMES_TO_SKIP_END >= 0 && FRAMES_TO_SKIP_START >= 0); + static_assert(MAX_CALL_DEPTH_CAPTURE > FRAMES_TO_SKIP_START + FRAMES_TO_SKIP_END); + static_assert(MAX_CALL_CAPTURES_MEM_SIZE_MB * 1024 * 1024 > sizeof(CallStack)); - MODULE_SANITY_CHECK(gModuleUtils) - mBuffLoad = 0; - mBuffLen = (MAX_CALL_CAPTURES_MEM_SIZE_MB * 1024 * 1024) / sizeof(CallStack); - mBuff = (CallStack*) malloc(mBuffLen * sizeof(CallStack)); + MODULE_SANITY_CHECK(gModuleUtils) + mBuffLoad = 0; + mBuffLen = (MAX_CALL_CAPTURES_MEM_SIZE_MB * 1024 * 1024) / sizeof(CallStack); + mBuff = (CallStack*) malloc(mBuffLen * sizeof(CallStack)); } const CallStackCapture::CallStack* CallStackCapture::getSnapshot() { - if (mBuffLoad > mBuffLen) { - static CallStack cs; - cs.frames[0] = 0; - return &cs; - } + if (mBuffLoad > mBuffLen) { + static CallStack cs; + cs.frames[0] = 0; + return &cs; + } - CallStack* cs = &mBuff[mBuffLoad]; - platformWriteStackTrace(cs); + CallStack* cs = &mBuff[mBuffLoad]; + platformWriteStackTrace(cs); - auto idx = mSnapshots.presents({ cs }); - if (idx) { - return mSnapshots.getSlotVal(idx); - } + auto idx = mSnapshots.presents({ cs }); + if (idx) { + return mSnapshots.getSlotVal(idx); + } - mSnapshots.put({ cs }, cs); + mSnapshots.put({ cs }, cs); - mBuffLoad++; - return cs; + mBuffLoad++; + return cs; } const CallStackCapture::DebugSymbols* CallStackCapture::getSymbols(FramePointer frame) { - auto idx = mSymbols.presents(frame); - if (idx) { - return &mSymbols.getSlotVal(idx); - } + auto idx = mSymbols.presents(frame); + if (idx) { + return &mSymbols.getSlotVal(idx); + } - mSymbols.put(frame, {}); - auto symbols = &mSymbols.get(frame); + mSymbols.put(frame, {}); + auto symbols = &mSymbols.get(frame); - platformWriteDebugSymbols(frame, symbols); - return symbols; + platformWriteDebugSymbols(frame, symbols); + return symbols; } void CallStackCapture::clear() { - mBuffLoad = 0; - mSnapshots.removeAll(); - mSymbols.removeAll(); + mBuffLoad = 0; + mSnapshots.removeAll(); + mSymbols.removeAll(); } CallStackCapture::~CallStackCapture() { - free(mBuff); + free(mBuff); } // ---------------------------------- Platform Depended ---------------------------------- // @@ -118,90 +118,90 @@ CallStackCapture::~CallStackCapture() { #include void CallStackCapture::platformWriteStackTrace(CallStack* stack) { - auto depth = backtrace((void**)stack->frames, (int) MAX_CALL_DEPTH_CAPTURE - 1); - stack->frames[depth] = 0; + auto depth = backtrace((void**)stack->frames, (int) MAX_CALL_DEPTH_CAPTURE - 1); + stack->frames[depth] = 0; } static void getGetSourceFromBinaryAddress(const char* binary, const char* address, char* file, ualni* line) { - static char buff[1024]; + static char buff[1024]; - snprintf(buff, sizeof(buff), "addr2line -e %s -a %s", binary, address); - FILE* pipe = popen(buff, "r"); - if (pipe) { - fgets(buff, sizeof(buff), pipe); - fgets(buff, sizeof(buff), pipe); - pclose(pipe); - char* linePtr = strchr(buff, ':'); + snprintf(buff, sizeof(buff), "addr2line -e %s -a %s", binary, address); + FILE* pipe = popen(buff, "r"); + if (pipe) { + fgets(buff, sizeof(buff), pipe); + fgets(buff, sizeof(buff), pipe); + pclose(pipe); + char* linePtr = strchr(buff, ':'); - printf("%s\n", buff); + printf("%s\n", buff); - if (linePtr != nullptr && buff[0] != '?' && buff[1] != '?' && buff[2] != ':') { - *linePtr = '\0'; - auto sourceLen = std::strlen(buff); - std::strcpy(file, buff + ((sourceLen > MAX_DEBUG_INFO_LEN) ? (sourceLen - MAX_DEBUG_INFO_LEN) : 0)); - *line = strtoul(linePtr + 1, nullptr, 10); - return; - } - } + if (linePtr != nullptr && buff[0] != '?' && buff[1] != '?' && buff[2] != ':') { + *linePtr = '\0'; + auto sourceLen = std::strlen(buff); + std::strcpy(file, buff + ((sourceLen > MAX_DEBUG_INFO_LEN) ? (sourceLen - MAX_DEBUG_INFO_LEN) : 0)); + *line = strtoul(linePtr + 1, nullptr, 10); + return; + } + } - std::strcpy(file, "unresolved"); - *line = 0; + std::strcpy(file, "unresolved"); + *line = 0; } static void getDemangledName(const char* func, char* out) { - int status; - size_t funcDemangledSize = MAX_DEBUG_INFO_LEN; - char* funcDemangled = (char*)malloc(funcDemangledSize); - char* ret = abi::__cxa_demangle(func, funcDemangled, &funcDemangledSize, &status); - if (status == 0) { - funcDemangled = ret; - auto funcLen = std::strlen(funcDemangled); - std::strcpy(out, funcDemangled + ((funcLen > MAX_DEBUG_INFO_LEN) ? (funcLen - MAX_DEBUG_INFO_LEN) : 0)); - free(ret); - return; - } - auto funcLen = std::strlen(func); - std::strcpy(out, func + ((funcLen > MAX_DEBUG_INFO_LEN) ? (funcLen - MAX_DEBUG_INFO_LEN) : 0)); - free(funcDemangled); + int status; + size_t funcDemangledSize = MAX_DEBUG_INFO_LEN; + char* funcDemangled = (char*)malloc(funcDemangledSize); + char* ret = abi::__cxa_demangle(func, funcDemangled, &funcDemangledSize, &status); + if (status == 0) { + funcDemangled = ret; + auto funcLen = std::strlen(funcDemangled); + std::strcpy(out, funcDemangled + ((funcLen > MAX_DEBUG_INFO_LEN) ? (funcLen - MAX_DEBUG_INFO_LEN) : 0)); + free(ret); + return; + } + auto funcLen = std::strlen(func); + std::strcpy(out, func + ((funcLen > MAX_DEBUG_INFO_LEN) ? (funcLen - MAX_DEBUG_INFO_LEN) : 0)); + free(funcDemangled); } void CallStackCapture::platformWriteDebugSymbols(FramePointer frame, DebugSymbols* out) { - void* addrList[1] = { (void*) frame }; - auto symbolsArray = backtrace_symbols(addrList, 1); + void* addrList[1] = { (void*) frame }; + auto symbolsArray = backtrace_symbols(addrList, 1); - // 'bin(fun+addr)' - char* bin = *symbolsArray; - char* func = nullptr; - char* offset = nullptr; + // 'bin(fun+addr)' + char* bin = *symbolsArray; + char* func = nullptr; + char* offset = nullptr; - // 'bin fun+addr' - for (char *p = bin; *p; ++p) { - if (*p == '(') { *p = 0; func = p + 1; } - else if (*p == '+') { offset = p; } - else if (*p == ')' && offset) { *p = 0; } - } + // 'bin fun+addr' + for (char *p = bin; *p; ++p) { + if (*p == '(') { *p = 0; func = p + 1; } + else if (*p == '+') { offset = p; } + else if (*p == ')' && offset) { *p = 0; } + } - if (func && offset) { - getGetSourceFromBinaryAddress(bin, func, out->file, &out->line); + if (func && offset) { + getGetSourceFromBinaryAddress(bin, func, out->file, &out->line); - if (offset != func) { - *offset = 0; - getDemangledName(func, out->function); - } else { - std::strcpy(out->function, "unresolved"); - } - } else { - std::strcpy(out->file, "unresolved"); - std::strcpy(out->function, "unresolved"); - } + if (offset != func) { + *offset = 0; + getDemangledName(func, out->function); + } else { + std::strcpy(out->function, "unresolved"); + } + } else { + std::strcpy(out->file, "unresolved"); + std::strcpy(out->function, "unresolved"); + } - free(symbolsArray); + free(symbolsArray); } #else void CallStackCapture::platformWriteStackTrace(CallStack* stack) { stack->frames[0] = 0; } void CallStackCapture::platformWriteDebugSymbols(FramePointer frame, DebugSymbols* out) { - std::strcpy(out->file, "unresolved"); - std::strcpy(out->function, "unresolved"); + std::strcpy(out->file, "unresolved"); + std::strcpy(out->function, "unresolved"); } #endif \ No newline at end of file diff --git a/Utils/private/Testing.cpp b/Utils/private/Testing.cpp index ae5ed46..323ac07 100644 --- a/Utils/private/Testing.cpp +++ b/Utils/private/Testing.cpp @@ -10,72 +10,72 @@ using namespace tp; Testing tp::gTesting; void Testing::startTest(const char* name) { - MODULE_SANITY_CHECK(gModuleUtils) - mCurrent->mSubTests.pushBack(new TestingNode{ {}, {}, name, mCurrent }); - mCurrent = mCurrent->mSubTests.last()->data; + MODULE_SANITY_CHECK(gModuleUtils) + mCurrent->mSubTests.pushBack(new TestingNode{ {}, {}, name, mCurrent }); + mCurrent = mCurrent->mSubTests.last()->data; } void Testing::endTest() { - if (mCurrent->mParent) { - mCurrent = mCurrent->mParent; - } + if (mCurrent->mParent) { + mCurrent = mCurrent->mParent; + } } void Testing::addFailedCheck(const FailedCheck& info) { - DEBUG_BREAK(0 && info.expression); - auto lastRecord = &mCurrent->mFailedChecks.last()->data; - if (lastRecord && lastRecord->failedCheck.file == info.file && lastRecord->failedCheck.line == info.line) { - lastRecord->times++; - return; - } - mCurrent->mFailedChecks.pushBack({ info, 1 }); + DEBUG_BREAK(0 && info.expression); + auto lastRecord = &mCurrent->mFailedChecks.last()->data; + if (lastRecord && lastRecord->failedCheck.file == info.file && lastRecord->failedCheck.line == info.line) { + lastRecord->times++; + return; + } + mCurrent->mFailedChecks.pushBack({ info, 1 }); } void Testing::reportState() { - mRootTest.updateState(); + mRootTest.updateState(); - printf("\n"); - mRootTest.report(); + printf("\n"); + mRootTest.report(); } bool Testing::hasFailed() { - mRootTest.updateState(); - return mRootTest.mHasFailed; + mRootTest.updateState(); + return mRootTest.mHasFailed; } void Testing::setRootName(const char* name) { - mRootTest.mName = name; + mRootTest.mName = name; } void Testing::TestingNode::updateState() { - for (auto child : mSubTests) { - child->updateState(); - mHasFailed = child->mHasFailed; - if (mHasFailed) return; - } - mHasFailed = mFailedChecks.length(); + for (auto child : mSubTests) { + child->updateState(); + mHasFailed = child->mHasFailed; + if (mHasFailed) return; + } + mHasFailed = mFailedChecks.length(); } void Testing::TestingNode::report(const char* path) const { - if (!mHasFailed) { - return; - } + if (!mHasFailed) { + return; + } - auto newPath = path ? std::string(path) + "/" + mName : std::string(mName); + auto newPath = path ? std::string(path) + "/" + mName : std::string(mName); - for (auto check : mFailedChecks) { - auto failedCheck = &check.data().failedCheck; - auto times = check.data().times; - printf("%s Failed - (%s) %s:%llu x%i\n", newPath.c_str(), failedCheck->expression, failedCheck->file, failedCheck->line, (halni) times); - } + for (auto check : mFailedChecks) { + auto failedCheck = &check.data().failedCheck; + auto times = check.data().times; + printf("%s Failed - (%s) %s:%llu x%i\n", newPath.c_str(), failedCheck->expression, failedCheck->file, failedCheck->line, (halni) times); + } - for (const auto& child : mSubTests) { - child->report(newPath.c_str()); - } + for (const auto& child : mSubTests) { + child->report(newPath.c_str()); + } } Testing::TestingNode::~TestingNode() { - for (const auto& child : mSubTests) { - delete child.data(); - } + for (const auto& child : mSubTests) { + delete child.data(); + } } diff --git a/Utils/private/Timing.cpp b/Utils/private/Timing.cpp index cd02685..518a4f7 100644 --- a/Utils/private/Timing.cpp +++ b/Utils/private/Timing.cpp @@ -5,77 +5,73 @@ #include "Timing.hpp" #include "Utils.hpp" -#define GETTIMEMSC() \ - (time_ms)( \ - std::chrono::duration_cast( \ - std::chrono::time_point_cast(std::chrono::high_resolution_clock::now()) \ - .time_since_epoch()) \ - .count()) +#define GETTIMEMSC() (time_ms)\ + (std::chrono::duration_cast(std::chrono::time_point_cast(std::chrono::high_resolution_clock::now()).time_since_epoch()).count()) #define THREAD_SLEEP(time_ms) std::this_thread::sleep_for(std::chrono::milliseconds(time_ms)) tp::time_ms tp::gCurrentTime = tp::get_time(); namespace tp { - time_ms get_time() { - gCurrentTime = GETTIMEMSC(); - return gCurrentTime; - } + time_ms get_time() { + gCurrentTime = GETTIMEMSC(); + return gCurrentTime; + } - void sleep(time_ms mDuration) { - THREAD_SLEEP(mDuration); - } + void sleep(time_ms mDuration) { + THREAD_SLEEP(mDuration); + } - Timer::Timer() { - mDuration = 0; - mStart = GETTIMEMSC(); - } + Timer::Timer() { + mDuration = 0; + mStart = GETTIMEMSC(); + } - Timer::Timer(time_ms mDuration) { - mStart = GETTIMEMSC(); - this->mDuration = mDuration; - } + Timer::Timer(time_ms mDuration) { + mStart = GETTIMEMSC(); + this->mDuration = mDuration; + } - bool Timer::isTimeout() { - return mDuration < GETTIMEMSC() - mStart; - } + bool Timer::isTimeout() { + return mDuration < GETTIMEMSC() - mStart; + } - void Timer::reset() { - mStart = GETTIMEMSC(); - } + void Timer::reset() { + mStart = GETTIMEMSC(); + } - time_ms Timer::timePassed() { - return GETTIMEMSC() - mStart; - } + time_ms Timer::timePassed() { + return GETTIMEMSC() - mStart; + } - time_ms Timer::remainder() { - return mDuration - (GETTIMEMSC() - mStart); - } + time_ms Timer::remainder() { + return mDuration - (GETTIMEMSC() - mStart); + } - time_ms Timer::start() { return mStart; } - time_ms Timer::duration() { return mDuration; } - void Timer::setDuration(time_ms dur) { mDuration = dur; } + time_ms Timer::start() { return mStart; } + time_ms Timer::duration() { return mDuration; } + void Timer::setDuration(time_ms dur) { mDuration = dur; } - void Timer::wait() { - if (!isTimeout()) { - sleep(remainder()); - } - } + void Timer::wait() { + if (!isTimeout()) { + sleep(remainder()); + } + } - float Timer::easeIn(time_ms pDuration) { - if (!pDuration) { - pDuration = mDuration; - } - float x = (1.f / pDuration) * timePassed(); - return clamp((1.1f * x) / (x + 0.1f), 0.f, 1.f); - } + float Timer::easeIn(time_ms pDuration) { + if (!pDuration) { + pDuration = mDuration; + } + float x = (1.f / pDuration) * timePassed(); + return clamp((1.1f * x) / (x + 0.1f), 0.f, 1.f); + } - float Timer::easeOut(time_ms pDuration) { - if (!pDuration) { - pDuration = mDuration; - } - float x = (1.f / pDuration) * timePassed(); - return clamp((0.1f * (1 - x)) / (x + 0.1f), 0.f, 1.f); - } + float Timer::easeOut(time_ms pDuration) { + if (!pDuration) { + pDuration = mDuration; + } + float x = (1.f / pDuration) * timePassed(); + return clamp((0.1f * (1 - x)) / (x + 0.1f), 0.f, 1.f); + } } \ No newline at end of file diff --git a/Utils/private/Utils.cpp b/Utils/private/Utils.cpp index b330593..6dbef24 100644 --- a/Utils/private/Utils.cpp +++ b/Utils/private/Utils.cpp @@ -11,84 +11,84 @@ void initializeCallStackCapture(); void deinitializeCallStackCapture(); static bool initialize(const tp::ModuleManifest* self) { - initializeCallStackCapture(); - return true; + initializeCallStackCapture(); + return true; } static void deinitialize(const tp::ModuleManifest* self) { - deinitializeCallStackCapture(); - tp::gTesting.reportState(); - if (tp::gTesting.hasFailed()) { exit(1); } + deinitializeCallStackCapture(); + tp::gTesting.reportState(); + if (tp::gTesting.hasFailed()) { exit(1); } } namespace tp { - static ModuleManifest* sModuleUtilsDeps[] = { &gModuleContainers, nullptr }; - ModuleManifest gModuleUtils = ModuleManifest("Utils", initialize, deinitialize, sModuleUtilsDeps); + static ModuleManifest* sModuleUtilsDeps[] = { &gModuleContainers, nullptr }; + ModuleManifest gModuleUtils = ModuleManifest("Utils", initialize, deinitialize, sModuleUtilsDeps); - void memsetv(void* p, uhalni bytesize, uint1 val) { - MODULE_SANITY_CHECK(gModuleBase) + void memsetv(void* p, uhalni bytesize, uint1 val) { + MODULE_SANITY_CHECK(gModuleBase) - alni alignedval = 0; - for (ualni idx = 0; idx < sizeof(alni); idx++) { - ((uint1*) &alignedval)[idx] = val; - } + alni alignedval = 0; + for (ualni idx = 0; idx < sizeof(alni); idx++) { + ((uint1*) &alignedval)[idx] = val; + } - ualni alignedlen = bytesize / sizeof(alni); - for (ualni idx = 0; idx < alignedlen; idx++) { - ((alni*) p)[idx] = alignedval; - } + ualni alignedlen = bytesize / sizeof(alni); + for (ualni idx = 0; idx < alignedlen; idx++) { + ((alni*) p)[idx] = alignedval; + } - ualni unalignedlen = bytesize - (alignedlen * sizeof(alni)); - for (ualni idx = 0; idx < unalignedlen; idx++) { - ((uint1*) p)[bytesize - idx - 1] = val; - } - } + ualni unalignedlen = bytesize - (alignedlen * sizeof(alni)); + for (ualni idx = 0; idx < unalignedlen; idx++) { + ((uint1*) p)[bytesize - idx - 1] = val; + } + } - void memcp(void* left, const void* right, uhalni len) { - MODULE_SANITY_CHECK(gModuleBase) + void memcp(void* left, const void* right, uhalni len) { + MODULE_SANITY_CHECK(gModuleBase) - ualni alignedlen = len / sizeof(alni); - for (ualni idx = 0; idx < alignedlen; idx++) { - ((alni*) left)[idx] = ((alni*) right)[idx]; - } + ualni alignedlen = len / sizeof(alni); + for (ualni idx = 0; idx < alignedlen; idx++) { + ((alni*) left)[idx] = ((alni*) right)[idx]; + } - ualni unalignedlen = len - (alignedlen * sizeof(alni)); - for (ualni idx = 0; idx < unalignedlen; idx++) { - ((uint1*) left)[len - idx - 1] = ((uint1*) right)[len - idx - 1]; - } - } + ualni unalignedlen = len - (alignedlen * sizeof(alni)); + for (ualni idx = 0; idx < unalignedlen; idx++) { + ((uint1*) left)[len - idx - 1] = ((uint1*) right)[len - idx - 1]; + } + } - int1 memecomp(const void* left, const void* right, uhalni len) { - MODULE_SANITY_CHECK(gModuleBase) - if (!len) return 0; + int1 memecomp(const void* left, const void* right, uhalni len) { + MODULE_SANITY_CHECK(gModuleBase) + if (!len) return 0; - ualni alignedLength = len / sizeof(alni); - for (ualni idx = 0; idx < alignedLength; idx++) { - if (((alni*) left)[idx] == ((alni*) right)[idx]) { - continue; - } - if (((alni*) left)[idx] > ((alni*) right)[idx]) { - return 1; - } - return -1; - } + ualni alignedLength = len / sizeof(alni); + for (ualni idx = 0; idx < alignedLength; idx++) { + if (((alni*) left)[idx] == ((alni*) right)[idx]) { + continue; + } + if (((alni*) left)[idx] > ((alni*) right)[idx]) { + return 1; + } + return -1; + } - ualni unalignedLength = len - (alignedLength * sizeof(alni)); - for (ualni idx = 0; idx < unalignedLength; idx++) { - if (((uint1*) left)[len - idx - 1] == ((uint1*) right)[len - idx - 1]) { - continue; - } - if (((uint1*) left)[len - idx - 1] > ((uint1*) right)[len - idx - 1]) { - return 1; - } - return -1; - } - return 0; - } + ualni unalignedLength = len - (alignedLength * sizeof(alni)); + for (ualni idx = 0; idx < unalignedLength; idx++) { + if (((uint1*) left)[len - idx - 1] == ((uint1*) right)[len - idx - 1]) { + continue; + } + if (((uint1*) left)[len - idx - 1] > ((uint1*) right)[len - idx - 1]) { + return 1; + } + return -1; + } + return 0; + } - alnf randf() { - alnf r = static_cast(std::rand()) / static_cast(RAND_MAX); - return r; - } + alnf randf() { + alnf r = static_cast(std::rand()) / static_cast(RAND_MAX); + return r; + } } \ No newline at end of file diff --git a/Utils/public/Debugging.hpp b/Utils/public/Debugging.hpp index ef128af..b669fa3 100644 --- a/Utils/public/Debugging.hpp +++ b/Utils/public/Debugging.hpp @@ -12,110 +12,110 @@ namespace tp { class CallStackCapture { - public: - typedef tp::alni FramePointer; + public: + typedef tp::alni FramePointer; - class CallStack { - friend CallStackCapture; - FramePointer frames[MAX_CALL_DEPTH_CAPTURE]; + class CallStack { + friend CallStackCapture; + FramePointer frames[MAX_CALL_DEPTH_CAPTURE]; - public: - [[nodiscard]] ualni getDepth() const; + public: + [[nodiscard]] ualni getDepth() const; - class Iterator { - const FramePointer* mFrame; - public: - explicit Iterator(const FramePointer* frame) : mFrame(frame) {}; - FramePointer getFrame() { return *mFrame; } - bool operator==(const Iterator& in) const { return in.mFrame == mFrame; } - void operator++() { mFrame++; } - const Iterator& operator*() const { return *this; } - }; + class Iterator { + const FramePointer* mFrame; + public: + explicit Iterator(const FramePointer* frame) : mFrame(frame) {}; + FramePointer getFrame() { return *mFrame; } + bool operator==(const Iterator& in) const { return in.mFrame == mFrame; } + void operator++() { mFrame++; } + const Iterator& operator*() const { return *this; } + }; - [[nodiscard]] Iterator begin() const { return Iterator(frames + FRAMES_TO_SKIP_START); } - [[nodiscard]] Iterator end() const { return Iterator(frames + FRAMES_TO_SKIP_START + getDepth()); } - }; + [[nodiscard]] Iterator begin() const { return Iterator(frames + FRAMES_TO_SKIP_START); } + [[nodiscard]] Iterator end() const { return Iterator(frames + FRAMES_TO_SKIP_START + getDepth()); } + }; - class DebugSymbols { - friend CallStackCapture; - char function[MAX_DEBUG_INFO_LEN + 1] = { 0 }; - char file[MAX_DEBUG_INFO_LEN + 1] = { 0 }; - ualni line = 0; - public: - [[nodiscard]] const char* getFunc() const { return function; } - [[nodiscard]] const char* getFile() const { return file; } - [[nodiscard]] ualni getLine() const { return line; } - }; + class DebugSymbols { + friend CallStackCapture; + char function[MAX_DEBUG_INFO_LEN + 1] = { 0 }; + char file[MAX_DEBUG_INFO_LEN + 1] = { 0 }; + ualni line = 0; + public: + [[nodiscard]] const char* getFunc() const { return function; } + [[nodiscard]] const char* getFile() const { return file; } + [[nodiscard]] ualni getLine() const { return line; } + }; - public: - CallStackCapture(); - ~CallStackCapture(); + public: + CallStackCapture(); + ~CallStackCapture(); - [[nodiscard]] const CallStack* getSnapshot(); - const DebugSymbols* getSymbols(FramePointer fp); + [[nodiscard]] const CallStack* getSnapshot(); + const DebugSymbols* getSymbols(FramePointer fp); - public: + public: - template - void write(Saver& file) { - file.write(mBuffLoad); - for (auto cs : *this) { - file.write(cs.getCallStack()->getDepth()); - for (auto frame : *cs.getCallStack()) { - file.write((ualni) frame.getFrame()); - } - } - file.write(mSymbols); - } + template + void write(Saver& file) { + file.write(mBuffLoad); + for (auto cs : *this) { + file.write(cs.getCallStack()->getDepth()); + for (auto frame : *cs.getCallStack()) { + file.write((ualni) frame.getFrame()); + } + } + file.write(mSymbols); + } - // independent of the configuration - template - void read(Loader& file) { - clear(); - ualni loadLen; - file.read(loadLen); - for (auto cs = loadLen; cs; cs--) { - ualni callStackLen; - file.read(callStackLen); - for (auto fp = callStackLen; fp; fp--) { - // -- - } - } - } + // independent of the configuration + template + void read(Loader& file) { + clear(); + ualni loadLen; + file.read(loadLen); + for (auto cs = loadLen; cs; cs--) { + ualni callStackLen; + file.read(callStackLen); + for (auto fp = callStackLen; fp; fp--) { + // -- + } + } + } - public: - class Iterator { - const CallStack* mSnapshot; - public: - explicit Iterator(const CallStack* start) : mSnapshot(start) {}; - const CallStack* getCallStack() { return mSnapshot; } - bool operator==(const Iterator& in) const { return in.mSnapshot == mSnapshot; } - void operator++() { mSnapshot++; } - const Iterator& operator*() const { return *this; } - }; + public: + class Iterator { + const CallStack* mSnapshot; + public: + explicit Iterator(const CallStack* start) : mSnapshot(start) {}; + const CallStack* getCallStack() { return mSnapshot; } + bool operator==(const Iterator& in) const { return in.mSnapshot == mSnapshot; } + void operator++() { mSnapshot++; } + const Iterator& operator*() const { return *this; } + }; - [[nodiscard]] Iterator begin() const { return Iterator(mBuff); } - [[nodiscard]] Iterator end() const { return Iterator(mBuff + mBuffLoad); } + [[nodiscard]] Iterator begin() const { return Iterator(mBuff); } + [[nodiscard]] Iterator end() const { return Iterator(mBuff + mBuffLoad); } - private: + private: - struct CallStackKey { - CallStack* cs; - bool operator==(const CallStackKey& in) const; - }; + struct CallStackKey { + CallStack* cs; + bool operator==(const CallStackKey& in) const; + }; - static void platformWriteStackTrace(CallStack* stack); - static void platformWriteDebugSymbols(FramePointer frame, DebugSymbols* out); - [[nodiscard]] static ualni hashCallStack(CallStackKey key); + static void platformWriteStackTrace(CallStack* stack); + static void platformWriteDebugSymbols(FramePointer frame, DebugSymbols* out); + [[nodiscard]] static ualni hashCallStack(CallStackKey key); - void clear(); + void clear(); - private: - ualni mBuffLen; - ualni mBuffLoad; - CallStack* mBuff; - Map mSnapshots; - Map mSymbols; + private: + ualni mBuffLen; + ualni mBuffLoad; + CallStack* mBuff; + Map mSnapshots; + Map mSymbols; }; extern CallStackCapture* gCSCapture; diff --git a/Utils/public/Sorting.hpp b/Utils/public/Sorting.hpp index c166674..70e602f 100644 --- a/Utils/public/Sorting.hpp +++ b/Utils/public/Sorting.hpp @@ -41,23 +41,23 @@ namespace tp { while (i < n1 && j < n2) { if (!(grater(Left[i], Right[j]))) { - buff[k] = Left[i]; + buff[k] = Left[i]; i++; } else { - buff[k] = Right[j]; + buff[k] = Right[j]; j++; } k++; } while (i < n1) { - buff[k] = Left[i]; + buff[k] = Left[i]; i++; k++; } while (j < n2) { - buff[k] = Right[j]; + buff[k] = Right[j]; j++; k++; } diff --git a/Utils/public/Testing.hpp b/Utils/public/Testing.hpp index d6e59b8..c8c1c1c 100644 --- a/Utils/public/Testing.hpp +++ b/Utils/public/Testing.hpp @@ -4,61 +4,61 @@ #include "List.hpp" namespace tp { - class Testing { - public: + class Testing { + public: - struct FailedCheck { - const char* expression = nullptr; - const char* file = nullptr; - ualni line = 0; - }; + struct FailedCheck { + const char* expression = nullptr; + const char* file = nullptr; + ualni line = 0; + }; - Testing() = default; - void startTest(const char* name); - void endTest(); - void addFailedCheck(const FailedCheck& info); - void reportState(); - void setRootName(const char* name); - [[nodiscard]] bool hasFailed(); + Testing() = default; + void startTest(const char* name); + void endTest(); + void addFailedCheck(const FailedCheck& info); + void reportState(); + void setRootName(const char* name); + [[nodiscard]] bool hasFailed(); - private: - struct TestingNode { - struct FailedCheckRecord { FailedCheck failedCheck; ualni times; }; - List mFailedChecks; - List mSubTests; - const char* mName = "Unnamed"; - TestingNode* mParent = nullptr; - bool mHasFailed = false; + private: + struct TestingNode { + struct FailedCheckRecord { FailedCheck failedCheck; ualni times; }; + List mFailedChecks; + List mSubTests; + const char* mName = "Unnamed"; + TestingNode* mParent = nullptr; + bool mHasFailed = false; - void report(const char* path = nullptr) const; - void updateState(); - ~TestingNode(); - }; + void report(const char* path = nullptr) const; + void updateState(); + ~TestingNode(); + }; - TestingNode mRootTest; - TestingNode* mCurrent = &mRootTest; - }; + TestingNode mRootTest; + TestingNode* mCurrent = &mRootTest; + }; - extern Testing gTesting; + extern Testing gTesting; } #define TEST_DEF(Name)\ - static void Name##FunctorBody();\ - void test##Name() { \ - tp::gTesting.startTest(#Name);\ - Name##FunctorBody();\ - tp::gTesting.endTest();\ - } \ - void Name##FunctorBody() + static void Name##FunctorBody();\ + void test##Name() { \ + tp::gTesting.startTest(#Name);\ + Name##FunctorBody();\ + tp::gTesting.endTest();\ + } \ + void Name##FunctorBody() #define TEST_DEF_STATIC(Name)\ - static void Name##FunctorBody();\ - static void test##Name() { \ - tp::gTesting.startTest(#Name);\ - Name##FunctorBody();\ - tp::gTesting.endTest();\ - } \ - void Name##FunctorBody() + static void Name##FunctorBody();\ + static void test##Name() { \ + tp::gTesting.startTest(#Name);\ + Name##FunctorBody();\ + tp::gTesting.endTest();\ + } \ + void Name##FunctorBody() #define TEST(expr) if (!(expr)) tp::gTesting.addFailedCheck({ #expr, __FILE__, __LINE__ }) #define TEST_EQUAL(l, r) if (!((l) == (r))) tp::gTesting.addFailedCheck({ #l" == "#r, __FILE__, __LINE__ }) diff --git a/Utils/public/Timing.hpp b/Utils/public/Timing.hpp index d58c4d6..f37f1f1 100644 --- a/Utils/public/Timing.hpp +++ b/Utils/public/Timing.hpp @@ -4,55 +4,55 @@ namespace tp { - typedef alni time_ms; - typedef alni time_ns; + typedef alni time_ms; + typedef alni time_ns; - extern time_ms gCurrentTime; + extern time_ms gCurrentTime; - class Timer { + class Timer { - time_ms mStart; - time_ms mDuration; + time_ms mStart; + time_ms mDuration; - public: + public: - Timer(); - explicit Timer(time_ms time); + Timer(); + explicit Timer(time_ms time); - time_ms start(); - time_ms duration(); - void setDuration(time_ms dur); + time_ms start(); + time_ms duration(); + void setDuration(time_ms dur); - bool isTimeout(); - void reset(); - time_ms timePassed(); - time_ms remainder(); - void wait(); + bool isTimeout(); + void reset(); + time_ms timePassed(); + time_ms remainder(); + void wait(); - float easeIn(time_ms duration = 0); - float easeOut(time_ms duration = 0); - }; + float easeIn(time_ms duration = 0); + float easeOut(time_ms duration = 0); + }; - void sleep(time_ms duration); - time_ms get_time(); + void sleep(time_ms duration); + time_ms get_time(); - struct FpsCounter { - halni frames = 0; - Timer time; - halni fps = 0; + struct FpsCounter { + halni frames = 0; + Timer time; + halni fps = 0; - FpsCounter() : time(1000) {} + FpsCounter() : time(1000) {} - void update(bool log = true) { - frames++; - if (time.isTimeout()) { - fps = frames; - if (log) { - // printf("fps %i \n", fps); - } - frames = 0; - time.reset(); - } - } - }; + void update(bool log = true) { + frames++; + if (time.isTimeout()) { + fps = frames; + if (log) { + // printf("fps %i \n", fps); + } + frames = 0; + time.reset(); + } + } + }; } \ No newline at end of file diff --git a/Utils/public/Utils.hpp b/Utils/public/Utils.hpp index 9860f63..79f9935 100644 --- a/Utils/public/Utils.hpp +++ b/Utils/public/Utils.hpp @@ -7,73 +7,73 @@ namespace tp { - extern ModuleManifest gModuleUtils; + extern ModuleManifest gModuleUtils; - void memsetv(void* p, uhalni bytesize, uint1 val); - void memcp(void* left, const void* right, uhalni len); - int1 memequal(const void* left, const void* right, uhalni len); + void memsetv(void* p, uhalni bytesize, uint1 val); + void memcp(void* left, const void* right, uhalni len); + int1 memequal(const void* left, const void* right, uhalni len); } namespace tp { - [[nodiscard]] alnf randf(); + [[nodiscard]] alnf randf(); } namespace tp { - template - class Pair { - public: - Pair() {} - Pair(T1 t1, T2 t2) : head(t1), tail(t2) {} - union { T1 t1; T1 head; T1 x; }; - union { T2 t2; T2 tail; T2 y; }; - }; + template + class Pair { + public: + Pair() {} + Pair(T1 t1, T2 t2) : head(t1), tail(t2) {} + union { T1 t1; T1 head; T1 x; }; + union { T2 t2; T2 tail; T2 y; }; + }; - template - class Bits { - Type mFlags = 0; - public: - Bits() = default; - explicit Bits(Type val) { mFlags = val; } - explicit Bits(bool val) { for (int bit = 0; bit < sizeof(Type); bit++) { set(bit, val); } } - bool get(int1 idx) { return mFlags & (1l << idx); } - void set(int1 idx, bool val) { - if (val) { - mFlags |= (1l << idx); - } else { - mFlags &= ~(1l << idx); - } - } - }; + template + class Bits { + Type mFlags = 0; + public: + Bits() = default; + explicit Bits(Type val) { mFlags = val; } + explicit Bits(bool val) { for (int bit = 0; bit < sizeof(Type); bit++) { set(bit, val); } } + bool get(int1 idx) { return mFlags & (1l << idx); } + void set(int1 idx, bool val) { + if (val) { + mFlags |= (1l << idx); + } else { + mFlags &= ~(1l << idx); + } + } + }; - template - class Range { - public: - class Iterator { - public: - tType mIndex; - explicit Iterator(tType pStartIndex) : mIndex(pStartIndex) {} - tType index() const { return mIndex; } - inline void operator++() { mIndex++; } - inline operator tType() const { return mIndex; } - inline bool operator==(Iterator pIndex) { return mIndex == pIndex.mIndex; } - inline bool operator!=(Iterator pIndex) { return mIndex != pIndex.mIndex; } - inline const Iterator& operator*() { return *this; } - }; + template + class Range { + public: + class Iterator { + public: + tType mIndex; + explicit Iterator(tType pStartIndex) : mIndex(pStartIndex) {} + tType index() const { return mIndex; } + inline void operator++() { mIndex++; } + inline operator tType() const { return mIndex; } + inline bool operator==(Iterator pIndex) { return mIndex == pIndex.mIndex; } + inline bool operator!=(Iterator pIndex) { return mIndex != pIndex.mIndex; } + inline const Iterator& operator*() { return *this; } + }; - tType mBegin = 0; - tType mEnd = 0; + tType mBegin = 0; + tType mEnd = 0; - Range() = default; - explicit Range(tType pEndIndex) : mBegin(0), mEnd(pEndIndex) {} - Range(tType pStartIndex, tType pEndIndex) : mBegin(pStartIndex), mEnd(pEndIndex) {} + Range() = default; + explicit Range(tType pEndIndex) : mBegin(0), mEnd(pEndIndex) {} + Range(tType pStartIndex, tType pEndIndex) : mBegin(pStartIndex), mEnd(pEndIndex) {} - bool valid() { return mBegin < mEnd; } + bool valid() { return mBegin < mEnd; } - tType idxBegin() const { return mBegin; } - tType idxEnd() const { return mEnd; } - Iterator begin() { return Iterator(mBegin); } - Iterator end() { return Iterator(mEnd); } - }; + tType idxBegin() const { return mBegin; } + tType idxEnd() const { return mEnd; } + Iterator begin() { return Iterator(mBegin); } + Iterator end() { return Iterator(mEnd); } + }; } \ No newline at end of file diff --git a/Utils/tests/Tests.cpp b/Utils/tests/Tests.cpp index d8b022a..9073e53 100644 --- a/Utils/tests/Tests.cpp +++ b/Utils/tests/Tests.cpp @@ -8,60 +8,60 @@ using namespace tp; void printSnapshot(const tp::CallStackCapture::CallStack* snapshot) { - printf("CallStack: \n"); - for (auto frame : *snapshot) { - auto symbols = gCSCapture->getSymbols(frame.getFrame()); - printf(" %s ----- %s:%llu\n", symbols->getFunc(), symbols->getFile(), symbols->getLine()); - } - printf("\n"); + printf("CallStack: \n"); + for (auto frame : *snapshot) { + auto symbols = gCSCapture->getSymbols(frame.getFrame()); + printf(" %s ----- %s:%llu\n", symbols->getFunc(), symbols->getFile(), symbols->getLine()); + } + printf("\n"); } void common() { - gCSCapture->getSnapshot(); + gCSCapture->getSnapshot(); } void first() { - common(); - common(); - common(); + common(); + common(); + common(); } void second() { - common(); - common(); - common(); - common(); + common(); + common(); + common(); + common(); } void third() { - common(); - common(); + common(); + common(); } void root() { - first(); - second(); - third(); + first(); + second(); + third(); } TEST_DEF(Debugging) { - root(); + root(); - for (auto cs : *gCSCapture) { - printSnapshot(cs.getCallStack()); - } + for (auto cs : *gCSCapture) { + printSnapshot(cs.getCallStack()); + } } int main() { - tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; - tp::ModuleManifest testModule("UtilsTest", nullptr, nullptr, deps); + tp::ModuleManifest* deps[] = { &tp::gModuleUtils, nullptr }; + tp::ModuleManifest testModule("UtilsTest", nullptr, nullptr, deps); - if (!testModule.initialize()) { - return 1; - } + if (!testModule.initialize()) { + return 1; + } - testDebugging(); + testDebugging(); - testModule.deinitialize(); + testModule.deinitialize(); } \ No newline at end of file