Template Class SmartChunk

Class Documentation

template<typename TransmissionInterface, typename T, typename H = cxx::add_const_conditionally_t<mepoo::NoUserHeader, T>>
class SmartChunk

Public Functions

template<typename S = T, typename = ForProducerOnly<S, T>>
SmartChunk(cxx::unique_ptr<T> &&smartChunkUniquePtr, TransmissionInterface &producer) noexcept

Constructor for a SmartChunk used by the Producer.

Template Parameters:

S – is a dummy template parameter to enable the constructor only for non-const T

Parameters:
  • smartChunkUniquePtr – is a rvalue to a cxx::unique_ptr<T> with to the data of the encapsulated type T

  • producer – is a reference to the producer to be able to use producer specific methods

template<typename S = T, typename = ForConsumerOnly<S, T>>
explicit SmartChunk(cxx::unique_ptr<T> &&smartChunkUniquePtr) noexcept

Constructor for a SmartChunk used by the Consumer.

Template Parameters:

S – is a dummy template parameter to enable the constructor only for const T

Parameters:

smartChunkUniquePtr – is a rvalue to a cxx::unique_ptr<T> with to the data of the encapsulated type T

~SmartChunk() noexcept = default
SmartChunk &operator=(SmartChunk &&rhs) noexcept = default
SmartChunk(SmartChunk &&rhs) noexcept = default
SmartChunk(const SmartChunk&) = delete
SmartChunk &operator=(const SmartChunk&) = delete
T *operator->() noexcept

Transparent access to the encapsulated type.

Returns:

a pointer to the encapsulated type.

const T *operator->() const noexcept

Transparent read-only access to the encapsulated type.

Returns:

a const pointer to the encapsulated type.

T &operator*() noexcept

Provides a reference to the encapsulated type.

Returns:

A T& to the encapsulated type.

const T &operator*() const noexcept

Provides a const reference to the encapsulated type.

Returns:

A const T& to the encapsulated type.

explicit operator bool() const noexcept

Indicates whether the smartChunk is valid, i.e. refers to allocated memory.

Returns:

true if the smartChunk is valid, false otherwise.

T *get() noexcept

Mutable access to the encapsulated type loaned to the smartChunk.

Returns:

a pointer to the encapsulated type.

const T *get() const noexcept

Read-only access to the encapsulated type loaned to the smartChunk.

Returns:

a const pointer to the encapsulated type.

cxx::add_const_conditionally_t<mepoo::ChunkHeader, T> *getChunkHeader() noexcept

Retrieve the ChunkHeader of the underlying memory chunk loaned to the smartChunk.

Returns:

The ChunkHeader of the underlying memory chunk.

const mepoo::ChunkHeader *getChunkHeader() const noexcept

Retrieve the ChunkHeader of the underlying memory chunk loaned to the smartChunk.

Returns:

The const ChunkHeader of the underlying memory chunk.

Protected Types

template<typename S, typename TT>
using ForProducerOnly = std::enable_if_t<std::is_same<S, TT>::value && !std::is_const<TT>::value, S>

Helper type to enable the constructor for the producer, i.e. when T has no const qualifier.

template<typename S, typename TT>
using ForConsumerOnly = std::enable_if_t<std::is_same<S, TT>::value && std::is_const<TT>::value, S>

Helper type to enable the constructor for the consumer, i.e. when T has a const qualifier.

template<typename R, typename HH>
using HasUserHeader = std::enable_if_t<std::is_same<R, HH>::value && !std::is_same<R, mepoo::NoUserHeader>::value, R>

Helper type to enable some methods only if a user-header is used.

Protected Functions

template<typename R = H, typename = HasUserHeader<R, H>>
cxx::add_const_conditionally_t<R, T> &getUserHeader() noexcept

Retrieve the user-header of the underlying memory chunk loaned to the SmartChunk.

Returns:

The user-header of the underlying memory chunk.

template<typename R = H, typename = HasUserHeader<R, H>>
const R &getUserHeader() const noexcept

Retrieve the user-header of the underlying memory chunk loaned to the SmartChunk.

Returns:

The user-header of the underlying memory chunk.

T *release() noexcept

Note

used by the producer to release the chunk ownership from the SmartChunk after publishing the chunk and therefore preventing the invocation of the custom deleter

Protected Attributes

internal::SmartChunkPrivateData<TransmissionInterface, T, H> m_members