libresidfp
1.0.2
Main Page
Classes
Files
File List
src
array.h
1
/*
2
* This file is part of libsidplayfp, a SID player engine.
3
*
4
* Copyright (C) 2011-2014 Leandro Nini
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#ifndef ARRAY_H
22
#define ARRAY_H
23
24
25
#include <atomic>
26
30
class
counter
31
{
32
private
:
33
std::atomic<unsigned int> c;
34
35
public
:
36
counter
() : c(1) {}
37
void
increase() { ++c; }
38
unsigned
int
decrease() {
return
--c; }
39
};
40
44
template
<
typename
T>
45
class
matrix
46
{
47
private
:
48
T* data;
49
counter
* count;
50
const
unsigned
int
x, y;
51
52
private
:
53
matrix
& operator=(
const
matrix
&) =
delete
;
54
55
public
:
56
matrix
(
unsigned
int
new_x,
unsigned
int
new_y) :
57
data(
new
T[new_x * new_y]),
58
count(
new
counter
()),
59
x(new_x),
60
y(new_y) {}
61
62
matrix
(
const
matrix
& p) :
63
data(p.data),
64
count(p.count),
65
x(p.x),
66
y(p.y) { count->increase(); }
67
68
~matrix
() {
if
(count->decrease() == 0) {
delete
count;
delete
[] data; } }
69
70
unsigned
int
length()
const
{
return
x * y; }
71
72
T* operator[](
unsigned
int
a) {
return
&data[a * y]; }
73
74
T
const
* operator[](
unsigned
int
a)
const
{
return
&data[a * y]; }
75
};
76
77
using
matrix_t
=
matrix<short>
;
78
79
#endif
counter
Definition
array.h:31
matrix
Definition
array.h:46
Generated on Fri May 15 2026 12:59:32 for libresidfp by
1.9.8