Mercator  0.4.0
Buffer.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU General Public License (See COPYING for details).
3 // Copyright (C) 2003 Alistair Riddoch
4 
5 #ifndef MERCATOR_BUFFER_H
6 #define MERCATOR_BUFFER_H
7 
8 namespace Mercator {
9 
11 template<typename DataType>
12 class Buffer {
13  protected:
15  const unsigned int m_channels;
17  const unsigned int m_size;
19  DataType * m_data;
20 
21  public:
26  explicit Buffer(unsigned int size, unsigned int channels);
27  virtual ~Buffer();
28 
34  DataType & operator()(unsigned int x,unsigned int y,unsigned int channel) {
35  return m_data[(y * m_size + x) * m_channels + channel];
36  }
37 
43  const DataType & operator()(unsigned int x,
44  unsigned int y,
45  unsigned int channel) const {
46  return m_data[(y * m_size + x) * m_channels + channel];
47  }
48 
49 
51  unsigned int getSize() const {
52  return m_size;
53  }
54 
56  unsigned int getChannels() const {
57  return m_channels;
58  }
59 
61  DataType * getData() {
62  return m_data;
63  }
64 
66  const DataType * getData() const {
67  return m_data;
68  }
69 
74  void allocate() {
75  m_data = new DataType[m_size * m_size * m_channels];
76  }
77 
81  bool isValid() const {
82  return (m_data != nullptr);
83  }
84 
88  void invalidate() {
89  delete [] m_data;
90  m_data = nullptr;
91  }
92 
93 };
94 
95 } // namespace Mercator
96 
97 #endif // MERCATOR_BUFFER_H
const DataType & operator()(unsigned int x, unsigned int y, unsigned int channel) const
Retrieve the data value at a given point.
Definition: Buffer.h:43
DataType * m_data
Pointer to buffer containing data values.
Definition: Buffer.h:19
DataType * getData()
Accessor for a pointer to buffer containing data values.
Definition: Buffer.h:61
void invalidate()
De-allocate the storage for this buffer.
Definition: Buffer.h:88
Template for managing buffers of data for a segment.
Definition: Buffer.h:12
Definition: Area.cpp:20
const unsigned int m_size
The size of segment, m_res + 1.
Definition: Buffer.h:17
const unsigned int m_channels
The number of data values per height point.
Definition: Buffer.h:15
void allocate()
Allocate the storage required by the buffer.
Definition: Buffer.h:74
bool isValid() const
Determine if this buffer has valid allocated storage.
Definition: Buffer.h:81
unsigned int getSize() const
Accessor for the size of segment, m_res + 1.
Definition: Buffer.h:51
const DataType * getData() const
Accessor for a pointer to buffer containing data values.
Definition: Buffer.h:66
DataType & operator()(unsigned int x, unsigned int y, unsigned int channel)
Retrieve the data value at a given point.
Definition: Buffer.h:34
Buffer(unsigned int size, unsigned int channels)
Constructor.
Definition: Buffer_impl.h:10
unsigned int getChannels() const
Accessor for the number of data values per height point.
Definition: Buffer.h:56