BufferBase.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef RTC_BUFFERBASE_H
00021 #define RTC_BUFFERBASE_H
00022 
00023 #include <stddef.h>
00024 #include <coil/Properties.h>
00025 #include <rtm/BufferStatus.h>
00026 
00041 namespace RTC
00042 {
00103   template <class DataType>
00104   class BufferBase
00105     : public BufferStatus
00106   {
00107   public:
00108     BUFFERSTATUS_ENUM
00109 
00121     virtual ~BufferBase(void)
00122     {
00123     };
00124     
00136     virtual void init(const coil::Properties& prop) = 0;
00137 
00157     virtual size_t length(void) const = 0;
00158 
00183     virtual ReturnCode length(size_t n) = 0;
00184 
00208     virtual ReturnCode reset() = 0;
00209 
00210 
00211     //----------------------------------------------------------------------
00233     virtual DataType* wptr(long int n = 0) = 0;
00234 
00257     virtual ReturnCode advanceWptr(long int n = 1) = 0;
00258 
00284     virtual ReturnCode put(const DataType& value) = 0;
00285 
00311     virtual ReturnCode write(const DataType& value,
00312                              long int sec = -1, long int nsec = -1) = 0;
00313 
00335     virtual size_t writable() const = 0;
00336 
00356     virtual bool full(void) const = 0;
00357 
00358     //----------------------------------------------------------------------
00379     virtual DataType* rptr(long int n = 0) = 0;
00380 
00403     virtual ReturnCode advanceRptr(long int n = 1) = 0;
00404 
00430     virtual ReturnCode get(DataType& value) = 0;
00431 
00451     virtual DataType&  get() = 0;
00452 
00476     virtual ReturnCode read(DataType& value,
00477                             long int sec = -1, long int nsec = -1) = 0;
00478     
00500     virtual size_t readable() const = 0;
00501 
00521     virtual bool empty(void) const = 0;
00522 
00523   };
00524   
00551   template <class DataType>
00552   class NullBuffer
00553     : public BufferBase<DataType>
00554   {
00555   public:
00577     NullBuffer(long int size = 1)
00578       : m_length(1)
00579     {
00580     }
00581     
00597     virtual ~NullBuffer(void)
00598     {
00599     }
00600     
00620     virtual long int length(void) const
00621     {
00622       return 1;
00623     }
00624     
00648     virtual bool write(const DataType& value)
00649     {
00650       m_data = value;
00651       return true;
00652     }
00653     
00677     virtual bool read(DataType& value)
00678     {
00679       value = m_data;
00680       return true;
00681     }
00682     
00702     virtual bool isFull(void) const
00703     {
00704       return false;
00705     }
00706     
00726     virtual bool isEmpty(void) const
00727     {
00728       return false;
00729     }
00730     
00731   protected:
00751     virtual void put(const DataType& data)
00752     {
00753       m_data = data;
00754     }
00755     
00775     virtual const DataType& get(void)
00776     {
00777       return m_data;
00778     }
00779     
00802     virtual DataType& getRef(void)
00803     {
00804       return m_data;
00805     }
00806     
00807   private:
00808     DataType m_data;
00809     long int m_length;
00810   };
00811 }; // namespace RTC
00812 #endif // BufferBase_h


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:03