OpenRTM-aist 2.0.2
Loading...
Searching...
No Matches
BufferBase.h
Go to the documentation of this file.
1// -*- C++ -*-
20#ifndef RTC_BUFFERBASE_H
21#define RTC_BUFFERBASE_H
22
23#include <cstddef>
24#include <coil/Properties.h>
25#include <rtm/BufferStatus.h>
26#include <chrono>
27
42namespace RTC
43{
104 template <class DataType>
106 {
107 public:
108
120 virtual ~BufferBase() = default;
121
133 virtual void init(const coil::Properties& prop) = 0;
134
154 virtual size_t length() const = 0;
155
180 virtual BufferStatus length(size_t n) = 0;
181
205 virtual BufferStatus reset() = 0;
206
207
208 //----------------------------------------------------------------------
230 virtual DataType* wptr(long int n = 0) = 0;
231
254 virtual BufferStatus advanceWptr(long int n = 1, bool unlock_enable = true) = 0;
255
281 virtual BufferStatus put(const DataType& value) = 0;
282
308 virtual BufferStatus write(const DataType& value,
309 std::chrono::nanoseconds timeout
310 = std::chrono::nanoseconds(-1)) = 0;
311
333 virtual size_t writable() const = 0;
334
354 virtual bool full() const = 0;
355
356 //----------------------------------------------------------------------
377 virtual DataType* rptr(long int n = 0) = 0;
378
401 virtual BufferStatus advanceRptr(long int n = 1, bool unlock_enable = true) = 0;
402
428 virtual BufferStatus get(DataType& value) = 0;
429
449 virtual DataType& get() = 0;
450
474 virtual BufferStatus read(DataType& value,
475 std::chrono::nanoseconds nsec
476 = std::chrono::nanoseconds(-1)) = 0;
477
499 virtual size_t readable() const = 0;
500
520 virtual bool empty() const = 0;
521
522 };
523
550 template <class DataType>
552 : public BufferBase<DataType>
553 {
554 public:
576 explicit NullBuffer(long int size = 1)
577 : m_length(size)
578 {
579 }
580
596 virtual ~NullBuffer() = default;
597
617 virtual long int length() const
618 {
619 return 1;
620 }
621
645 virtual bool write(const DataType& value)
646 {
647 m_data = value;
648 return true;
649 }
650
674 virtual bool read(DataType& value)
675 {
676 value = m_data;
677 return true;
678 }
679
699 virtual bool isFull() const
700 {
701 return false;
702 }
703
723 virtual bool isEmpty() const
724 {
725 return false;
726 }
727
728 protected:
748 virtual void put(const DataType& data)
749 {
750 m_data = data;
751 }
752
772 virtual const DataType& get()
773 {
774 return m_data;
775 }
776
799 virtual DataType& getRef()
800 {
801 return m_data;
802 }
803
804 private:
805 DataType m_data;
806 long int m_length;
807 };
808} // namespace RTC
809#endif // BufferBase_h
Buffer status enum definition.
BufferBase abstract class.
Definition BufferBase.h:106
virtual size_t writable() const =0
Get a writable number.
virtual BufferStatus advanceRptr(long int n=1, bool unlock_enable=true)=0
Forward n reading pointers.
virtual BufferStatus put(const DataType &value)=0
Write data into the buffer.
virtual size_t length() const =0
Get the buffer length.
virtual BufferStatus get(DataType &value)=0
Read data from the buffer.
virtual DataType & get()=0
Read data from the buffer.
virtual ~BufferBase()=default
Virtual destructor.
virtual void init(const coil::Properties &prop)=0
Set the buffer.
virtual BufferStatus reset()=0
Reset the buffer status.
virtual size_t readable() const =0
Write data into the buffer.
virtual BufferStatus read(DataType &value, std::chrono::nanoseconds nsec=std::chrono::nanoseconds(-1))=0
Read data from the buffer.
virtual BufferStatus length(size_t n)=0
Set the buffer length.
virtual BufferStatus write(const DataType &value, std::chrono::nanoseconds timeout=std::chrono::nanoseconds(-1))=0
Write data into the buffer.
virtual DataType * wptr(long int n=0)=0
Get the writing pointer.
virtual bool full() const =0
Check on whether the buffer is full.
virtual DataType * rptr(long int n=0)=0
Get the reading pointer.
virtual bool empty() const =0
Check on whether the buffer is empty.
virtual BufferStatus advanceWptr(long int n=1, bool unlock_enable=true)=0
Forward n writing pointers.
Concrete buffer class for dummy.
Definition BufferBase.h:553
virtual void put(const DataType &data)
Store data into the buffer.
Definition BufferBase.h:748
virtual bool isFull() const
Check on whether the buffer is full.
Definition BufferBase.h:699
virtual const DataType & get()
Get data from the buffer.
Definition BufferBase.h:772
virtual long int length() const
Get the buffer length (always 1)
Definition BufferBase.h:617
virtual ~NullBuffer()=default
Destructor.
virtual DataType & getRef()
Get the buffer's reference to be written the next.
Definition BufferBase.h:799
NullBuffer(long int size=1)
Constructer.
Definition BufferBase.h:576
virtual bool read(DataType &value)
Read data from the buffer.
Definition BufferBase.h:674
virtual bool write(const DataType &value)
Write data into the buffer.
Definition BufferBase.h:645
virtual bool isEmpty() const
Check on whether the buffer is empty.
Definition BufferBase.h:723
RT-Component.
BufferStatus
DataPortStatus return codes.
Definition BufferStatus.h:57