2 * @file AllocatedMatrix.h
3 * Declares and implements the AllocatedMatrix template class.
4 * @ingroup meshtex-util
8 * Copyright 2012 Joel Baxter
10 * This file is part of MeshTex.
12 * MeshTex is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
17 * MeshTex is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
26 #if !defined(INCLUDED_ALLOCATEDMATRIX_H)
27 #define INCLUDED_ALLOCATEDMATRIX_H
29 #include "debugging/debugging.h"
33 * Matrix subclass that allocates its data array on construction and
34 * deallocates it on destruction.
36 * @ingroup meshtex-util
38 template<typename Element>
39 class AllocatedMatrix : public Matrix<Element>
43 public: // public methods
46 * Constructor. Allocates a data array of the appropriate size.
48 * @param x Matrix x dimension.
49 * @param y Matrix y dimension.
51 AllocatedMatrix(std::size_t x, std::size_t y) : m_x(x), m_y(y), m_data(_allocated = new Element[x*y]){}
52 // Matrix(x, y, (_allocated = new Element[x*y])) {}
55 * Destructor. Deallocates the data array.
57 ~AllocatedMatrix() { delete [] _allocated; }
59 private: // private member vars
62 * Pointer to the data array so that the destructor can find it for deletion.
67 #endif // #if !defined(INCLUDED_ALLOCATEDMATRIX_H)