Fast DDS  Version 3.0.0
Fast DDS
Loading...
Searching...
No Matches
LoanableCollection Class Referenceabstract

A collection of generic opaque pointers that can receive the buffer from outside (loan). More...

#include <LoanableCollection.hpp>

Inheritance diagram for LoanableCollection:

Public Types

using size_type = int32_t
 
using element_type = void *
 

Public Member Functions

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 Member Functions

 LoanableCollection ()=default
 Default constructor.
 
virtual void resize (size_type new_length)=0
 

Protected Attributes

size_type maximum_ = 0
 
size_type length_ = 0
 
element_typeelements_ = nullptr
 
bool has_ownership_ = true
 

Detailed Description

A collection of generic opaque pointers that can receive the buffer from outside (loan).

This is an abstract class. See LoanableSequence for details.

Member Typedef Documentation

◆ element_type

using element_type = void*

◆ size_type

using size_type = int32_t

Constructor & Destructor Documentation

◆ LoanableCollection()

LoanableCollection ( )
protecteddefault

Default constructor.

Creates the loanable collection with no data.

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

Member Function Documentation

◆ buffer()

const element_type * buffer ( ) const
inline

Get the pointer to the elements buffer.

The returned value may be nullptr if maximum() is 0. Otherwise it is guaranteed that up to maximum() elements can be accessed.

Returns
the pointer to the elements buffer.

◆ has_ownership()

bool has_ownership ( ) const
inline

Get the ownership flag.

Returns
whether the collection has ownership of the buffer.

◆ length() [1/2]

size_type length ( ) const
inline

Get the number of elements currently accessible.

Returns
the number of elements currently accessible.

◆ length() [2/2]

bool length ( size_type  new_length)
inline

Set the number of elements currently accessible.

This method tells the collection that a certain number of elements should be accessible. If the new length is greater than the current maximum() the collection should allocate space for the new elements. If this is the case and the collection does not own the buffer (i.e. has_ownership() is false) then no allocation will be performed, the length will remain unchanged, and false will be returned.

Precondition
new_length >= 0
Parameters
[in]new_lengthNew number of elements to be accessible.
Returns
true if the new length was correctly set.
Postcondition
length() == new_length
maximum() >= new_length

◆ loan()

bool loan ( element_type buffer,
size_type  new_maximum,
size_type  new_length 
)
inline

Loan a buffer to the collection.

Parameters
[in]bufferpointer to the buffer to be loaned.
[in]new_maximumnumber of allocated elements in buffer.
[in]new_lengthnumber of accessible elements in buffer.
Precondition
(has_ownership() == false) || (maximum() == 0)
new_maximum > 0
new_maximum >= new_length
buffer != nullptr
Returns
false if preconditions are not met.
true if operation succeeds.
Postcondition
buffer() == buffer
has_ownership() == false
maximum() == new_maximum
length() == new_length

◆ maximum()

size_type maximum ( ) const
inline

Get the maximum number of elements currently allocated.

Returns
the maximum number of elements currently allocated.

◆ resize()

virtual void resize ( size_type  new_length)
protectedpure virtual

◆ unloan() [1/2]

element_type * unloan ( )
inline

Remove the loan from the collection.

Precondition
has_ownership() == false
Returns
nullptr if preconditions are not met.
pointer to the previously loaned buffer of elements.
Postcondition
buffer() == nullptr
has_ownership() == true
length() == 0
maximum() == 0

◆ unloan() [2/2]

element_type * unloan ( size_type maximum,
size_type length 
)
inline

Remove the loan from the collection.

Parameters
[out]maximumnumber of allocated elements on the returned buffer.
[out]lengthnumber of accessible elements on the returned buffer.
Precondition
has_ownership() == false
Returns
nullptr if preconditions are not met.
pointer to the previously loaned buffer of elements.
Postcondition
buffer() == nullptr
has_ownership() == true
length() == 0
maximum() == 0

Member Data Documentation

◆ elements_

element_type* elements_ = nullptr
protected

◆ has_ownership_

bool has_ownership_ = true
protected

◆ length_

size_type length_ = 0
protected

◆ maximum_

size_type maximum_ = 0
protected

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