COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
comms::util::alloc::InPlaceSingleNoVirtualDestructor< TInterface, TAllocMessages, TOrigMessages, TId, TDefaultType > Class Template Reference

#include "alloc.h"

Detailed Description

template<typename TInterface, typename TAllocMessages, typename TOrigMessages, typename TId, typename TDefaultType = void>
class comms::util::alloc::InPlaceSingleNoVirtualDestructor< TInterface, TAllocMessages, TOrigMessages, TId, TDefaultType >

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.

Template Parameters
TInterfaceCommon interface class for all objects being allocated with this allocator.
TAllocMessagesAll 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.
TOrigMessagesAll the original message types (without comms::GenericMessage added) ids of which are known at compile time.
TDefaultTypeMessage 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.
 

Member Typedef Documentation

◆ Ptr

template<typename TInterface , typename TAllocMessages , typename TOrigMessages , typename TId , typename TDefaultType = void>
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.

Member Function Documentation

◆ alloc()

template<typename TInterface , typename TAllocMessages , typename TOrigMessages , typename TId , typename TDefaultType = void>
template<typename TObj , typename... TArgs>
Ptr comms::util::alloc::InPlaceSingleNoVirtualDestructor< TInterface, TAllocMessages, TOrigMessages, TId, TDefaultType >::alloc ( TId  id,
unsigned  idx,
TArgs &&...  args 
)

Allocation function.

Template Parameters
TObjType of the object being allocated, expected to be the same as or derived from TInterface.
TArgstypes of arguments to be passed to the constructor.
Parameters
[in]idNumeric ID of the message
[in]idxIndex of the message type among types with same ID provided in TOrigMessages tuple.
[in]argsExtra arguments to be passed to allocated object's constructor.
Returns
Smart pointer to the allocated object.

The documentation for this class was generated from the following file: