libsidplayfp
2.7.0
Main Page
Classes
Files
Examples
File List
src
builders
residfp-builder
residfp
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
#ifdef HAVE_CONFIG_H
26
# include "config.h"
27
#endif
28
29
#ifdef HAVE_CXX11
30
# include <atomic>
31
#endif
32
36
class
counter
37
{
38
private
:
39
#ifndef HAVE_CXX11
40
volatile
unsigned
int
c;
41
#else
42
std::atomic<unsigned int> c;
43
#endif
44
45
public
:
46
counter
() : c(1) {}
47
void
increase() { ++c; }
48
unsigned
int
decrease() {
return
--c; }
49
};
50
54
template
<
typename
T>
55
class
matrix
56
{
57
private
:
58
T* data;
59
counter
* count;
60
const
unsigned
int
x, y;
61
62
public
:
63
matrix
(
unsigned
int
x,
unsigned
int
y) :
64
data(
new
T[x * y]),
65
count(
new
counter
()),
66
x(x),
67
y(y) {}
68
69
matrix
(
const
matrix
& p) :
70
data(p.data),
71
count(p.count),
72
x(p.x),
73
y(p.y) { count->increase(); }
74
75
~matrix
() {
if
(count->decrease() == 0) {
delete
count;
delete
[] data; } }
76
77
unsigned
int
length()
const
{
return
x * y; }
78
79
T* operator[](
unsigned
int
a) {
return
&data[a * y]; }
80
81
T
const
* operator[](
unsigned
int
a)
const
{
return
&data[a * y]; }
82
};
83
84
typedef
matrix<short>
matrix_t
;
85
86
#endif
counter
Definition
array.h:37
matrix
Definition
array.h:56
Generated on Wed Apr 3 2024 00:00:00 for libsidplayfp by
1.10.0