Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

BufferBase.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00020 /*
00021  * $Log: BufferBase.h,v $
00022  * Revision 1.2  2006/12/02 18:24:15  n-ando
00023  * BufferBase's interfaces were changed.
00024  *
00025  * Revision 1.1  2006/11/27 09:44:34  n-ando
00026  * The first commitment.
00027  *
00028  */
00029 
00030 #ifndef BufferBase_h
00031 #define BufferBase_h
00032 
00033 namespace RTC
00034 {
00068   template <class DataType>
00069   class BufferBase
00070   {
00071   public:
00083     virtual ~BufferBase(){};
00084 
00096     virtual long int length() const = 0;
00097 
00109     virtual bool write(const DataType& value) = 0;
00110 
00122     virtual bool read(DataType& value) = 0;
00123 
00135     virtual bool isFull() const = 0;
00136 
00148     virtual bool isEmpty() const = 0;
00149 
00150   protected:
00162     virtual void put(const DataType& data) = 0;
00163 
00175     virtual const DataType& get() = 0;
00176 
00188     virtual DataType& getRef() = 0;
00189 
00190   };
00191 
00192 
00193 
00194 
00195   template <class DataType>
00196   class NullBuffer
00197     : public BufferBase<DataType>
00198   {
00199   public:
00200     NullBuffer(long int size = 1)
00201       : m_length(1)
00202     {
00203     }
00204 
00205     virtual ~NullBuffer()
00206     {
00207     }
00208 
00209     virtual long int length() const
00210     {
00211       return 1;
00212     }
00213 
00214     virtual bool write(const DataType& value)
00215     {
00216       m_data = value;
00217       return true;
00218     }
00219 
00220     virtual bool read(DataType& value)
00221     {
00222       value = m_data;
00223       return true;
00224     }
00225 
00226     virtual bool isFull() const
00227     {
00228       return false;
00229     }
00230 
00231     virtual bool isEmpty() const
00232     {
00233       return false;
00234     }
00235     
00236   protected:
00237     virtual void put(const DataType& data)
00238     {
00239       m_data = data;
00240     }
00241 
00242     virtual const DataType& get()
00243     {
00244       return m_data;
00245     }
00246 
00247     virtual DataType& getRef()
00248     {
00249       return m_data;
00250     }
00251 
00252   private:
00253     DataType m_data;
00254     long int m_length;
00255   };
00256 
00257 
00258 }; // namespace RTC
00259 #endif // BufferBase_h

Generated on Mon Jul 23 17:08:14 2007 for OpenRTM by  doxygen 1.4.1