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.4.2  2007/09/21 09:18:12  n-ando
00023  * Documentation was modified.
00024  *
00025  * Revision 1.2  2006/12/02 18:24:15  n-ando
00026  * BufferBase's interfaces were changed.
00027  *
00028  * Revision 1.1  2006/11/27 09:44:34  n-ando
00029  * The first commitment.
00030  *
00031  */
00032 
00033 #ifndef BufferBase_h
00034 #define BufferBase_h
00035 
00036 namespace RTC
00037 {
00071   template <class DataType>
00072   class BufferBase
00073   {
00074   public:
00086     virtual ~BufferBase(){};
00087 
00099     virtual long int length() const = 0;
00100 
00112     virtual bool write(const DataType& value) = 0;
00113 
00125     virtual bool read(DataType& value) = 0;
00126 
00138     virtual bool isFull() const = 0;
00139 
00151     virtual bool isEmpty() const = 0;
00152 
00153   protected:
00165     virtual void put(const DataType& data) = 0;
00166 
00178     virtual const DataType& get() = 0;
00179 
00191     virtual DataType& getRef() = 0;
00192 
00193   };
00194 
00195 
00196 
00197 
00198   template <class DataType>
00199   class NullBuffer
00200     : public BufferBase<DataType>
00201   {
00202   public:
00203     NullBuffer(long int size = 1)
00204       : m_length(1)
00205     {
00206     }
00207 
00208     virtual ~NullBuffer()
00209     {
00210     }
00211 
00212     virtual long int length() const
00213     {
00214       return 1;
00215     }
00216 
00217     virtual bool write(const DataType& value)
00218     {
00219       m_data = value;
00220       return true;
00221     }
00222 
00223     virtual bool read(DataType& value)
00224     {
00225       value = m_data;
00226       return true;
00227     }
00228 
00229     virtual bool isFull() const
00230     {
00231       return false;
00232     }
00233 
00234     virtual bool isEmpty() const
00235     {
00236       return false;
00237     }
00238     
00239   protected:
00240     virtual void put(const DataType& data)
00241     {
00242       m_data = data;
00243     }
00244 
00245     virtual const DataType& get()
00246     {
00247       return m_data;
00248     }
00249 
00250     virtual DataType& getRef()
00251     {
00252       return m_data;
00253     }
00254 
00255   private:
00256     DataType m_data;
00257     long int m_length;
00258   };
00259 
00260 
00261 }; // namespace RTC
00262 #endif // BufferBase_h

Generated on Fri Oct 5 05:15:59 2007 for OpenRTM by  doxygen 1.4.1