Fast RTPS  Version 2.7.0
Fast RTPS
ResourceLimitedVector< _Ty, _KeepOrderEnabler, _LimitsConfig, _Alloc, _Collection > Class Template Reference

Resource limited wrapper of std::vector. More...

#include <ResourceLimitedVector.hpp>

Public Types

using configuration_type = _LimitsConfig
 
using collection_type = _Collection
 
using value_type = _Ty
 
using allocator_type = _Alloc
 
using pointer = typename collection_type::pointer
 
using const_pointer = typename collection_type::const_pointer
 
using reference = typename collection_type::reference
 
using const_reference = typename collection_type::const_reference
 
using size_type = typename collection_type::size_type
 
using difference_type = typename collection_type::difference_type
 
using iterator = typename collection_type::iterator
 
using const_iterator = typename collection_type::const_iterator
 
using reverse_iterator = typename collection_type::reverse_iterator
 
using const_reverse_iterator = typename collection_type::const_reverse_iterator
 

Public Member Functions

 ResourceLimitedVector (configuration_type cfg=configuration_type(), const allocator_type &alloc=allocator_type())
 Construct a ResourceLimitedVector. More...
 
 ResourceLimitedVector (const ResourceLimitedVector &other)
 
virtual ~ResourceLimitedVector ()=default
 
ResourceLimitedVectoroperator= (const ResourceLimitedVector &other)
 
iterator insert (const_iterator pos, const value_type &value)
 Insert value before pos. More...
 
iterator insert (const_iterator pos, value_type &&value)
 Insert value before pos. More...
 
pointer push_back (const value_type &val)
 Add element at the end. More...
 
pointer push_back (value_type &&val)
 Add element at the end. More...
 
template<typename ... Args>
pointer emplace_back (Args &&... args)
 Construct and insert element at the end. More...
 
bool remove (const value_type &val)
 Remove element. More...
 
template<class UnaryPredicate >
bool remove_if (UnaryPredicate pred)
 Remove element. More...
 
template<class InputIterator >
void assign (InputIterator first, InputIterator last)
 Assign vector content. More...
 
void assign (size_type n, const value_type &val)
 Assign vector content. More...
 
void assign (std::initializer_list< value_type > il)
 Assign vector content. More...
 
 operator const collection_type & () const noexcept
 Const cast to underlying collection. More...
 
reference at (size_type pos)
 Wrappers to other basic vector methods. More...
 
const_reference at (size_type pos) const
 
reference operator[] (size_type pos)
 
const_reference operator[] (size_type pos) const
 
reference front ()
 
const_reference front () const
 
reference back ()
 
const_reference back () const
 
iterator begin () noexcept
 
const_iterator begin () const noexcept
 
const_iterator cbegin () const noexcept
 
iterator end () noexcept
 
const_iterator end () const noexcept
 
const_iterator cend () const noexcept
 
reverse_iterator rbegin () noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
reverse_iterator rend () noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crend () const noexcept
 
bool empty () const noexcept
 
size_type size () const noexcept
 
size_type capacity () const noexcept
 
size_type max_size () const noexcept
 
void clear ()
 
iterator erase (const_iterator pos)
 
iterator erase (const_iterator first, const_iterator last)
 
void pop_back ()
 
value_typedata ()
 
const value_typedata () const
 

Protected Member Functions

bool ensure_capacity ()
 Make room for one item. More...
 
template<typename Enabler = _KeepOrderEnabler>
std::enable_if<!Enabler::value, void >::type do_remove (iterator it)
 Remove element. More...
 
template<typename Enabler = _KeepOrderEnabler>
std::enable_if< Enabler::value, void >::type do_remove (iterator it)
 Remove element. More...
 

Protected Attributes

configuration_type configuration_
 
collection_type collection_
 

Detailed Description

template<typename _Ty, typename _KeepOrderEnabler = std::false_type, typename _LimitsConfig = ResourceLimitedContainerConfig, typename _Alloc = std::allocator<_Ty>, typename _Collection = std::vector<_Ty, _Alloc>>
class eprosima::fastrtps::ResourceLimitedVector< _Ty, _KeepOrderEnabler, _LimitsConfig, _Alloc, _Collection >

Resource limited wrapper of std::vector.

This template class holds an unordered collection of elements using a std::vector or a replacement. It makes use of a ResourceLimitedContainerConfig to setup the allocation behaviour regarding the number of elements in the collection.

It features linear increment of the capacity, initial preallocation, and maximum number of elements control.

