Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Buffer.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_Buffer_h_
00003 #define INCLUDED_Buffer_h_
00004 
00005 //! Buffer.
00006 /*! A buffer has three main properties: position, capacity and limit.
00007  * Capacity is the real size of the underlying array.
00008  * Position is the index of the current element in the buffer (used only by
00009  * buffer filling operations at the moment).
00010  * Limit is the virtual size of the buffer. Operations such as filling up
00011  * the buffer, seeking and so on never go over the limit mark of the buffer. 
00012  *
00013  * 0 <= position <= limit <= capacity.
00014  */
00015 class Buffer {
00016   public:
00017     //! Constructs a new buffer of specified capacity and limit
00018     Buffer(int size);
00019     //! Constructs a copy of the buffer
00020     Buffer(const Buffer& rhs);
00021     //! Makes this buffer a copy of the rhs buffer
00022     Buffer& operator=(const Buffer& rhs);
00023     //! destructor, deletes #data
00024     virtual ~Buffer();
00025     
00026     //! Gets the pointer to the first element of the underlying array.
00027     const char* GetData() const { return data; }
00028     //! Gets the pointer to the first element of the underlying array.
00029     char* GetData() { return data; }
00030     //! Gets the capacity of the buffer.
00031     int GetCapacity() const { return capacity; }
00032     //! Sets the capacity of the buffer. The underlying array grows and shrinks.
00033     void SetCapacity(int size);
00034     //! Gets the current position. position <= limit.
00035     int GetPosition() const { return position; }
00036     //! Gets the limit mark of the buffer. limit <= capacity
00037     int GetLimit() const { return limit; }
00038     //! Sets the current position.
00039     void SetPosition(int pos);
00040     //! Sets the limit mark. limit <= capacity
00041     void SetLimit(int lim);
00042     //! Tries to fill the buffer from current position up to the limit mark. Advances the position, src and srcLen. Returns true if the buffer has been filled.
00043     bool Fill(const char*&src, int& srcLen);
00044     //! Tries to fill the buffer from current position up to the limit mark. Advances the position, src and srcLen. Returns true if the buffer has been filled.
00045     bool Fill(char*& src, int& srcLen) { return Fill(const_cast<const char*&>(src), srcLen); }
00046     //! Checks whether the buffer is full, that is position == limit.
00047     bool IsFull() const { return (position >= limit); }
00048   private:
00049     char* data;   //!< the buffer itself
00050     int capacity; //!< the the real size of the underlying array.
00051     int limit; //!< Position is the index of the current element in the buffer (used only by buffer filling operations at the moment)
00052     int position; //!< Limit is the virtual size of the buffer. Operations such as filling up the buffer, seeking and so on never go over the limit mark of the buffer. 
00053     
00054     //! returns the lesser of @a a or @a b
00055     static int min(int a, int b) { return ((a < b) ? a : b); }
00056 };
00057 
00058 
00059 /*! @file
00060  * @brief Describes Buffer, a general memory management data structure, featuring position, limit, and capacity marks
00061  * @author Alexander Klyubin (A.Kljubin AT herts ac uk) (Creator)
00062  * Submitted as part of "Full-duplex Audio Streaming" patch
00063  */
00064 
00065 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:36 2016 by Doxygen 1.6.3