OpenRTM-aist 2.0.2
Loading...
Searching...
No Matches
RTC::RingBuffer< DataType > Class Template Reference

Ring buffer implementation class. More...

#include <RingBuffer.h>

Inheritance diagram for RTC::RingBuffer< DataType >:
Collaboration diagram for RTC::RingBuffer< DataType >:

Public Member Functions

 RingBuffer (long int length=RINGBUFFER_DEFAULT_LENGTH)
 Constructor.
 
 ~RingBuffer () override
 Virtual destractor.
 
void init (const coil::Properties &prop) override
 
size_t length () const override
 Get the buffer length.
 
BufferStatus length (size_t n) override
 Get the buffer length.
 
BufferStatus reset () override
 Get the buffer length.
 
DataType * wptr (long int n=0) override
 Get the buffer length.
 
BufferStatus advanceWptr (long int n=1, bool unlock_enable=true) override
 Get the buffer length.
 
BufferStatus put (const DataType &value) override
 Write data into the buffer.
 
BufferStatus write (const DataType &value, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1)) override
 Write data into the buffer.
 
size_t writable () const override
 Write data into the buffer.
 
bool full () const override
 Check on whether the buffer is full.
 
DataType * rptr (long int n=0) override
 Get the buffer length.
 
BufferStatus advanceRptr (long int n=1, bool unlock_enable=true) override
 Get the buffer length.
 
BufferStatus get (DataType &value) override
 Write data into the buffer.
 
DataType & get () override
 Reading data from the buffer.
 
BufferStatus read (DataType &value, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1)) override
 Readout data from the buffer.
 
size_t readable () const override
 Write data into the buffer.
 
bool empty () const override
 Check on whether the buffer is empty.
 
- Public Member Functions inherited from RTC::BufferBase< DataType >
virtual ~BufferBase ()=default
 Virtual destructor.
 

Detailed Description

template<class DataType>
class RTC::RingBuffer< DataType >

Ring buffer implementation class.

This is the buffer implementation class with ring shaped buffer of specified length. If data is stored in the entire buffer, data from now on will be overwritten from old data one by one. Therefore, only the length of latest data is stored in the buffer.

Note: In the current implementation, only last stored data can be read from the buffer.

Parameters
DataTypeData type to store in the buffer
Since
0.4.0

Constructor & Destructor Documentation

◆ RingBuffer()

template<class DataType >
RTC::RingBuffer< DataType >::RingBuffer ( long int length = RINGBUFFER_DEFAULT_LENGTH)
inlineexplicit

Constructor.

Constructor. Initialize the buffer by specified buffer length. However, if the specified length is less than two, the buffer should be initialized by two in length.

Parameters
lengthBuffer length

References RTC::RingBuffer< DataType >::reset().

◆ ~RingBuffer()

template<class T >
RTC::RingBuffer< T >::~RingBuffer ( )
overridedefault

Virtual destractor.

Virtual destractor

Member Function Documentation

◆ advanceRptr()

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::advanceRptr ( long int n = 1,
bool unlock_enable = true )
inlineoverridevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

References RTC::RingBuffer< DataType >::full(), RTC::OK, and RTC::PRECONDITION_NOT_MET.

Referenced by RTC::RingBuffer< DataType >::read(), and RTC::RingBuffer< DataType >::write().

◆ advanceWptr()

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::advanceWptr ( long int n = 1,
bool unlock_enable = true )
inlineoverridevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

References RTC::RingBuffer< DataType >::empty(), RTC::OK, and RTC::PRECONDITION_NOT_MET.

Referenced by RTC::RingBuffer< DataType >::write().

◆ empty()

template<class DataType >
bool RTC::RingBuffer< DataType >::empty ( ) const
inlineoverridevirtual

Check on whether the buffer is empty.

Pure virtual function to check on whether the buffer is empty.

Returns
True if the buffer is empty, else false.

Implements RTC::BufferBase< DataType >.

Referenced by RTC::RingBuffer< DataType >::advanceWptr(), and RTC::RingBuffer< DataType >::read().

◆ full()

template<class DataType >
bool RTC::RingBuffer< DataType >::full ( ) const
inlineoverridevirtual

Check on whether the buffer is full.

Pure virtual function to check on whether the buffer is full.

Returns
True if the buffer is full, else false.

