libcommonc++  0.7
AbstractBuffer.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_AbstractBuffer_hxx
24 #define __ccxx_AbstractBuffer_hxx
25 
26 #include <commonc++/Common.h++>
28 
29 #include <cstring>
30 
31 namespace ccxx {
32 
38 template<typename T> class AbstractBuffer
39 {
40  public:
41 
43  virtual ~AbstractBuffer();
44 
52  virtual void setSize(uint_t newSize);
53 
55  virtual void clear();
56 
62  inline uint_t getSize() const
63  { return(_size); }
64 
66  virtual uint_t getRemaining() const = 0;
67 
69  inline virtual bool hasRemaining() const
70  { return(getRemaining() > 0); }
71 
73  inline T* getBase()
74  { return(_data); }
75 
77  inline const T* getBase() const
78  { return(_data); }
79 
80  protected:
81 
87  AbstractBuffer(uint_t size);
88 
93  AbstractBuffer(T* data, size_t size, bool takeOwnership = true);
94 
96  T* _data;
100  bool _owner;
101 
102  private:
103 
104  CCXX_COPY_DECLS(AbstractBuffer);
105 };
106 
107 #include <commonc++/AbstractBufferImpl.h++>
108 
109 } // namespace ccxx
110 
111 #endif // __ccxx_AbstractBuffer_hxx
const T * getBase() const
Get a pointer to the base of the buffer.
Definition: AbstractBuffer.h++:77
AbstractBuffer(uint_t size)
Construct a new buffer with the given size.
virtual uint_t getRemaining() const =0
Get the number of elements remaining in the buffer.
virtual ~AbstractBuffer()
Destructor.
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
virtual bool hasRemaining() const
Test if the buffer has elements available to be read or written.
Definition: AbstractBuffer.h++:69
T * getBase()
Get a pointer to the base of the buffer.
Definition: AbstractBuffer.h++:73
bool _owner
Whether this object owns the raw buffer.
Definition: AbstractBuffer.h++:100
T * _data
A pointer to the raw buffer.
Definition: AbstractBuffer.h++:96
virtual void clear()
Clear the buffer.
uint_t _size
The size of the buffer.
Definition: AbstractBuffer.h++:98
An abstract base class for buffers.
Definition: AbstractBuffer.h++:38
Definition: AllocationMap.c++:25
virtual void setSize(uint_t newSize)
Resize the buffer.
uint_t getSize() const
Get the size of the buffer.
Definition: AbstractBuffer.h++:62