Buffer.h++

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002    commonc++ - A C++ Common Class Library
00003    Copyright (C) 2005-2012  Mark A Lindner
00004 
00005    This file is part of commonc++.
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with this library; if not, write to the Free
00019    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00020    ---------------------------------------------------------------------------
00021 */
00022 
00023 #ifndef __ccxx_Buffer_hxx
00024 #define __ccxx_Buffer_hxx
00025 
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/AbstractBuffer.h++>
00028 #include <commonc++/OutOfBoundsException.h++>
00029 
00030 #include <cstring>
00031 #include <algorithm>
00032 
00033 namespace ccxx {
00034 
00044 template <typename T> class Buffer : public AbstractBuffer<T>
00045 {
00046   public:
00047 
00053   Buffer(size_t size);
00054 
00057   virtual ~Buffer() throw();
00058 
00063   virtual void clear() throw();
00064 
00069   void flip() throw();
00070 
00074   void rewind() throw();
00075 
00079   void setLimit(size_t limit) throw();
00080 
00084   void setPosition(size_t pos) throw();
00085 
00093   size_t bump(size_t delta) throw();
00094 
00103   size_t skip(size_t delta) throw();
00104 
00113   bool put(const T& item) throw();
00114 
00123   bool get(T * item) throw();
00124 
00134   bool put(const T * items, size_t count) throw();
00135 
00144   void fill(const T& item, size_t count = 0) throw();
00145 
00155   bool get(T * items, size_t count) throw();
00156 
00165   int peek(const T& item) const throw();
00166 
00170   inline T *getPointer() throw()
00171   { return(this->_data + this->_pos); }
00172 
00176   inline const T *getPointer() const throw()
00177   { return(this->_data + this->_pos); }
00178 
00182   inline size_t getLimit() const throw()
00183   { return(_limit); }
00184 
00190   inline size_t getRemaining() const throw()
00191   { return(_limit - _pos); }
00192 
00199   inline bool hasRemaining() const throw()
00200   { return(_limit > _pos); }
00201 
00205   inline size_t getPosition() const throw()
00206   { return(_pos); }
00207 
00214   T& operator[](int index) throw(OutOfBoundsException);
00215 
00222   T operator[](int index) const throw(OutOfBoundsException);
00223 
00224   protected:
00225 
00227   size_t _limit;
00229   size_t _pos;
00230 
00231   private:
00232 
00233   CCXX_COPY_DECLS(Buffer);
00234 };
00235 
00236 #include <commonc++/BufferImpl.h++>
00237 
00238 typedef Buffer<byte_t> ByteBuffer;
00239 typedef Buffer<char> CharBuffer;
00240 
00241 }; // namespace ccxx
00242 
00243 #endif // __ccxx_Buffer_hxx
00244 
00245 /* end of header file */
Generated on Sat Nov 26 16:49:07 2011 for libcommonc++ by  doxygen 1.6.3