Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
Buffer.hGo 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 virtual ~Buffer(); 00024 00025 //! Gets the pointer to the first element of the underlying array. 00026 const char* GetData() const { return data; } 00027 //! Gets the pointer to the first element of the underlying array. 00028 char* GetData() { return data; } 00029 //! Gets the capacity of the buffer. 00030 int GetCapacity() const { return capacity; } 00031 //! Sets the capacity of the buffer. The underlying array grows and shrinks. 00032 void SetCapacity(int size); 00033 //! Gets the current position. position <= limit. 00034 int GetPosition() const { return position; } 00035 //! Gets the limit mark of the buffer. limit <= capacity 00036 int GetLimit() const { return limit; } 00037 //! Sets the current position. 00038 void SetPosition(int pos); 00039 //! Sets the limit mark. limit <= capacity 00040 void SetLimit(int lim); 00041 //! 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. 00042 bool Fill(const char*&src, int& srcLen); 00043 //! 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. 00044 bool Fill(char*& src, int& srcLen) { return Fill((const char*&) src, srcLen); } 00045 //! Checks whether the buffer is full, that is position == limit. 00046 bool IsFull() const { return (position >= limit); } 00047 private: 00048 char* data; 00049 int capacity; 00050 int limit; 00051 int position; 00052 00053 static int min(int a, int b) { return ((a < b) ? a : b); } 00054 }; 00055 #endif |
Tekkotsu v2.2.1 |
Generated Tue Nov 23 16:36:37 2004 by Doxygen 1.3.9.1 |