From b36d072ad7a7b9c6e30fcb25d6bbb001a8393468 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 10 Apr 2022 17:20:49 +0200 Subject: refactor: add factory class & make DI container return unique ptrs --- src/DI/factory.tpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/DI/factory.tpp (limited to 'src/DI/factory.tpp') diff --git a/src/DI/factory.tpp b/src/DI/factory.tpp new file mode 100644 index 0000000..38b9c00 --- /dev/null +++ b/src/DI/factory.tpp @@ -0,0 +1,65 @@ +#pragma once + +#include "factory.hpp" + +template +Factory::Factory(const Factory &factory) : _functor(factory._functor) +{ +} + +template +Factory::Factory(Factory &&factory) noexcept + : _functor(std::move(factory._functor)) +{ +} + +template +auto Factory::operator=(Factory &&factory) noexcept + -> Factory & +{ + _functor = std::move(factory._functor); + return *this; +} + +template +auto Factory::operator=(std::nullptr_t) noexcept + -> Factory & +{ + _functor = nullptr; + return *this; +} + +template +Factory::~Factory() = default; + +template +Factory::operator bool() const noexcept +{ + return static_cast(_functor); +} + +template +auto Factory::operator()(Args... args) const -> Return +{ + return _functor(std::forward(args)...); +} + +template +auto Factory::target_type() const noexcept -> const std::type_info & +{ + return _functor.target_type(); +} + +template +template +auto Factory::target() noexcept -> Tp * +{ + return static_cast(_functor.template target()); +} + +template +template +auto Factory::target() const noexcept -> const Tp * +{ + return _functor.template target(); +} -- cgit v1.2.3-18-g5258