BufferBase.h

説明を見る。
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     
00125     virtual void init(const coil::Properties& prop) = 0;
00126 
00146     virtual size_t length(void) const = 0;
00147 
00169     virtual ReturnCode length(size_t n) = 0;
00170 
00192     virtual ReturnCode reset() = 0;
00193 
00194 
00195     //----------------------------------------------------------------------
00216     virtual DataType* wptr(long int n = 0) = 0;
00217 
00239     virtual ReturnCode advanceWptr(long int n = 1) = 0;
00240 
00265     virtual ReturnCode put(const DataType& value) = 0;
00266 
00291     virtual ReturnCode write(const DataType& value,
00292                              long int sec = -1, long int nsec = -1) = 0;
00293 
00318     virtual size_t writable() const = 0;
00319 
00339     virtual bool full(void) const = 0;
00340 
00341     //----------------------------------------------------------------------
00362     virtual DataType* rptr(long int n = 0) = 0;
00363 
00385     virtual ReturnCode advanceRptr(long int n = 1) = 0;
00386 
00411     virtual ReturnCode get(DataType& value) = 0;
00412     virtual DataType&  get() = 0;
00413 
00437     virtual ReturnCode read(DataType& value,
00438                             long int sec = -1, long int nsec = -1) = 0;
00439     
00464     virtual size_t readable() const = 0;
00465 
00485     virtual bool empty(void) const = 0;
00486 
00487   };
00488   
00515   template <class DataType>
00516   class NullBuffer
00517     : public BufferBase<DataType>
00518   {
00519   public:
00541     NullBuffer(long int size = 1)
00542       : m_length(1)
00543     {
00544     }
00545     
00561     virtual ~NullBuffer(void)
00562     {
00563     }
00564     
00584     virtual long int length(void) const
00585     {
00586       return 1;
00587     }
00588     
00612     virtual bool write(const DataType& value)
00613     {
00614       m_data = value;
00615       return true;
00616     }
00617     
00641     virtual bool read(DataType& value)
00642     {
00643       value = m_data;
00644       return true;
00645     }
00646     
00666     virtual bool isFull(void) const
00667     {
00668       return false;
00669     }
00670     
00690     virtual bool isEmpty(void) const
00691     {
00692       return false;
00693     }
00694     
00695   protected:
00715     virtual void put(const DataType& data)
00716     {
00717       m_data = data;
00718     }
00719     
00739     virtual const DataType& get(void)
00740     {
00741       return m_data;
00742     }
00743     
00766     virtual DataType& getRef(void)
00767     {
00768       return m_data;
00769     }
00770     
00771   private:
00772     DataType m_data;
00773     long int m_length;
00774   };
00775 }; // namespace RTC
00776 #endif // BufferBase_h

OpenRTMに対してSun May 24 14:08:25 2009に生成されました。  doxygen 1.5.3