From 40d02748924aa7c48b04cf948204d8dacdfbbc74 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 30 Apr 2022 16:28:13 +0200 Subject: refactor: replace DI files with the yacppdic library --- src/CMakeLists.txt | 12 +- src/DI/alloc_functor.hpp | 84 -------------- src/DI/alloc_functor.tpp | 179 ----------------------------- src/DI/allocation.hpp | 32 ------ src/DI/allocation.tpp | 18 --- src/DI/auto_wirable.hpp | 15 --- src/DI/auto_wirable.tpp | 11 -- src/DI/compressed_pair.hpp | 200 --------------------------------- src/DI/concepts.hpp | 11 -- src/DI/container.cpp | 9 -- src/DI/container.hpp | 60 ---------- src/DI/container.tpp | 82 -------------- src/DI/copyable_functor.hpp | 47 -------- src/DI/copyable_functor.tpp | 107 ------------------ src/DI/extra_concepts.hpp | 6 - src/DI/factory.hpp | 192 ------------------------------- src/DI/factory.tpp | 65 ----------- src/DI/function_wrapper.hpp | 20 ---- src/DI/function_wrapper.tpp | 17 --- src/DI/interfaces/copyable_functor.hpp | 41 ------- src/DI/interfaces/wrapper.hpp | 17 --- src/DI/object_type.cpp | 27 ----- src/DI/object_type.hpp | 32 ------ src/DI/object_wrapper.hpp | 20 ---- src/DI/object_wrapper.tpp | 10 -- src/DI/strip_signature.hpp | 103 ----------------- src/DI/type_traits.hpp | 18 --- src/DI/value_functor.hpp | 65 ----------- src/DI/value_functor.tpp | 191 ------------------------------- src/argument_parser.hpp | 6 +- src/bootstrap.cpp | 6 +- src/bootstrap.hpp | 4 +- src/engine/engine.hpp | 5 +- src/engine/graphics/window.hpp | 5 +- src/engine/user/cursor.hpp | 5 +- src/engine/user/input.hpp | 6 +- src/interfaces/game.hpp | 4 +- src/interfaces/generation_tracker.hpp | 4 +- src/interfaces/matrix.hpp | 6 +- src/interfaces/randomization.hpp | 4 +- src/interfaces/scene.hpp | 4 +- src/interfaces/status_updater.hpp | 5 +- src/interfaces/statusline.hpp | 4 +- src/randomization/seed_generator.hpp | 5 +- 44 files changed, 50 insertions(+), 1714 deletions(-) delete mode 100644 src/DI/alloc_functor.hpp delete mode 100644 src/DI/alloc_functor.tpp delete mode 100644 src/DI/allocation.hpp delete mode 100644 src/DI/allocation.tpp delete mode 100644 src/DI/auto_wirable.hpp delete mode 100644 src/DI/auto_wirable.tpp delete mode 100644 src/DI/compressed_pair.hpp delete mode 100644 src/DI/concepts.hpp delete mode 100644 src/DI/container.cpp delete mode 100644 src/DI/container.hpp delete mode 100644 src/DI/container.tpp delete mode 100644 src/DI/copyable_functor.hpp delete mode 100644 src/DI/copyable_functor.tpp delete mode 100644 src/DI/extra_concepts.hpp delete mode 100644 src/DI/factory.hpp delete mode 100644 src/DI/factory.tpp delete mode 100644 src/DI/function_wrapper.hpp delete mode 100644 src/DI/function_wrapper.tpp delete mode 100644 src/DI/interfaces/copyable_functor.hpp delete mode 100644 src/DI/interfaces/wrapper.hpp delete mode 100644 src/DI/object_type.cpp delete mode 100644 src/DI/object_type.hpp delete mode 100644 src/DI/object_wrapper.hpp delete mode 100644 src/DI/object_wrapper.tpp delete mode 100644 src/DI/strip_signature.hpp delete mode 100644 src/DI/type_traits.hpp delete mode 100644 src/DI/value_functor.hpp delete mode 100644 src/DI/value_functor.tpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 679949b..92ce76b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,7 +51,7 @@ target_compile_options( -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch-default -Wundef -Werror - -pedantic -fsanitize=address -fno-exceptions -stdlib=libc++ + -pedantic -fsanitize=address -fno-exceptions ) if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") @@ -64,6 +64,12 @@ endif() target_include_directories(${PROJECT_NAME} PRIVATE .) -target_link_libraries_system(${PROJECT_NAME} ctre fmt::fmt-header-only GSL) +target_link_libraries_system( + ${PROJECT_NAME} + ctre + fmt::fmt-header-only + GSL + yacppdic +) -target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address -stdlib=libc++) +target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=address) diff --git a/src/DI/alloc_functor.hpp b/src/DI/alloc_functor.hpp deleted file mode 100644 index ea40b22..0000000 --- a/src/DI/alloc_functor.hpp +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#include "DI/allocation.hpp" -#include "DI/compressed_pair.hpp" - -#include -#include -#include - -template -struct InvokeReturnWrapper -{ - template - static auto call(Args &&...args) -> Return; -}; - -/** - * Holds a functor and a allocator. - */ -template -class AllocFunctor; - -template -class AllocFunctor -{ -public: - using Target = Function; - using Alloc = Allocator; - - explicit AllocFunctor(Target &&function); - - explicit AllocFunctor(const Target &function, const Alloc &allocator); - - explicit AllocFunctor(const Target &function, Alloc &&allocator); - - explicit AllocFunctor(Target &&function, Alloc &&allocator); - - auto operator()(Args &&...args) -> Return; - - [[nodiscard]] auto target() const -> const Target &; - - [[nodiscard]] auto get_allocator() const -> const Alloc &; - - [[nodiscard]] auto clone() const -> AllocFunctor *; - - void destroy() noexcept; - - static void destroy_and_delete(AllocFunctor *functor); - -private: - CompressedPair _function; -}; - -/** - * Holds a functor and a allocator. - */ -template -class DefaultAllocFunctor; - -template -class DefaultAllocFunctor -{ -public: - using Target = Function; - - explicit DefaultAllocFunctor(Target &&function); - - explicit DefaultAllocFunctor(const Target &function); - - auto operator()(Args &&...args) -> Return; - - auto target() const -> const Target &; - - auto clone() const -> DefaultAllocFunctor *; - - void destroy() noexcept; - - static void destroy_and_delete(DefaultAllocFunctor *function); - -private: - Function _function; -}; - -#include "alloc_functor.tpp" diff --git a/src/DI/alloc_functor.tpp b/src/DI/alloc_functor.tpp deleted file mode 100644 index 9611a3d..0000000 --- a/src/DI/alloc_functor.tpp +++ /dev/null @@ -1,179 +0,0 @@ -#pragma once - -#include "alloc_functor.hpp" - -template -template -auto InvokeReturnWrapper::call(Args &&...args) -> Return -{ - return std::invoke(std::forward(args)...); -} - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define ALLOC_FUNCTOR_TEMPLATE \ - template - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define ALLOC_FUNCTOR AllocFunctor - -ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(Target &&function) - : _function( - std::piecewise_construct, - std::forward_as_tuple(std::move(function)), - std::forward_as_tuple() - ) -{ -} - -ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(const Target &function, const Alloc &allocator) - : _function( - std::piecewise_construct, - std::forward_as_tuple(function), - std::forward_as_tuple(allocator) - ) -{ -} - -ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(const Target &function, Alloc &&allocator) - : _function( - std::piecewise_construct, - std::forward_as_tuple(function), - std::forward_as_tuple(std::move(allocator)) - ) -{ -} - -ALLOC_FUNCTOR_TEMPLATE -ALLOC_FUNCTOR::AllocFunctor(Target &&function, Alloc &&allocator) - : _function( - std::piecewise_construct, - std::forward_as_tuple(std::move(function)), - std::forward_as_tuple(std::move(allocator)) - ) -{ -} - -ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::operator()(Args &&...args) -> Return -{ - using Invoker = InvokeReturnWrapper; - - return Invoker::call(_function.first(), std::forward(args)...); -} - -ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::target() const -> const Target & -{ - return _function.first(); -} - -ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::get_allocator() const -> const Alloc & -{ - return _function.second(); -} - -ALLOC_FUNCTOR_TEMPLATE -auto ALLOC_FUNCTOR::clone() const -> AllocFunctor * -{ - using AllocTraits = std::allocator_traits; - - using AllocHelper = typename RebindAllocHelper::type; - - auto alloc_helper = AllocHelper(_function.second()); - - using Destructor = AllocDestructor; - - auto hold = std::unique_ptr( - alloc_helper.allocate(1), - _Dp(alloc_helper, 1) - ); - - ::new (static_cast(hold.get())) - AllocFunctor(_function.first(), _Alloc(alloc_helper)); - - return hold.release(); -} - -ALLOC_FUNCTOR_TEMPLATE -void ALLOC_FUNCTOR::destroy() noexcept -{ - _function.~CompressedPair(); -} - -ALLOC_FUNCTOR_TEMPLATE -void ALLOC_FUNCTOR::destroy_and_delete(AllocFunctor *functor) -{ - using AllocTraits = std::allocator_traits; - - using FunctorAlloc = typename RebindAllocHelper::type; - - auto functor_alloc = FunctorAlloc(functor->get_allocator()); - - functor->destroy(); - functor_alloc.deallocate(functor, 1); -} - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DEFAULT_ALLOC_FUNCTOR_TEMPLATE \ - template - -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define DEFAULT_ALLOC_FUNCTOR DefaultAllocFunctor - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -DEFAULT_ALLOC_FUNCTOR::DefaultAllocFunctor(Target &&function) - : _function(std::move(function)) -{ -} - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -DEFAULT_ALLOC_FUNCTOR::DefaultAllocFunctor(const Target &function) : _function(function) -{ -} - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -auto DEFAULT_ALLOC_FUNCTOR::operator()(Args &&...args) -> Return -{ - using Invoker = InvokeReturnWrapper; - - return Invoker::call(_function, std::forward(args)...); -} - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -auto DEFAULT_ALLOC_FUNCTOR::target() const -> const Target & -{ - return _function; -} - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -auto DEFAULT_ALLOC_FUNCTOR::clone() const -> DefaultAllocFunctor * -{ - std::allocator allocator; - - DefaultAllocFunctor *functor_ptr = allocator.allocate(1); - - // NOLINTNEXTLINE(cppcoreguidelines-owning-memory) - auto *res = ::new (static_cast(functor_ptr)) DefaultAllocFunctor(_function); - - return res; -} - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -void DEFAULT_ALLOC_FUNCTOR::destroy() noexcept -{ - _function.~_Target(); -} - -DEFAULT_ALLOC_FUNCTOR_TEMPLATE -void DEFAULT_ALLOC_FUNCTOR::destroy_and_delete(DefaultAllocFunctor *function) -{ - function->destroy(); - - std::allocator allocator; - - allocator.deallocate(function, 1); -} diff --git a/src/DI/allocation.hpp b/src/DI/allocation.hpp deleted file mode 100644 index ac0fa38..0000000 --- a/src/DI/allocation.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include - -template -struct RebindAllocHelper -{ - using type = typename Traits::template rebind_alloc; -}; - -template -class AllocDestructor -{ - using _alloc_traits = std::allocator_traits; - -public: - using Pointer = typename _alloc_traits::pointer; - using Size = typename _alloc_traits::size_type; - - using pointer = Pointer; - using size = Size; - - AllocDestructor(Allocator &allocator, Size alloc_size) noexcept; - - void operator()(Pointer ptr) noexcept; - -private: - Allocator &_allocator; - Size _size; -}; - -#include "allocation.tpp" diff --git a/src/DI/allocation.tpp b/src/DI/allocation.tpp deleted file mode 100644 index 8753970..0000000 --- a/src/DI/allocation.tpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "allocation.hpp" - -template -AllocDestructor::AllocDestructor( - Allocator &allocator, - Size alloc_size -) noexcept - : _allocator(allocator), _size(alloc_size) -{ -} - -template -void AllocDestructor::operator()(Pointer ptr) noexcept -{ - _alloc_traits::deallocate(_allocator, ptr, _size); -} diff --git a/src/DI/auto_wirable.hpp b/src/DI/auto_wirable.hpp deleted file mode 100644 index 7c94074..0000000 --- a/src/DI/auto_wirable.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "DI/container.hpp" - -#include - -template -class AutoWirable -{ -public: - static auto resolve(const Container &container) noexcept - -> std::unique_ptr; -}; - -#include "auto_wirable.tpp" diff --git a/src/DI/auto_wirable.tpp b/src/DI/auto_wirable.tpp deleted file mode 100644 index 4ad34c4..0000000 --- a/src/DI/auto_wirable.tpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "auto_wirable.hpp" - -template -auto AutoWirable::resolve( - const Container &container -) noexcept -> std::unique_ptr -{ - return std::make_unique(container.get()...); -} diff --git a/src/DI/compressed_pair.hpp b/src/DI/compressed_pair.hpp deleted file mode 100644 index b8646db..0000000 --- a/src/DI/compressed_pair.hpp +++ /dev/null @@ -1,200 +0,0 @@ -#pragma once - -#include "DI/extra_concepts.hpp" - -#include -#include -#include -#include - -// Tag used to default initialize one or both of the pair's elements. -struct DefaultInitTag -{ -}; - -struct ValueInitTag -{ -}; - -template -struct TupleIndices -{ -}; - -template -struct IntegerSequence -{ - template