Skip to content

Commit 7584aa6

Browse files
committed
Update delegate library
1 parent 3cd0582 commit 7584aa6

7 files changed

Lines changed: 38 additions & 18 deletions

File tree

Delegate/Delegate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/// @brief Delegate series of classes are used to invoke a function synchronously.
1010
/// @details Delgates support binding to free functions, class instance functions, class
1111
/// static function, and std::function targets. Lambda functions can be bound to a delegate
12-
/// when assigned to a `std::function`. The classes are not thread safe.
12+
/// when assigned to a `std::function`. The classes are not thread-safe.
1313
///
1414
/// Limitations:
1515
///
@@ -23,6 +23,7 @@
2323
#include <memory>
2424
#include "DelegateOpt.h"
2525

26+
/// The delegate library namespace
2627
namespace DelegateLib {
2728

2829
/// @brief Non-template base class for all delegates.

Delegate/DelegateAsync.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
/// sending a clone of the object to the destination thread message queue. The destination
1313
/// thread calls `Invoke()` to invoke the target function.
1414
///
15+
/// Argument data is created on the heap using `operator new` for transport thought a thread
16+
/// message queue. An optional fixed-block allocator is available. See `USE_ALLOCATOR`.
17+
///
1518
/// `RetType operator()(Args... args)` - called by the source thread to initiate the async
16-
/// function call. May throw `std::bad_alloc` if dynamic storage allocation fails and USE_ASSERTS
17-
/// is not defined. Clone() may also throw `std::bad_alloc`. All other delegate class functions do
18-
/// not throw exceptions.
19+
/// function call. May throw `std::bad_alloc` if dynamic storage allocation fails and `USE_ASSERTS`
20+
/// is not defined. Clone() may also throw `std::bad_alloc` unless `USE_ASSERTS`. All other delegate
21+
/// class functions do not throw exceptions.
1922
///
2023
/// `void Invoke(std::shared_ptr<DelegateMsg> msg)` - called by the destination
2124
/// thread to invoke the target function. The destination thread must not call any other
@@ -49,6 +52,22 @@
4952

5053
namespace DelegateLib {
5154

55+
// Helper trait to check if a type is a reference to a std::shared_ptr
56+
template <typename T>
57+
struct is_shared_ptr_reference : std::false_type {};
58+
59+
template <typename T>
60+
struct is_shared_ptr_reference<std::shared_ptr<T>&> : std::true_type {};
61+
62+
template <typename T>
63+
struct is_shared_ptr_reference<std::shared_ptr<T>*> : std::true_type {};
64+
65+
template <typename T>
66+
struct is_shared_ptr_reference<const std::shared_ptr<T>&> : std::true_type {};
67+
68+
template <typename T>
69+
struct is_shared_ptr_reference<const std::shared_ptr<T>* > : std::true_type {};
70+
5271
/// @brief Stores all function arguments suitable for non-blocking asynchronous calls.
5372
/// Argument data is stored in the heap.
5473
/// @tparam Args The argument types of the bound delegate function.
@@ -265,8 +284,8 @@ class DelegateFreeAsync<RetType(Args...)> : public DelegateFree<RetType(Args...)
265284
// undefined. In other words:
266285
// void MyFunc(std::shared_ptr<T> data) // Ok!
267286
// void MyFunc(std::shared_ptr<T>& data) // Error if DelegateAsync or DelegateSpAsync target!
268-
static_assert(!(std::disjunction_v<is_shared_ptr<Args>...> &&
269-
(std::disjunction_v<std::is_lvalue_reference<Args>, std::is_pointer<Args>> || ...)),
287+
static_assert(!(
288+
std::disjunction_v<is_shared_ptr_reference<Args>...>),
270289
"std::shared_ptr reference argument not allowed");
271290
}
272291
}
@@ -565,8 +584,8 @@ class DelegateMemberAsync<TClass, RetType(Args...)> : public DelegateMember<TCla
565584
// undefined. In other words:
566585
// void MyFunc(std::shared_ptr<T> data) // Ok!
567586
// void MyFunc(std::shared_ptr<T>& data) // Error if DelegateAsync or DelegateSpAsync target!
568-
static_assert(!(std::disjunction_v<is_shared_ptr<Args>...> &&
569-
(std::disjunction_v<std::is_lvalue_reference<Args>, std::is_pointer<Args>> || ...)),
587+
static_assert(!(
588+
std::disjunction_v<is_shared_ptr_reference<Args>...>),
570589
"std::shared_ptr reference argument not allowed");
571590
}
572591
}
@@ -806,8 +825,8 @@ class DelegateFunctionAsync<RetType(Args...)> : public DelegateFunction<RetType(
806825
// undefined. In other words:
807826
// void MyFunc(std::shared_ptr<T> data) // Ok!
808827
// void MyFunc(std::shared_ptr<T>& data) // Error if DelegateAsync or DelegateSpAsync target!
809-
static_assert(!(std::disjunction_v<is_shared_ptr<Args>...> &&
810-
(std::disjunction_v<std::is_lvalue_reference<Args>, std::is_pointer<Args>> || ...)),
828+
static_assert(!(
829+
std::disjunction_v<is_shared_ptr_reference<Args>...>),
811830
"std::shared_ptr reference argument not allowed");
812831
}
813832
}

