Template Class LoanableSequence
Defined in File LoanableSequence.hpp
Inheritance Relationships
Base Type
public eprosima::fastdds::dds::LoanableTypedCollection< T, std::true_type >
(Template Class LoanableTypedCollection)
Class Documentation
-
template<typename T, typename _NonConstEnabler = std::true_type>
class LoanableSequence : public eprosima::fastdds::dds::LoanableTypedCollection<T, std::true_type> 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>
’ asFooSeq
.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
Public Types
-
using size_type = LoanableCollection::size_type
-
using element_type = LoanableCollection::element_type
Public Functions
-
LoanableSequence() = default
Default constructor.
Creates the sequence with no data.
- Post
buffer() == nullptr
- Post
has_ownership() == true
- Post
length() == 0
- Post
maximum() == 0
-
inline LoanableSequence(size_type max)
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
max – [in] Number of elements to pre-allocate.
- Post
buffer() != nullptr
- Post
has_ownership() == true
- Post
length() == 0
- Post
maximum() == max
-
inline ~LoanableSequence()
Deallocate this sequence’s buffer.
- Pre
has_ownership() == true. If this precondition is not met, no memory will be released and a warning will be logged.
- Post
maximum() == 0 and the underlying buffer is released.
-
inline LoanableSequence(const LoanableSequence &other)
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
other – [in] The sequence from where contents are to be copied.
- Post
has_ownership() == true
- Post
maximum() == other.length()
- Post
length() == other.length()
- Post
buffer() != nullptr when other.length() > 0
-
inline LoanableSequence &operator=(const LoanableSequence &other)
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
other – [in] The sequence from where contents are to be copied.
- Post
has_ownership() == true
- Post
maximum() >= other.length()
- Post
length() == other.length()
- Post
buffer() != nullptr when other.length() > 0