Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/common/array.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2008 by Sindre Aamås *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef ARRAY_H
20
#define ARRAY_H
21
22
#include <cstddef>
23
#include "uncopyable.h"
24
25
template<typename T>
26
class Array : Uncopyable {
27
T *a;
28
std::size_t sz;
29
30
public:
31
explicit Array(const std::size_t size = 0) : a(size ? new T[size] : 0), sz(size) {}
32
~Array() { delete []a; }
33
void reset(const std::size_t size = 0) { delete []a; a = size ? new T[size] : 0; sz = size; }
34
std::size_t size() const { return sz; }
35
T * get() const { return a; }
36
operator T*() const { return a; }
37
};
38
39
template<typename T>
40
class ScopedArray : Uncopyable {
41
T *a_;
42
43
public:
44
explicit ScopedArray(T *a = 0) : a_(a) {}
45
~ScopedArray() { delete []a_; }
46
void reset(T *a = 0) { delete []a_; a_ = a; }
47
T * release() { T *a = a_; a_ = 0; return a; }
48
T * get() const { return a_; }
49
operator T*() const { return a_; }
50
};
51
52
#endif
53
54