Template Parameters
_TyElement type.
_KeepOrderEnablerIndicates if element order should be kept when removing items, defaults to std::false_type.
_LimitsConfigType defining the resource limits configuration, defaults to ResourceLimitedContainerConfig
_AllocAllocator to use on the underlying collection type, defaults to std::allocator<_Ty>.
_CollectionType used to store the collection of items, defaults to std::vector<_Ty, _Alloc>.

Member Typedef Documentation

◆ allocator_type

using allocator_type = _Alloc

◆ collection_type

using collection_type = _Collection

◆ configuration_type

using configuration_type = _LimitsConfig

◆ const_iterator

using const_iterator = typename collection_type::const_iterator

◆ const_pointer

using const_pointer = typename collection_type::const_pointer

◆ const_reference

using const_reference = typename collection_type::const_reference

◆ const_reverse_iterator

using const_reverse_iterator = typename collection_type::const_reverse_iterator

◆ difference_type

using difference_type = typename collection_type::difference_type

◆ iterator

using iterator = typename collection_type::iterator

◆ pointer

using pointer = typename collection_type::pointer

◆ reference

using reference = typename collection_type::reference

◆ reverse_iterator

using reverse_iterator = typename collection_type::reverse_iterator

◆ size_type

using size_type = typename collection_type::size_type

◆ value_type

using value_type = _Ty

Constructor & Destructor Documentation

◆ ResourceLimitedVector() [1/2]

Construct a ResourceLimitedVector.

This constructor receives a ResourceLimitedContainerConfig to setup the allocation behaviour regarding the number of elements in the collection.

The cfg parameter indicates the initial number to be reserved, the maximum number of items allowed, and the capacity increment value.

Parameters
cfgResource limits configuration to use.
allocAllocator object. Forwarded to collection constructor.

◆ ResourceLimitedVector() [2/2]

ResourceLimitedVector ( const ResourceLimitedVector< _Ty, _KeepOrderEnabler, _LimitsConfig, _Alloc, _Collection > &  other)
inline

◆ ~ResourceLimitedVector()

virtual ~ResourceLimitedVector ( )
virtualdefault

Member Function Documentation

◆ assign() [1/3]

void assign ( InputIterator  first,
InputIterator  last 
)
inline

Assign vector content.

Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.

Parameters
first,lastInput iterators to the initial and final positions in a sequence. The range used is [first,last), which includes all the elements between first and last, including the element pointed by first but not the element pointed by last. The function template argument InputIterator shall be an input iterator type that points to elements of a type from which value_type objects can be constructed. If the size of this range is greater than the maximum number of elements allowed on the resource limits configuration, the elements exceeding that maximum will be silently discarded.

◆ assign() [2/3]

void assign ( size_type  n,
const value_type val 
)
inline

Assign vector content.

Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.

Parameters
nNew size for the container. Will be truncated if greater than the maximum allowed on the resource limits configuration.
valValue to fill the container with. Each of the n elements in the container will be initialized to a copy of this value.

◆ assign() [3/3]

void assign ( std::initializer_list< value_type il)
inline

Assign vector content.

Assigns new contents to the vector, replacing its current contents, and modifying its size accordingly.

Parameters
ilAn initializer_list object. The compiler will automatically construct such objects from initializer list declarators. Member type value_type is the type of the elements in the container. If the size of this list is greater than the maximum number of elements allowed on the resource limits configuration, the elements exceeding that maximum will be silently discarded.

◆ at() [1/2]

reference at ( size_type  pos)
inline

Wrappers to other basic vector methods.

Please refer to https://en.cppreference.com/w/cpp/container/vector

◆ at() [2/2]

const_reference at ( size_type  pos) const
inline

◆ back() [1/2]

reference back ( )
inline

◆ back() [2/2]

const_reference back ( ) const
inline

◆ begin() [1/2]

const_iterator begin ( ) const
inlinenoexcept

◆ begin() [2/2]

iterator begin ( )
inlinenoexcept

◆ capacity()

size_type capacity ( ) const
inlinenoexcept

◆ cbegin()

const_iterator cbegin ( ) const
inlinenoexcept

◆ cend()

const_iterator cend ( ) const
inlinenoexcept

◆ clear()

void clear ( )
inline

◆ crbegin()

const_reverse_iterator crbegin ( ) const
inlinenoexcept

◆ crend()

const_reverse_iterator crend ( ) const
inlinenoexcept

◆ data() [1/2]

value_type* data ( )
inline

◆ data() [2/2]

const value_type* data ( ) const
inline

◆ do_remove() [1/2]

std::enable_if<!Enabler::value, void>::type do_remove ( iterator  it)
inlineprotected

Remove element.

Removes the element pointed to by it. All iterators may become invalidated. This version doesn't keep the order of insertion, optimizing the number of copies performed.

Parameters
itIterator pointing to the item to be removed.

