diff options
author | HampusM <hampus@hampusmat.com> | 2022-04-10 17:20:49 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:58 +0200 |
commit | b36d072ad7a7b9c6e30fcb25d6bbb001a8393468 (patch) | |
tree | 7749fc877652bb2cf7bbd2b7c1fed5e3abe397fc /src/DI/interfaces/copyable_functor.hpp | |
parent | b828d4799a84beb1afbd889e5c4cb939a8b3df78 (diff) |
refactor: add factory class & make DI container return unique ptrs
Diffstat (limited to 'src/DI/interfaces/copyable_functor.hpp')
-rw-r--r-- | src/DI/interfaces/copyable_functor.hpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/DI/interfaces/copyable_functor.hpp b/src/DI/interfaces/copyable_functor.hpp new file mode 100644 index 0000000..46b7588 --- /dev/null +++ b/src/DI/interfaces/copyable_functor.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include <typeinfo> + +/** + * A copyable function object. + */ +template <class Function> +class ICopyableFunctor; + +template <class Return, class... Args> +class ICopyableFunctor<Return(Args...)> +{ +public: + ICopyableFunctor() = default; + + ICopyableFunctor(const ICopyableFunctor &) = delete; + + ICopyableFunctor(ICopyableFunctor &&) = delete; + + virtual ~ICopyableFunctor() = default; + + [[nodiscard]] virtual auto clone() const -> ICopyableFunctor * = 0; + + virtual void clone(ICopyableFunctor *) const = 0; + + virtual void destroy() noexcept = 0; + + virtual void destroy_deallocate() noexcept = 0; + + virtual auto operator()(Args &&...) -> Return = 0; + + auto operator=(const ICopyableFunctor &) = delete; + + auto operator=(ICopyableFunctor &&) = delete; + + [[nodiscard]] virtual auto target(const std::type_info &) const noexcept -> const + void * = 0; + + [[nodiscard]] virtual auto target_type() const noexcept -> const std::type_info & = 0; +}; |