Fast DDS  Version 3.1.2
Fast DDS
Loading...
Searching...
No Matches
LoanableSequence< T, _NonConstEnabler > Class Template Reference

A type-safe, ordered collection of elements that can receive the buffer from outside (loan). More...

#include <LoanableSequence.hpp>

Inheritance diagram for LoanableSequence< T, _NonConstEnabler >:

Public Types

using size_type = LoanableCollection::size_type
 
using element_type = LoanableCollection::element_type
 
- Public Types inherited from LoanableCollection
using size_type = int32_t
 
using element_type = void *
 

Public Member Functions

 LoanableSequence ()=default
 Default constructor.
 
 LoanableSequence (size_type max)
 Pre-allocation constructor.
 
 ~LoanableSequence ()
 Deallocate this sequence's buffer.
 
 LoanableSequence (const LoanableSequence &other)
 Construct a sequence with the contents of another sequence.
 
LoanableSequenceoperator= (const LoanableSequence &other)
 Copy the contents of another sequence into this one.
 
- Public Member Functions inherited from LoanableTypedCollection< T, _NonConstEnabler >
template<typename Enabler = _NonConstEnabler>
std::enable_if< Enabler::value, T >::type & operator[] (size_type n)
 Set an element of the sequence.
 
const T & operator[] (size_type n) const
 Get an element of the sequence.
 
- Public Member Functions inherited from LoanableCollection
const element_typebuffer () const
 Get the pointer to the elements buffer.
 
bool has_ownership () const
 Get the ownership flag.
 
size_type maximum () const
 Get the maximum number of elements currently allocated.
 
size_type length () const
 Get the number of elements currently accessible.
 
bool length (size_type new_length)
 Set the number of elements currently accessible.
 
bool loan (element_type *buffer, size_type new_maximum, size_type new_length)
 Loan a buffer to the collection.
 
element_typeunloan (size_type &maximum, size_type &length)
 Remove the loan from the collection.
 
element_typeunloan ()
 Remove the loan from the collection.
 

Protected Attributes

size_type maximum_
 
size_type length_
 
element_typeelements_
 
bool has_ownership_
 
- Protected Attributes inherited from LoanableCollection
size_type maximum_ = 0
 
size_type length_ = 0
 
element_typeelements_ = nullptr
 
bool has_ownership_ = true
 

Additional Inherited Members

- Protected Member Functions inherited from LoanableCollection
 LoanableCollection ()=default
 Default constructor.
 

Detailed Description

template<typename T, typename _NonConstEnabler = std::true_type>
class eprosima::fastdds::dds::LoanableSequence< T, _NonConstEnabler >

A type-safe, ordered collection of elements that can receive the buffer from outside (loan).

For users who define data types in OMG IDL, this type corresponds to the IDL express sequence<T>.

For any user-data type Foo that an application defines for the purpose of data-distribution with Fast DDS, a 'using FooSeq = LoanableSequence<Foo>' is generated. The sequence offers a subset of the methods defined by the standard OMG IDL to C++ mapping for sequences. We refer to an IDL 'sequence<Foo>' as FooSeq.

The state of a sequence is described by the properties 'maximum', 'length' and 'has_ownership'.

  • The 'maximum' represents the size of the underlying buffer; this is the maximum number of elements it can possibly hold. It is returned by the maximum() operation.
  • The 'length' represents the actual number of elements it currently holds. It is returned by the length() operation.
  • The 'has_ownership' flag represents whether the sequence owns the underlying buffer. It is returned by the has_ownership() operation. If the sequence does not own the underlying buffer, the underlying buffer is loaned from somewhere else. This flag influences the lifecycle of the sequence and what operations are allowed on it. The general guidelines are provided below and more details are described in detail as pre-conditions and post-conditions of each of the sequence's operations:
  • If has_ownership == true, the sequence has ownership on the buffer. It is then responsible for destroying the buffer when the sequence is destroyed.
  • If has_ownership == false, the sequence does not have ownership on the buffer. This implies that the sequence is loaning the buffer. The sequence should not be destroyed until the loan is returned.
  • A sequence with a zero maximum always has has_ownership == true

Member Typedef Documentation

◆ element_type

template<typename T , typename _NonConstEnabler = std::true_type>
using element_type = LoanableCollection::element_type

◆ size_type

template<typename T , typename _NonConstEnabler = std::true_type>
using size_type = LoanableCollection::size_type

Constructor & Destructor Documentation

◆ LoanableSequence() [1/3]

template<typename T , typename _NonConstEnabler = std::true_type>
LoanableSequence ( )
default

Default constructor.

Creates the sequence with no data.

Postcondition
buffer() == nullptr
has_ownership() == true
length() == 0
maximum() == 0

◆ LoanableSequence() [2/3]

template<typename T , typename _NonConstEnabler = std::true_type>
LoanableSequence ( size_type  max)
inline

Pre-allocation constructor.

Creates the sequence with an initial number of allocated elements. When the input parameter is less than or equal to 0, the behavior is equivalent to the default constructor. Otherwise, the post-conditions below will apply.

Parameters
[in]maxNumber of elements to pre-allocate.
Postcondition
buffer() != nullptr
has_ownership() == true
length() == 0
maximum() == max

◆ ~LoanableSequence()

template<typename T , typename _NonConstEnabler = std::true_type>
~LoanableSequence ( )
inline

Deallocate this sequence's buffer.

Precondition
has_ownership() == true. If this precondition is not met, no memory will be released and a warning will be logged.
Postcondition
maximum() == 0 and the underlying buffer is released.

◆ LoanableSequence() [3/3]

template<typename T , typename _NonConstEnabler = std::true_type>
LoanableSequence ( const LoanableSequence< T, _NonConstEnabler > &  other)
inline

Construct a sequence with the contents of another sequence.

This method performs a deep copy of the sequence received into this one. Allocations will happen when other.length() > 0

Parameters
[in]otherThe sequence from where contents are to be copied.
Postcondition
has_ownership() == true
maximum() == other.length()
length() == other.length()
buffer() != nullptr when other.length() > 0

Member Function Documentation

◆ operator=()

template<typename T , typename _NonConstEnabler = std::true_type>
LoanableSequence & operator= ( const LoanableSequence< T, _NonConstEnabler > &  other)
inline

Copy the contents of another sequence into this one.

This method performs a deep copy of the sequence received into this one. If this sequence had a buffer loaned, it will behave as if unloan has been called. Allocations will happen when (a) has_ownership() == false and other.length() > 0 (b) has_ownership() == true and other.length() > maximum()

Parameters
[in]otherThe sequence from where contents are to be copied.
Postcondition
has_ownership() == true
maximum() >= other.length()
length() == other.length()
buffer() != nullptr when other.length() > 0

Member Data Documentation

◆ elements_

template<typename T , typename _NonConstEnabler = std::true_type>
element_type* elements_
protected

◆ has_ownership_

template<typename T , typename _NonConstEnabler = std::true_type>
bool has_ownership_
protected

◆ length_

template<typename T , typename _NonConstEnabler = std::true_type>
size_type length_
protected

◆ maximum_

template<typename T , typename _NonConstEnabler = std::true_type>
size_type maximum_
protected

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