COMMS
Template library intended to help with implementation of communication protocols.
|
#include "alloc.h"
Dynamic memory allocator for message types without virtual destructor.
Uses standard operator "new" to allocate and initialise requested object while using custom deleter.
TInterface | Common interface class for all objects being allocated with this allocator. |
TAllMessages | Tuple of all messages types, object of which could be allocated. |
TId | Type of message ID |
TDefaultType | Message type to cast to when correct type cannot be recognised. void means does not exist. |
Public Types | |
using | Ptr = std::unique_ptr< TInterface, Deleter > |
Smart pointer (std::unique_ptr) to the allocated object. | |
Static Public Member Functions | |
template<typename TObj , typename... TArgs> | |
static Ptr | alloc (TId id, unsigned idx, TArgs &&... args) |
Allocation function. | |
static constexpr bool | canAllocate () |
Inquiry whether allocation is possible. | |
|
static |
Allocation function.
TObj | Type of the object being allocated, expected to be the same as or derived from TInterface. |
TArgs | types of arguments to be passed to the constructor. |
[in] | id | Numeric ID of the message |
[in] | idx | Index of the message type among types with same ID provided in TAllMessages tuple. |
[in] | args | Extra arguments to be passed to allocated object's constructor. |
|
staticconstexpr |
Inquiry whether allocation is possible.