COMMS
Template library intended to help with implementation of communication protocols.
|
#include "alloc.h"
In-place single object allocator.
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. |
TAllTypes | All the possible 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. |
Public Types | |
using | Ptr = std::unique_ptr< TInterface, details::InPlaceDeleter< TInterface > > |
Smart pointer (std::unique_ptr) to the allocated object. | |
Public Member Functions | |
~InPlaceSingle () | |
Destructor. | |
template<typename TObj , typename... TArgs> | |
Ptr | alloc (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. | |
template<typename TObj > | |
Ptr | wrap (TObj *obj) |
Function used to wrap raw pointer into a smart one. | |
using comms::util::alloc::InPlaceSingle< TInterface, TAllTypes >::Ptr = std::unique_ptr<TInterface, details::InPlaceDeleter<TInterface> > |
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::InPlaceSingle< TInterface, TAllTypes >::alloc | ( | 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] | args | Extra arguments to be passed to allocated object's constructor. |
Ptr comms::util::alloc::InPlaceSingle< TInterface, TAllTypes >::wrap | ( | TObj * | obj | ) |
Function used to wrap raw pointer into a smart one.
Type | of the object, expected to be the same as or derived from TInterface. |
[in] | obj | Pointer to previously allocated object. |