rclcpp
master
C++ ROS Client Library API
|
Go to the documentation of this file.
15 #ifndef RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_
16 #define RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_
35 namespace experimental
44 template<
typename BufferT>
49 : capacity_(capacity),
50 ring_buffer_(capacity),
51 write_index_(capacity_ - 1),
72 write_index_ = next_(write_index_);
73 ring_buffer_[write_index_] =
std::move(request);
76 read_index_ = next_(read_index_);
97 auto request =
std::move(ring_buffer_[read_index_]);
98 read_index_ = next_(read_index_);
153 inline size_t next_(
size_t val)
155 return (val + 1) % capacity_;
164 inline bool has_data_()
const
176 inline bool is_full_()
const
178 return size_ == capacity_;
196 #endif // RCLCPP__EXPERIMENTAL__BUFFERS__RING_BUFFER_IMPLEMENTATION_HPP_
void enqueue(BufferT request)
Add a new element to store in the ring buffer.
Definition: ring_buffer_implementation.hpp:68
RingBufferImplementation(size_t capacity)
Definition: ring_buffer_implementation.hpp:48
bool has_data() const
Get if the ring buffer has at least one element stored.
Definition: ring_buffer_implementation.hpp:124
Logger get_logger(const std::string &name)
Return a named logger.
BufferT dequeue()
Remove the oldest element from ring buffer.
Definition: ring_buffer_implementation.hpp:88
virtual ~RingBufferImplementation()
Definition: ring_buffer_implementation.hpp:60
Store elements in a fixed-size, FIFO buffer.
Definition: ring_buffer_implementation.hpp:45
size_t next(size_t val)
Get the next index value for the ring buffer.
Definition: ring_buffer_implementation.hpp:112
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
bool is_full() const
Get if the size of the buffer is equal to its capacity.
Definition: ring_buffer_implementation.hpp:137
void clear()
Definition: ring_buffer_implementation.hpp:143
Definition: buffer_implementation_base.hpp:26
#define RCLCPP_ERROR(logger,...)
Definition: logging.hpp:1398