template<typename T, typename Alloc = std::allocator<void>>
class rclcpp::mapped_ring_buffer::MappedRingBuffer< T, Alloc >
Ring buffer container of 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.
template<typename T , typename Alloc = std::allocator<void>>
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
-
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
template<typename T , typename Alloc = std::allocator<void>>
Return ownership of the value stored in the ring buffer, leaving a copy.
The key is matched if an element in the ring bufer has a matching key. This method will allocate in order to store a copy.
The key is not guaranteed to be unique, see the class docs for more.
The ownership of the currently stored object is returned, but a copy is made and stored in its place. This means that multiple calls to this function for a particular element will result in returning the copied and stored object not the original. This also means that later calls to pop_at_key will not return the originally stored object, since it was returned by the first call to this method.
The contents of value before the method is called are discarded.
- Parameters
-
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
template<typename T , typename Alloc = std::allocator<void>>
Return 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
-
key | the key associated with the stored value |
value | if the key is found, the value is stored in this parameter |
template<typename T , typename Alloc = std::allocator<void>>
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, if a pair was replaced, then value will contain ownership of that displaced value. Otherwise it will be a nullptr.
- Parameters
-
key | the key associated with the value to be stored |
value | the value to store, and optionally the value displaced |