rclcpp
master
C++ ROS Client Library API
|
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>
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... | |
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.
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemAllocTraits = allocator::AllocRebind<T, Alloc> |
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemAlloc = typename ElemAllocTraits::allocator_type |
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemDeleter = allocator::Deleter<ElemAlloc, T> |
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ConstElemSharedPtr = std::shared_ptr<const T> |
using rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >::ElemUniquePtr = std::unique_ptr<T, ElemDeleter> |
|
inlineexplicit |
Constructor.
The constructor will allocate memory while reserving space.
size | size of the ring buffer; must be positive and non-zero. |
allocator | optional custom allocator |
|
inlinevirtual |
|
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.
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
|
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.
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
|
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.
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
|
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.
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
|
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.
key | the key associated with the value to be stored |
value | the value to store, and optionally the value displaced |
|
inline |
Insert a key-value pair, displacing an existing pair if necessary.
See bool push_and_replace(uint64_t key, const ConstElemSharedPtr & value)
.
|
inline |
Return true if the key is found in the ring buffer, otherwise false.