CLAM-Development
1.4.0
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
Tools
SDIF
SDIFMatrix.hxx
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2004 MUSIC TECHNOLOGY GROUP (MTG)
3
* UNIVERSITAT POMPEU FABRA
4
*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*
20
*/
21
22
#ifndef _SdifMatrix_hxx_
23
#define _SdifMatrix_hxx_
24
25
#include "
SDIFHeader.hxx
"
26
27
#undef CLAM_USE_XML
28
#include "
Array.hxx
"
29
30
#include "
SDIFType.hxx
"
31
32
namespace
SDIF
33
{
47
class
Matrix
48
{
49
friend
class
File
;
50
protected
:
51
MatrixHeader
mHeader
;
52
53
Matrix
(
const
MatrixHeader
& header)
54
:
mHeader
(header)
55
{
56
}
57
58
Matrix
(
59
const
TypeId
& type =
TypeId::sDefault
,
DataType
dataType =
eUnknown
,
60
CLAM::TInt32
nRows = 0,
CLAM::TInt32
nColumns = 0);
61
virtual
char
*
GetPtr
(
void
) = 0;
62
virtual
void
Resize
(
int
nElems) = 0;
63
virtual
void
SetSize
(
int
nElems) = 0;
64
public
:
65
virtual
~Matrix
() { }
66
67
TypeId
Type
(
void
) {
return
mHeader
.
mType
;}
68
69
CLAM::TInt32
Rows
(
void
) {
return
mHeader
.
mnRows
; }
70
CLAM::TInt32
Columns
(
void
) {
return
mHeader
.
mnColumns
; }
71
CLAM::TInt32
SizeInFile
(
void
)
72
{
73
CLAM::TUInt32
nElems =
mHeader
.
mnColumns
*
mHeader
.
mnRows
;
74
CLAM::TUInt32
elemSize =
mHeader
.
mDataType
&0xFF;
75
CLAM::TUInt32
size = nElems*elemSize;
76
CLAM::TUInt32
padding = 8-size&7;
77
78
return
mHeader
.
SizeInFile
()+size+padding;
79
}
80
};
81
82
template
<
class
T=CLAM::TFloat32>
class
ConcreteMatrix
:
public
Matrix
83
{
84
friend
class
File
;
85
private
:
86
CLAM::Array<T>
mpData;
87
public
:
94
ConcreteMatrix
(
95
const
TypeId
& type =
TypeId::sDefault
,
96
CLAM::TInt32
nRows = 0,
CLAM::TInt32
nColumns = 0)
97
:
Matrix
(type,
GetType
<T>::Get(),nRows,nColumns)
98
{
99
CLAM::TInt32
nElems =
Rows
()*
Columns
();
100
Resize
(nElems);
101
SetSize
(nElems);
102
}
103
104
ConcreteMatrix
(
const
MatrixHeader
& header)
105
:
Matrix
(header)
106
{
107
CLAM::TInt32
nElems =
Rows
()*
Columns
();
108
Resize
(nElems);
109
SetSize
(nElems);
110
}
111
112
char
*
GetPtr
(
void
) {
return
(
char
*)mpData.GetPtr(); }
113
void
Resize
(
int
nElems) { mpData.Resize(nElems); }
114
void
SetSize
(
int
nElems) { mpData.SetSize(nElems); }
115
116
121
T
GetValue
(
CLAM::TInt32
row,
CLAM::TInt32
col)
122
{
123
return
mpData[row*
mHeader
.
mnColumns
+ col];
124
}
125
130
void
SetValue
(
CLAM::TInt32
row,
CLAM::TInt32
col,
const
T& val)
131
{
132
mpData[row*
mHeader
.
mnColumns
+ col] = val;
133
}
134
};
135
}
136
137
#endif//_SdifMatrix_hxx_
138
Generated by
1.8.1