COMMS
Template library intended to help with implementation of communication protocols.
|
#include "alloc.h"
In-place single object allocator for message objects without virtual destructor.
May allocate only single object at a time. In order to be able to allocate new object, previous one must be destructed first. The allocator contains uninitialised storage area in its private data, which is used to contain allocated object.
TInterface | Common interface class for all objects being allocated with this allocator. |
TAllocMessages | All the possible message types that can be allocated with this allocator bundled in std::tuple. They are used to identify the size required to allocate any of the provided objects. |
TOrigMessages | All the original message types (without comms::GenericMessage added) ids of which are known at compile time. |
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. | |
Public Member Functions | |
template<typename TObj , typename... TArgs> | |
Ptr | alloc (TId id, unsigned idx, TArgs &&... args) |
Allocation function. | |
const void * | allocAddr () const |
Get address of the objects being allocated using this allocator. | |
bool | allocated () const |
Inquire whether the object is already allocated. | |
bool | canAllocate () const |
Inquiry whether allocation is possible. | |
using comms::util::alloc::InPlaceSingleNoVirtualDestructor< TInterface, TAllocMessages, TOrigMessages, TId, TDefaultType >::Ptr = std::unique_ptr<TInterface, Deleter> |
Smart pointer (std::unique_ptr) to the allocated object.
The custom deleter makes sure the destructor of the allocated object is called.
Ptr comms::util::alloc::InPlaceSingleNoVirtualDestructor< TInterface, TAllocMessages, TOrigMessages, TId, TDefaultType >::alloc | ( | TId | id, |
unsigned | idx, | ||
TArgs &&... | args | ||
) |
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 TOrigMessages tuple. |
[in] | args | Extra arguments to be passed to allocated object's constructor. |