Implements RTC::BufferBase< DataType >.

Referenced by RTC::RingBuffer< DataType >::advanceRptr(), and RTC::RingBuffer< DataType >::write().

◆ get() [1/2]

template<class DataType >
DataType & RTC::RingBuffer< DataType >::get ( )
inlineoverridevirtual

Reading data from the buffer.

Returns
Read data

Implements RTC::BufferBase< DataType >.

Referenced by RTC::RingBuffer< DataType >::read().

◆ get() [2/2]

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::get ( DataType & value)
inlineoverridevirtual

Write data into the buffer.

Pure virtual function to write data into the buffer.

Parameters
valueTarget data to write.
Returns
Result of having written in data (true:Successful, false:Failed)

Implements RTC::BufferBase< DataType >.

References RTC::OK.

◆ init()

template<class DataType >
void RTC::RingBuffer< DataType >::init ( const coil::Properties & prop)
inlineoverridevirtual

◆ length() [1/2]

template<class DataType >
size_t RTC::RingBuffer< DataType >::length ( ) const
inlineoverridevirtual

Get the buffer length.

Get the buffer length.

Returns
Buffer length

Implements RTC::BufferBase< DataType >.

◆ length() [2/2]

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::length ( size_t n)
inlineoverridevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

References RTC::OK, and RTC::RingBuffer< DataType >::reset().

◆ put()

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::put ( const DataType & value)
inlineoverridevirtual

Write data into the buffer.

Pure virtual function to write data into the buffer. Always OK will be returned in this implementation.

Parameters
valueTarget data to write.
Returns
OK: Successful BUFFER_ERROR: Failed

Implements RTC::BufferBase< DataType >.

References RTC::OK.

Referenced by RTC::RingBuffer< DataType >::write().

◆ read()

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::read ( DataType & value,
std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1) )
inlineoverridevirtual

Readout data from the buffer.

Readout data stored into the buffer.

Parameters
valueReadout data
Returns
Readout result (Always true: readout success is returned)

Implements RTC::BufferBase< DataType >.

References RTC::RingBuffer< DataType >::advanceRptr(), RTC::EMPTY, RTC::RingBuffer< DataType >::empty(), RTC::RingBuffer< DataType >::get(), RTC::OK, RTC::PRECONDITION_NOT_MET, and RTC::TIMEOUT.

◆ readable()

template<class DataType >
size_t RTC::RingBuffer< DataType >::readable ( ) const
inlineoverridevirtual

Write data into the buffer.

Pure virtual function to write data into the buffer.

Parameters
valueTarget data to write.
Returns
Result of having written in data (true:Successful, false:Failed)

Implements RTC::BufferBase< DataType >.

◆ reset()

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::reset ( )
inlineoverridevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

References RTC::OK.

Referenced by RTC::RingBuffer< DataType >::length(), and RTC::RingBuffer< DataType >::RingBuffer().

◆ rptr()

template<class DataType >
DataType * RTC::RingBuffer< DataType >::rptr ( long int n = 0)
inlineoverridevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

◆ wptr()

template<class DataType >
DataType * RTC::RingBuffer< DataType >::wptr ( long int n = 0)
inlineoverridevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

◆ writable()

template<class DataType >
size_t RTC::RingBuffer< DataType >::writable ( ) const
inlineoverridevirtual

Write data into the buffer.

Pure virtual function to write data into the buffer.

Parameters
valueTarget data to write.
Returns
Result of having written in data (true:Successful, false:Failed)

Implements RTC::BufferBase< DataType >.

◆ write()

template<class DataType >
BufferStatus RTC::RingBuffer< DataType >::write ( const DataType & value,
std::chrono::nanoseconds timeout = std::chrono::nanoseconds(-1) )
inlineoverridevirtual

Write data into the buffer.

Write data which is given argument into the buffer.

Parameters
valueTarget data for writing
Returns
Writing result (Always true: writing success is returned)

Implements RTC::BufferBase< DataType >.

References RTC::RingBuffer< DataType >::advanceRptr(), RTC::RingBuffer< DataType >::advanceWptr(), RTC::FULL, RTC::RingBuffer< DataType >::full(), RTC::OK, RTC::PRECONDITION_NOT_MET, RTC::RingBuffer< DataType >::put(), and RTC::TIMEOUT.


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