aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-03 19:17:48 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:54 +0200
commit70b21e90d7be4d892b7d17440d64630e7ee1a575 (patch)
tree429e9038df3263b31e98df301d0a0c85671057fa
parentc2f41a5b278df2837f4cc5617df07248a048d93c (diff)
refactor: improve factories
-rw-r--r--src/DI/container.hpp2
-rw-r--r--src/DI/function_wrapper.hpp2
-rw-r--r--src/DI/function_wrapper.tpp5
-rw-r--r--src/DI/type_traits.hpp4
-rw-r--r--src/interfaces/bounds.hpp4
-rw-r--r--src/interfaces/matrix.hpp4
-rw-r--r--src/interfaces/randomization.hpp5
-rw-r--r--src/interfaces/vector2.hpp4
8 files changed, 14 insertions, 16 deletions
diff --git a/src/DI/container.hpp b/src/DI/container.hpp
index 2dd194f..93722b6 100644
--- a/src/DI/container.hpp
+++ b/src/DI/container.hpp
@@ -34,7 +34,7 @@ public:
template <class Interface>
BindingBuilder<Interface> bind();
- template <class Interface, class = std::enable_if_t<std::is_abstract_v<Interface>>>
+ template <class Interface, class = std::enable_if_t<std::is_class_v<Interface>>>
std::shared_ptr<Interface> get() const;
template <typename Interface, typename = std::enable_if_t<is_func_v<Interface>>>
diff --git a/src/DI/function_wrapper.hpp b/src/DI/function_wrapper.hpp
index e4b6779..716668c 100644
--- a/src/DI/function_wrapper.hpp
+++ b/src/DI/function_wrapper.hpp
@@ -9,7 +9,7 @@ template <class Interface>
class FunctionWrapper : public IWrapper<Interface>
{
public:
- explicit FunctionWrapper(Interface func) : _func(func) {}
+ explicit FunctionWrapper(Interface func) noexcept;
[[nodiscard]] Interface get() const;
diff --git a/src/DI/function_wrapper.tpp b/src/DI/function_wrapper.tpp
index 4e09957..920c7f2 100644
--- a/src/DI/function_wrapper.tpp
+++ b/src/DI/function_wrapper.tpp
@@ -3,6 +3,11 @@
#include "function_wrapper.hpp"
template <class Interface>
+FunctionWrapper<Interface>::FunctionWrapper(Interface func) noexcept : _func(func)
+{
+}
+
+template <class Interface>
Interface FunctionWrapper<Interface>::get() const
{
return _func;
diff --git a/src/DI/type_traits.hpp b/src/DI/type_traits.hpp
index a852a4f..e4b6640 100644
--- a/src/DI/type_traits.hpp
+++ b/src/DI/type_traits.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <functional>
+#include <type_traits>
template <typename NotAFunc>
struct is_func : public std::false_type // NOLINT(readability-identifier-naming)
@@ -8,7 +8,7 @@ struct is_func : public std::false_type // NOLINT(readability-identifier-naming)
};
template <typename Return, typename... Args>
-struct is_func<std::function<Return(Args...)>> : public std::true_type
+struct is_func<Return (*)(Args...)> : public std::true_type
{
};
diff --git a/src/interfaces/bounds.hpp b/src/interfaces/bounds.hpp
index 7e920cf..b431874 100644
--- a/src/interfaces/bounds.hpp
+++ b/src/interfaces/bounds.hpp
@@ -2,7 +2,6 @@
#include "interfaces/vector2.hpp"
-#include <functional>
#include <memory>
enum CoordsValidation
@@ -39,5 +38,4 @@ struct IBoundsOptions
unsigned int height;
};
-using IBoundsFactory =
- std::function<std::shared_ptr<IBounds>(const IBoundsOptions &options)>;
+using IBoundsFactory = std::shared_ptr<IBounds> (*)(const IBoundsOptions &options);
diff --git a/src/interfaces/matrix.hpp b/src/interfaces/matrix.hpp
index ab5f40b..72d18d9 100644
--- a/src/interfaces/matrix.hpp
+++ b/src/interfaces/matrix.hpp
@@ -3,7 +3,6 @@
#include "interfaces/bounds.hpp"
#include "interfaces/vector2.hpp"
-#include <functional>
#include <memory>
template <typename Element>
@@ -46,5 +45,4 @@ public:
};
template <typename Element>
-using IMatrixFactory =
- std::function<std::shared_ptr<IMatrix<Element>>(const IBounds &bounds)>;
+using IMatrixFactory = std::shared_ptr<IMatrix<Element>> (*)(const IBounds &bounds);
diff --git a/src/interfaces/randomization.hpp b/src/interfaces/randomization.hpp
index 9eeec0a..12f6486 100644
--- a/src/interfaces/randomization.hpp
+++ b/src/interfaces/randomization.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <functional>
#include <memory>
class ISeedGenerator
@@ -11,7 +10,7 @@ public:
[[nodiscard]] virtual unsigned int random_seed() const = 0;
};
-using ISeedGeneratorFactory = std::function<std::shared_ptr<ISeedGenerator>()>;
+using ISeedGeneratorFactory = std::shared_ptr<ISeedGenerator> (*)();
/**
* Pseudo-random unsigned integer generator.
@@ -32,4 +31,4 @@ public:
};
using IRandomNumberGeneratorFactory =
- std::function<std::shared_ptr<IRandomNumberGenerator>(const unsigned int &seed)>;
+ std::shared_ptr<IRandomNumberGenerator> (*)(const unsigned int &seed);
diff --git a/src/interfaces/vector2.hpp b/src/interfaces/vector2.hpp
index 569dc30..dfd369f 100644
--- a/src/interfaces/vector2.hpp
+++ b/src/interfaces/vector2.hpp
@@ -1,6 +1,5 @@
#pragma once
-#include <functional>
#include <memory>
class IVector2
@@ -42,5 +41,4 @@ struct IVector2Options
unsigned int y;
};
-using IVector2Factory =
- std::function<std::shared_ptr<IVector2>(const IVector2Options &options)>;
+using IVector2Factory = std::shared_ptr<IVector2> (*)(const IVector2Options &options);