◆ do_remove() [2/2]

std::enable_if<Enabler::value, void>::type do_remove ( iterator  it)
inlineprotected

Remove element.

Removes the element pointed to by it. All iterators may become invalidated. This version keeps the order of insertion, so when removing an item different from the last one, part of the collection will be copied.

Parameters
itIterator pointing to the item to be removed.

◆ emplace_back()

pointer emplace_back ( Args &&...  args)
inline

Construct and insert element at the end.

Inserts a new element at the end of the vector, right after its current last element. This new element is constructed in place using args as the arguments for its constructor.

Parameters
argsArguments forwarded to construct the new element.
Returns
pointer to the new element, nullptr if resource limit is reached.

◆ empty()

bool empty ( ) const
inlinenoexcept

◆ end() [1/2]

const_iterator end ( ) const
inlinenoexcept

◆ end() [2/2]

iterator end ( )
inlinenoexcept

◆ ensure_capacity()

bool ensure_capacity ( )
inlineprotected

Make room for one item.

Tries to ensure that a new item can be added to the container.

Returns
true if there is room for a new item, false if resource limit is reached.

◆ erase() [1/2]

iterator erase ( const_iterator  first,
const_iterator  last 
)
inline

◆ erase() [2/2]

iterator erase ( const_iterator  pos)
inline

◆ front() [1/2]

reference front ( )
inline

◆ front() [2/2]

const_reference front ( ) const
inline

◆ insert() [1/2]

iterator insert ( const_iterator  pos,
const value_type value 
)
inline

Insert value before pos.

Parameters
positerator before which the content will be inserted. pos may be the end() iterator.
valueelement value to insert.
Returns
Iterator pointing to the inserted value. end() if insertion couldn't be done due to collection limits.

◆ insert() [2/2]

iterator insert ( const_iterator  pos,
value_type &&  value 
)
inline

Insert value before pos.

Parameters
positerator before which the content will be inserted. pos may be the end() iterator.
valueelement value to insert.
Returns
Iterator pointing to the inserted value. end() if insertion couldn't be done due to collection limits.

◆ max_size()

size_type max_size ( ) const
inlinenoexcept

◆ operator const collection_type &()

operator const collection_type & ( ) const
inlinenoexcept

Const cast to underlying collection.

Useful to easy integration on old APIs where a traditional container was used.

Returns
const reference to the underlying collection.

◆ operator=()

ResourceLimitedVector& operator= ( const ResourceLimitedVector< _Ty, _KeepOrderEnabler, _LimitsConfig, _Alloc, _Collection > &  other)
inline

◆ operator[]() [1/2]

reference operator[] ( size_type  pos)
inline

◆ operator[]() [2/2]

const_reference operator[] ( size_type  pos) const
inline

◆ pop_back()

void pop_back ( )
inline

◆ push_back() [1/2]

pointer push_back ( const value_type val)
inline

Add element at the end.

Adds a new element at the end of the vector, after its current last element. The content of val is copied to the new element.

Parameters
valValue to be copied to the new element.
Returns
pointer to the new element, nullptr if resource limit is reached.

◆ push_back() [2/2]

pointer push_back ( value_type &&  val)
inline

Add element at the end.

Adds a new element at the end of the vector, after its current last element. The content of val is moved to the new element.

Parameters
valValue to be moved to the new element.
Returns
pointer to the new element, nullptr if resource limit is reached.

◆ rbegin() [1/2]

const_reverse_iterator rbegin ( ) const
inlinenoexcept

◆ rbegin() [2/2]

reverse_iterator rbegin ( )
inlinenoexcept

◆ remove()

bool remove ( const value_type val)
inline

Remove element.

Removes the first element in the vector that compares equal to val. All iterators may become invalidated if this method returns true.

Parameters
valValue to be compared.
Returns
true if an element was removed, false otherwise.

◆ remove_if()

bool remove_if ( UnaryPredicate  pred)
inline

Remove element.

Removes the first element in the vector for which pred returns true. All iterators may become invalidated if this method returns true.

Parameters
predUnary function that accepts an element in the range as argument and returns a value convertible to bool. The value returned indicates whether the element is considered a match in the context of this function. The function shall not modify its argument. This can either be a function pointer or a function object.
Returns
true if an element was removed, false otherwise.

◆ rend() [1/2]

const_reverse_iterator rend ( ) const
inlinenoexcept

◆ rend() [2/2]

reverse_iterator rend ( )
inlinenoexcept

◆ size()

size_type size ( ) const
inlinenoexcept

Member Data Documentation

◆ collection_

collection_type collection_
protected

◆ configuration_

configuration_type configuration_
protected

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