BufferBase.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 #ifndef BufferBase_h
00021 #define BufferBase_h
00022 
00037 namespace RTC
00038 {
00089   template <class DataType>
00090   class BufferBase
00091   {
00092   public:
00104     virtual ~BufferBase()
00105     {
00106     };
00107     
00127     virtual long int length() const = 0;
00128     
00152     virtual bool write(const DataType& value) = 0;
00153     
00177     virtual bool read(DataType& value) = 0;
00178     
00198     virtual bool isFull() const = 0;
00199     
00219     virtual bool isEmpty() const = 0;
00220     
00221   protected:
00241     virtual void put(const DataType& data) = 0;
00242     
00262     virtual const DataType& get() = 0;
00263     
00284     virtual DataType& getRef() = 0;
00285   };
00286   
00313   template <class DataType>
00314   class NullBuffer
00315     : public BufferBase<DataType>
00316   {
00317   public:
00339     NullBuffer(long int size = 1)
00340       : m_length(1)
00341     {
00342     }
00343     
00359     virtual ~NullBuffer()
00360     {
00361     }
00362     
00382     virtual long int length() const
00383     {
00384       return 1;
00385     }
00386     
00410     virtual bool write(const DataType& value)
00411     {
00412       m_data = value;
00413       return true;
00414     }
00415     
00439     virtual bool read(DataType& value)
00440     {
00441       value = m_data;
00442       return true;
00443     }
00444     
00464     virtual bool isFull() const
00465     {
00466       return false;
00467     }
00468     
00488     virtual bool isEmpty() const
00489     {
00490       return false;
00491     }
00492     
00493   protected:
00513     virtual void put(const DataType& data)
00514     {
00515       m_data = data;
00516     }
00517     
00537     virtual const DataType& get()
00538     {
00539       return m_data;
00540     }
00541     
00564     virtual DataType& getRef()
00565     {
00566       return m_data;
00567     }
00568     
00569   private:
00570     DataType m_data;
00571     long int m_length;
00572   };
00573 }; // namespace RTC
00574 #endif // BufferBase_h

Generated on Wed May 21 05:17:34 2008 for OpenRTM by  doxygen 1.5.3