9 #ifndef OS_DELEGATE_HPP_
10 #define OS_DELEGATE_HPP_
45 template <
class Interface,
class Implementation>
48 static_assert(std::is_base_of<Interface, Implementation>::value,
"Implementation must derive from Interface");
49 static_assert(
sizeof(Implementation) <=
FW_HANDLE_MAX_SIZE,
"Handle size not large enough");
50 static_assert((
FW_HANDLE_ALIGNMENT %
alignof(Implementation)) == 0,
"Handle alignment invalid");
52 Implementation*
interface = new (aligned_new_memory) Implementation;
88 template <
class Interface,
class Implementation>
90 const Implementation* copy_me =
reinterpret_cast<const Implementation*
>(to_copy);
92 static_assert(std::is_base_of<Interface, Implementation>::value,
"Implementation must derive from Interface");
93 static_assert(
sizeof(Implementation) <=
sizeof(aligned_new_memory),
"Handle size not large enough");
94 static_assert((
FW_HANDLE_ALIGNMENT %
alignof(Implementation)) == 0,
"Handle alignment invalid");
96 Implementation*
interface = nullptr;
97 if (to_copy ==
nullptr) {
98 interface = new (aligned_new_memory) Implementation;
100 interface = new (aligned_new_memory) Implementation(*copy_me);
#define FW_HANDLE_ALIGNMENT
Alignment of handle storage.
#define FW_HANDLE_MAX_SIZE
Maximum size of a handle for OS resources (files, queues, locks, etc.)
U8 HandleStorage[FW_HANDLE_MAX_SIZE]
Storage type for OSAL handles.
Interface * makeDelegate(HandleStorage &aligned_new_memory)
Make a delegate of type Interface using Implementation without copy-constructor support (generic func...