OpenRTM-aist  1.2.1
Classes | Public Member Functions | Public Attributes | List of all members
RTC::RingBuffer< DataType > Class Template Reference

Ring buffer implementation class. More...

#include <RingBuffer.h>

Inheritance diagram for RTC::RingBuffer< DataType >:
Inheritance graph
[legend]
Collaboration diagram for RTC::RingBuffer< DataType >:
Collaboration graph
[legend]

Public Member Functions

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

Public Attributes

BUFFERSTATUS_ENUM typedef coil::Guard< coil::MutexGuard
 

Additional Inherited Members

- Public Types inherited from RTC::BufferStatus
enum  Enum {
  BUFFER_OK = 0, BUFFER_ERROR, BUFFER_FULL, BUFFER_EMPTY,
  NOT_SUPPORTED, TIMEOUT, PRECONDITION_NOT_MET
}
 DataPortStatus return codes. More...
 
- Static Public Member Functions inherited from RTC::BufferStatus
static const char * toString (Enum status)
 Convert BufferStatus into the string. More...
 

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

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

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().

template<class DataType >
virtual RTC::RingBuffer< DataType >::~RingBuffer ( void  )
inlinevirtual

Virtual destractor.

Virtual destractor

Member Function Documentation

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

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

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

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

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

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

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

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

template<class DataType >
virtual bool RTC::RingBuffer< DataType >::empty ( void  ) const
inlinevirtual

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 >.

References RTC::RingBuffer< DataType >::length(), coil::normalize(), and coil::stringTo().

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

template<class DataType >
virtual bool RTC::RingBuffer< DataType >::full ( void  ) const
inlinevirtual

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().

template<class DataType >
virtual ReturnCode RTC::RingBuffer< DataType >::get ( DataType &  value)
inlinevirtual

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 >.

template<class DataType >
virtual DataType& RTC::RingBuffer< DataType >::get ( void  )
inlinevirtual

Reading data from the buffer.

Returns
Read data

Implements RTC::BufferBase< DataType >.

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

Set the buffer.

Implements RTC::BufferBase< DataType >.

template<class DataType >
virtual size_t RTC::RingBuffer< DataType >::length ( void  ) const
inlinevirtual

Get the buffer length.

Get the buffer length.

Returns
Buffer length

Implements RTC::BufferBase< DataType >.

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

template<class DataType >
virtual ReturnCode RTC::RingBuffer< DataType >::length ( size_t  n)
inlinevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

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

template<class DataType >
virtual ReturnCode RTC::RingBuffer< DataType >::put ( const DataType &  value)
inlinevirtual

Write data into the buffer.

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

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

Implements RTC::BufferBase< DataType >.

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

template<class DataType >
virtual ReturnCode RTC::RingBuffer< DataType >::read ( DataType &  value,
long int  sec = -1,
long int  nsec = 0 
)
inlinevirtual

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::RingBuffer< DataType >::empty(), coil::TimeValue::sec(), and coil::TimeValue::usec().

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

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 >.

template<class DataType >
virtual ReturnCode RTC::RingBuffer< DataType >::reset ( )
inlinevirtual

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

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

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

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

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

Get the buffer length.

Pure virtual function to get the buffer length.

Returns
buffer length

Implements RTC::BufferBase< DataType >.

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

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 >.

template<class DataType >
virtual ReturnCode RTC::RingBuffer< DataType >::write ( const DataType &  value,
long int  sec = -1,
long int  nsec = 0 
)
inlinevirtual

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::RingBuffer< DataType >::full(), RTC::RingBuffer< DataType >::put(), coil::TimeValue::sec(), and coil::TimeValue::usec().

Member Data Documentation

template<class DataType >
BUFFERSTATUS_ENUM typedef coil::Guard<coil::Mutex> RTC::RingBuffer< DataType >::Guard

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