SCV
4.2.1
Simple Components for Visual
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
MatrixTemplate.h
Go to the documentation of this file.
1
7
#ifndef __SCV_MATRIX_TEMPLATE_H__
8
#define __SCV_MATRIX_TEMPLATE_H__
9
10
#ifndef DOXYGEN_SKIP_THIS
11
#include "
Point.h
"
12
#endif // DOXYGEN_SKIP_THIS
13
14
namespace
scv {
15
19
template
<
typename
T>
20
class
MatrixTemplate
{
21
public
:
22
23
virtual
~MatrixTemplate
(
void
) {}
24
26
MatrixTemplate
(
void
) :
_width
(0),
_height
(0) {
27
//none
28
}
33
MatrixTemplate
(
unsigned
int
width,
unsigned
int
height) :
_width
(width),
_height
(height) {
34
_data
.resize(
_width
*
_height
);
35
}
41
MatrixTemplate
(
unsigned
int
width,
unsigned
int
height,
const
T& rhs) :
_width
(width),
_height
(height) {
42
_data
.resize(
_width
*
_height
, rhs);
43
}
45
MatrixTemplate
(
const
MatrixTemplate
&rhs) :
_width
(rhs.
_width
),
_height
(rhs.
_height
) {
46
_data
= rhs.
_data
;
47
}
49
MatrixTemplate
&
operator=
(
const
MatrixTemplate
&rhs) {
50
if
(
this
!= &rhs) {
51
_data
= rhs.
_data
;
52
const_cast<
unsigned
int
&
>
(
_width
) = rhs.
_width
;
53
const_cast<unsigned int&>(
_height
) = rhs.
_height
;
54
}
55
return
*
this
;
56
}
58
inline
T&
operator()
(
unsigned
int
l,
unsigned
int
c) {
59
return
_data
[l *
_width
+ c];
60
}
62
bool
operator==
(
const
MatrixTemplate<T>
& rhs)
const
{
63
return
(
_data
== rhs.
_data
)?
true
:
false
;
64
}
66
inline
int
getWidth
(
void
)
const
{
67
return
_width
;
68
}
70
inline
int
getHeight
(
void
)
const
{
71
return
_height
;
72
}
77
inline
T &
get
(
unsigned
int
l,
unsigned
int
c) {
78
return
_data
[l *
_width
+ c];
79
}
81
inline
std::vector<T> &
getData
(
void
) {
82
return
_data
;
83
}
85
inline
void
set
(
const
scv::Point
&p, T rhs) {
86
_data
[p.y *
_width
+ p.x] = rhs;
87
}
89
inline
void
set
(
unsigned
int
l,
unsigned
int
c, T rhs) {
90
_data
[l *
_width
+ c] = rhs;
91
}
93
inline
bool
isValid
(
const
scv::Point
&p) {
94
return
(p.
y
>=0 && p.
y
< (
int
)
_height
&& p.
x
>= 0 && p.
x
< (
int
)
_width
)?
true
:
false
;
95
}
97
inline
bool
isValid
(
unsigned
int
l,
unsigned
int
c) {
98
return
(l <
_height
&& c <
_width
)?
true
:
false
;
99
}
104
inline
void
resize
(
unsigned
int
l,
unsigned
int
c) {
105
_data
.resize(l * c);
106
_width
= c;
107
_height
= l;
108
}
109
110
protected
:
111
unsigned
int
_width
,
_height
;
112
std::vector<T>
_data
;
113
};
114
115
}
// namespace scv
116
117
118
#endif // __SCV_MATRIX_TEMPLATE_H__
include
SCV
MatrixTemplate.h
Generated on Fri Dec 14 2012 09:44:49 for SCV by
1.8.2