]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/meshtex/AllocatedMatrix.h
Merge branch 'NateEag-master-patch-12920' into 'master'
[xonotic/netradiant.git] / contrib / meshtex / AllocatedMatrix.h
1 /**
2  * @file AllocatedMatrix.h
3  * Declares and implements the AllocatedMatrix template class.
4  * @ingroup meshtex-util
5  */
6
7 /*
8  * Copyright 2012 Joel Baxter
9  *
10  * This file is part of MeshTex.
11  *
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.
16  *
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.
21  *
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/>.
24  */
25
26 #if !defined(INCLUDED_ALLOCATEDMATRIX_H)
27 #define INCLUDED_ALLOCATEDMATRIX_H
28
29 #include "debugging/debugging.h"
30 #include "ipatch.h"
31
32 /**
33  * Matrix subclass that allocates its data array on construction and
34  * deallocates it on destruction.
35  *
36  * @ingroup meshtex-util
37  */
38 template<typename Element>
39 class AllocatedMatrix : public Matrix<Element>
40 {
41         //std::size_t m_x, m_y;
42         //Element* m_data;
43 public: // public methods
44
45    /**
46     * Constructor. Allocates a data array of the appropriate size.
47     *
48     * @param x Matrix x dimension.
49     * @param y Matrix y dimension.
50     */
51    //AllocatedMatrix(std::size_t x, std::size_t y) : m_x(x), m_y(y), m_data(_allocated = new Element[x*y]){} //doesnt work.
52    //AllocatedMatrix(std::size_t x, std::size_t y) : Matrix(x, y, (_allocated = new Element[x*y])) {} //msvc
53    typedef Matrix<Element> matrix_type;
54    AllocatedMatrix(std::size_t x, std::size_t y) : matrix_type(x, y, (_allocated = new Element[x*y])) {}
55
56
57    /**
58     * Destructor. Deallocates the data array.
59     */
60    ~AllocatedMatrix() { delete [] _allocated; }
61
62 private: // private member vars
63
64    /**
65     * Pointer to the data array so that the destructor can find it for deletion.
66     */
67    Element *_allocated;
68 };
69
70 #endif // #if !defined(INCLUDED_ALLOCATEDMATRIX_H)