Delegate/DelegateAsyncWait.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
/// the target function is not invoked.
2222
///
2323
/// The `m_lock` mutex is used to protect shared state data between the source and destination
24-
/// threads using the two thread safe functions below:
24+
/// threads using the two thread-safe functions below:
2525
///
2626
/// `RetType operator()(Args... args)` - called by the source thread to initiate the async
27-
/// function call. May throw `std::bad_alloc` if dynamic storage allocation fails. Clone()
28-
/// also may throw `std::bad_alloc`. All other delegate class functions do not throw exceptions.
27+
/// function call. May throw `std::bad_alloc` if dynamic storage allocation fails and `USE_ASSERTS`
28+
/// is not defined. Clone() also may throw `std::bad_alloc` unless 'USE_ASSERTS'. All other delegate
29+
/// class functions do not throw exceptions.
2930
///
3031
/// `void Invoke(std::shared_ptr<DelegateMsg> msg)` - called by the destination
3132
/// thread to invoke the target function. The destination thread must not call any other

Delegate/DelegateLib.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
/// @file
99
/// @brief DelegateLib.h is a single include to obtain all delegate functionality.
1010
///
11-
/// @mainpage C++ Delegate Library Documentation
12-
///
1311
/// A C++ delegate library capable of invoking any callable function either synchronously
1412
/// or asynchronously on a user specified thread of control.
1513
///

Delegate/DelegateOpt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
// If USE_ASSERTS defined above, consider defining USE_ALLOCATOR to prevent
2222
// std::list usage within delegate library from throwing a std::bad_alloc
2323
// exception. The std_allocator calls assert if out of memory.
24+
// See master CMakeLists.txt for info on enabling the fixed-block allocator.
2425
#ifdef USE_ALLOCATOR
25-
// Use stl_allocator fixed block allocator for dynamic storage allocation
26+
// Use stl_allocator fixed-block allocator for dynamic storage allocation
2627
#include "xlist.h"
2728
#include "stl_allocator.h"
2829
#else

Delegate/MulticastDelegateSafe.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/// @file
55
/// @brief Delegate container for storing and iterating over a collection of
6-
/// delegate instances. Class is thread safe.
6+
/// delegate instances. Class is thread-safe.
77

88
#include "MulticastDelegate.h"
99
#include <mutex>

Delegate/UnicastDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace DelegateLib {
1313
template <class R>
1414
struct UnicastDelegate; // Not defined
1515

16-
/// @brief A non-thread safe delegate container storing one delegate. Void and
16+
/// @brief A non-thread-safe delegate container storing one delegate. Void and
1717
/// non-void return values supported.
1818
template<class RetType, class... Args>
1919
class UnicastDelegate<RetType(Args...)>

0 commit comments

Comments
 (0)