|
|
@@ -19,9 +19,9 @@ namespace entt {
|
|
|
* Primary template isn't defined on purpose. All the specializations give a
|
|
|
* compile-time error unless the template parameter is a function type.
|
|
|
*
|
|
|
- * @tparam Function A valid function type.
|
|
|
+ * @tparam Type A valid signal handler type.
|
|
|
*/
|
|
|
-template<typename Function>
|
|
|
+template<typename Type>
|
|
|
class sink;
|
|
|
|
|
|
/**
|
|
|
@@ -30,9 +30,10 @@ class sink;
|
|
|
* Primary template isn't defined on purpose. All the specializations give a
|
|
|
* compile-time error unless the template parameter is a function type.
|
|
|
*
|
|
|
- * @tparam Function A valid function type.
|
|
|
+ * @tparam Type A valid function type.
|
|
|
+ * @tparam Allocator Type of allocator used to manage memory and elements.
|
|
|
*/
|
|
|
-template<typename Function>
|
|
|
+template<typename Type, typename Allocator>
|
|
|
class sigh;
|
|
|
|
|
|
/**
|
|
|
@@ -49,17 +50,104 @@ class sigh;
|
|
|
*
|
|
|
* @tparam Ret Return type of a function type.
|
|
|
* @tparam Args Types of arguments of a function type.
|
|
|
+ * @tparam Allocator Type of allocator used to manage memory and elements.
|
|
|
*/
|
|
|
-template<typename Ret, typename... Args>
|
|
|
-class sigh<Ret(Args...)> {
|
|
|
+template<typename Ret, typename... Args, typename Allocator>
|
|
|
+class sigh<Ret(Args...), Allocator> {
|
|
|
/*! @brief A sink is allowed to modify a signal. */
|
|
|
- friend class sink<Ret(Args...)>;
|
|
|
+ friend class sink<sigh<Ret(Args...), Allocator>>;
|
|
|
+
|
|
|
+ using allocator_traits = std::allocator_traits<Allocator>;
|
|
|
+ using alloc = typename allocator_traits::template rebind_alloc<delegate<Ret(Args...)>>;
|
|
|
+ using alloc_traits = typename std::allocator_traits<alloc>;
|
|
|
+
|
|
|
+ using container_type = std::vector<delegate<Ret(Args...)>, alloc>;
|
|
|
|
|
|
public:
|
|
|
+ /*! @brief Allocator type. */
|
|
|
+ using allocator_type = Allocator;
|
|
|
/*! @brief Unsigned integer type. */
|
|
|
using size_type = std::size_t;
|
|
|
/*! @brief Sink type. */
|
|
|
- using sink_type = sink<Ret(Args...)>;
|
|
|
+ using sink_type = sink<sigh<Ret(Args...), Allocator>>;
|
|
|
+
|
|
|
+ /*! @brief Default constructor. */
|
|
|
+ sigh()
|
|
|
+ : sigh{allocator_type{}} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Constructs a signal handler with a given allocator.
|
|
|
+ * @param allocator The allocator to use.
|
|
|
+ */
|
|
|
+ explicit sigh(const allocator_type &allocator)
|
|
|
+ : calls{allocator} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Default copy constructor.
|
|
|
+ * @param other The instance to copy from.
|
|
|
+ */
|
|
|
+ sigh(const sigh &other)
|
|
|
+ : calls{other.calls} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Allocator-extended copy constructor.
|
|
|
+ * @param other The instance to copy from.
|
|
|
+ * @param allocator The allocator to use.
|
|
|
+ */
|
|
|
+ sigh(const sigh &other, const allocator_type &allocator)
|
|
|
+ : calls{other.calls, allocator} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Default move constructor.
|
|
|
+ * @param other The instance to move from.
|
|
|
+ */
|
|
|
+ sigh(sigh &&other) ENTT_NOEXCEPT
|
|
|
+ : calls{std::move(other.calls)} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Allocator-extended move constructor.
|
|
|
+ * @param other The instance to move from.
|
|
|
+ * @param allocator The allocator to use.
|
|
|
+ */
|
|
|
+ sigh(sigh &&other, const allocator_type &allocator) ENTT_NOEXCEPT
|
|
|
+ : calls{std::move(other.calls), allocator} {}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Default copy assignment operator.
|
|
|
+ * @param other The instance to copy from.
|
|
|
+ * @return This signal handler.
|
|
|
+ */
|
|
|
+ sigh &operator=(const sigh &other) {
|
|
|
+ calls = other.calls;
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Default move assignment operator.
|
|
|
+ * @param other The instance to move from.
|
|
|
+ * @return This signal handler.
|
|
|
+ */
|
|
|
+ sigh &operator=(sigh &&other) ENTT_NOEXCEPT {
|
|
|
+ calls = std::move(other.calls);
|
|
|
+ return *this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Exchanges the contents with those of a given signal handler.
|
|
|
+ * @param other Signal handler to exchange the content with.
|
|
|
+ */
|
|
|
+ void swap(sigh &other) {
|
|
|
+ using std::swap;
|
|
|
+ swap(calls, other.calls);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Returns the associated allocator.
|
|
|
+ * @return The associated allocator.
|
|
|
+ */
|
|
|
+ [[nodiscard]] constexpr allocator_type get_allocator() const ENTT_NOEXCEPT {
|
|
|
+ return calls.get_allocator();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* @brief Instance type when it comes to connecting member functions.
|
|
|
@@ -133,7 +221,7 @@ public:
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- std::vector<delegate<Ret(Args...)>> calls;
|
|
|
+ container_type calls;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
@@ -271,10 +359,11 @@ private:
|
|
|
*
|
|
|
* @tparam Ret Return type of a function type.
|
|
|
* @tparam Args Types of arguments of a function type.
|
|
|
+ * @tparam Allocator Type of allocator used to manage memory and elements.
|
|
|
*/
|
|
|
-template<typename Ret, typename... Args>
|
|
|
-class sink<Ret(Args...)> {
|
|
|
- using signal_type = sigh<Ret(Args...)>;
|
|
|
+template<typename Ret, typename... Args, typename Allocator>
|
|
|
+class sink<sigh<Ret(Args...), Allocator>> {
|
|
|
+ using signal_type = sigh<Ret(Args...), Allocator>;
|
|
|
using difference_type = typename std::iterator_traits<typename decltype(signal_type::calls)::iterator>::difference_type;
|
|
|
|
|
|
template<auto Candidate, typename Type>
|
|
|
@@ -292,7 +381,7 @@ public:
|
|
|
* @brief Constructs a sink that is allowed to modify a given signal.
|
|
|
* @param ref A valid reference to a signal object.
|
|
|
*/
|
|
|
- sink(sigh<Ret(Args...)> &ref) ENTT_NOEXCEPT
|
|
|
+ sink(sigh<Ret(Args...), Allocator> &ref) ENTT_NOEXCEPT
|
|
|
: offset{},
|
|
|
signal{&ref} {}
|
|
|
|
|
|
@@ -507,14 +596,15 @@ private:
|
|
|
/**
|
|
|
* @brief Deduction guide.
|
|
|
*
|
|
|
- * It allows to deduce the function type of a sink directly from the signal it
|
|
|
- * refers to.
|
|
|
+ * It allows to deduce the signal handler type of a sink directly from the
|
|
|
+ * signal it refers to.
|
|
|
*
|
|
|
* @tparam Ret Return type of a function type.
|
|
|
* @tparam Args Types of arguments of a function type.
|
|
|
+ * @tparam Allocator Type of allocator used to manage memory and elements.
|
|
|
*/
|
|
|
-template<typename Ret, typename... Args>
|
|
|
-sink(sigh<Ret(Args...)> &) -> sink<Ret(Args...)>;
|
|
|
+template<typename Ret, typename... Args, typename Allocator>
|
|
|
+sink(sigh<Ret(Args...), Allocator> &) -> sink<sigh<Ret(Args...), Allocator>>;
|
|
|
|
|
|
} // namespace entt
|
|
|
|