rclcpp  master
C++ ROS Client Library API
Classes | Public Types | Public Member Functions | List of all members
rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc > Class Template Reference

Ring buffer container of shared_ptr's or unique_ptr's of T, which can be accessed by a key. More...

#include <mapped_ring_buffer.hpp>

Inheritance diagram for rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >:
Inheritance graph
[legend]
Collaboration diagram for rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >:
Collaboration graph
[legend]

Public Types

using ElemAllocTraits = allocator::AllocRebind< T, Alloc >
 
using ElemAlloc = typename ElemAllocTraits::allocator_type
 
using ElemDeleter = allocator::Deleter< ElemAlloc, T >
 
using ConstElemSharedPtr = std::shared_ptr< const T >
 
using ElemUniquePtr = std::unique_ptr< T, ElemDeleter >
 

Public Member Functions

 MappedRingBuffer (size_t size, std::shared_ptr< Alloc > allocator=nullptr)
 Constructor. More...
 
virtual ~MappedRingBuffer ()
 
void get (uint64_t key, ElemUniquePtr &value)
 Return a copy of the value stored in the ring buffer at the given key. More...
 
void get (uint64_t key, ConstElemSharedPtr &value)
 Share ownership of the value stored in the ring buffer at the given key. More...
 
void pop (uint64_t key, ElemUniquePtr &value)
 Give the ownership of the stored value to the caller if possible, or copy and release. More...
 
void pop (uint64_t key, ConstElemSharedPtr &value)
 Give the ownership of the stored value to the caller, at the given key. More...
 
bool push_and_replace (uint64_t key, ConstElemSharedPtr value)
 Insert a key-value pair, displacing an existing pair if necessary. More...
 
bool push_and_replace (uint64_t key, ElemUniquePtr value)
 Insert a key-value pair, displacing an existing pair if necessary. More...
 
bool has_key (uint64_t key)
 Return true if the key is found in the ring buffer, otherwise false. More...
 

Detailed Description

template<typename T, typename Alloc = std::allocator<void>>
class rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >

Ring buffer container of shared_ptr's or unique_ptr's of T, which can be accessed by a key.

T must be a CopyConstructable and CopyAssignable. This class can be used in a container by using the base class MappedRingBufferBase. This class must have a positive, non-zero size. This class cannot be resized nor can it reserve additional space after construction. This class is not CopyConstructable nor CopyAssignable.

The key's are not guaranteed to be unique because push_and_replace does not check for colliding keys. It is up to the user to only use unique keys. A side effect of this is that when get_copy_at_key or pop_at_key are called, they return the first encountered instance of the key. But iteration does not begin with the ring buffer's head, and therefore there is no guarantee on which value is returned if a key is used multiple times.

Member Typedef Documentation

◆ ElemAllocTraits

template<typename T , typename Alloc = std::allocator<void>>
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemAllocTraits = allocator::AllocRebind<T, Alloc>

◆ ElemAlloc

template<typename T , typename Alloc = std::allocator<void>>
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemAlloc = typename ElemAllocTraits::allocator_type

◆ ElemDeleter

template<typename T , typename Alloc = std::allocator<void>>
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemDeleter = allocator::Deleter<ElemAlloc, T>

◆ ConstElemSharedPtr

template<typename T , typename Alloc = std::allocator<void>>
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ConstElemSharedPtr = std::shared_ptr<const T>

◆ ElemUniquePtr

template<typename T , typename Alloc = std::allocator<void>>
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemUniquePtr = std::unique_ptr<T, ElemDeleter>

Constructor & Destructor Documentation

◆ MappedRingBuffer()

template<typename T , typename Alloc = std::allocator<void>>
rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::MappedRingBuffer ( size_t  size,
std::shared_ptr< Alloc >  allocator = nullptr 
)
inlineexplicit

Constructor.

The constructor will allocate memory while reserving space.

Parameters
sizesize of the ring buffer; must be positive and non-zero.
allocatoroptional custom allocator

◆ ~MappedRingBuffer()

template<typename T , typename Alloc = std::allocator<void>>
virtual rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::~MappedRingBuffer ( )
inlinevirtual

Member Function Documentation

◆ get() [1/2]

template<typename T , typename Alloc = std::allocator<void>>
void rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::get ( uint64_t  key,
ElemUniquePtr value 
)
inline

Return a copy of the value stored in the ring buffer at the given key.

The key is matched if an element in the ring buffer has a matching key. This method will allocate in order to return a copy.

The key is not guaranteed to be unique, see the class docs for more.

The contents of value before the method is called are discarded.

Parameters
keythe key associated with the stored value
valueif the key is found, the value is stored in this parameter

◆ get() [2/2]

template<typename T , typename Alloc = std::allocator<void>>
void rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::get ( uint64_t  key,
ConstElemSharedPtr value 
)
inline

Share ownership of the value stored in the ring buffer at the given key.

The key is matched if an element in the ring buffer has a matching key.

The key is not guaranteed to be unique, see the class docs for more.

The contents of value before the method is called are discarded.

Parameters
keythe key associated with the stored value
valueif the key is found, the value is stored in this parameter

◆ pop() [1/2]

template<typename T , typename Alloc = std::allocator<void>>
void rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::pop ( uint64_t  key,
ElemUniquePtr value 
)
inline

Give the ownership of the stored value to the caller if possible, or copy and release.

The key is matched if an element in the ring buffer has a matching key. This method may allocate in order to return a copy.

If the stored value is a shared_ptr, it is not possible to downgrade it to a unique_ptr. In that case, a copy is returned and the stored value is released.

The key is not guaranteed to be unique, see the class docs for more.

The contents of value before the method is called are discarded.

Parameters
keythe key associated with the stored value
valueif the key is found, the value is stored in this parameter

◆ pop() [2/2]

template<typename T , typename Alloc = std::allocator<void>>
void rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::pop ( uint64_t  key,
ConstElemSharedPtr value 
)
inline

Give the ownership of the stored value to the caller, at the given key.

The key is matched if an element in the ring buffer has a matching key.

The key is not guaranteed to be unique, see the class docs for more.

The contents of value before the method is called are discarded.

Parameters
keythe key associated with the stored value
valueif the key is found, the value is stored in this parameter

◆ push_and_replace() [1/2]

template<typename T , typename Alloc = std::allocator<void>>
bool rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::push_and_replace ( uint64_t  key,
ConstElemSharedPtr  value 
)
inline

Insert a key-value pair, displacing an existing pair if necessary.

The key's uniqueness is not checked on insertion. It is up to the user to ensure the key is unique. This method should not allocate memory.

After insertion the value will be a nullptr. If a pair were replaced, its smart pointer is reset.

Parameters
keythe key associated with the value to be stored
valuethe value to store, and optionally the value displaced

◆ push_and_replace() [2/2]

template<typename T , typename Alloc = std::allocator<void>>
bool rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::push_and_replace ( uint64_t  key,
ElemUniquePtr  value 
)
inline

Insert a key-value pair, displacing an existing pair if necessary.

See bool push_and_replace(uint64_t key, const ConstElemSharedPtr & value).

◆ has_key()

template<typename T , typename Alloc = std::allocator<void>>
bool rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::has_key ( uint64_t  key)
inline

Return true if the key is found in the ring buffer, otherwise false.


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