VR-Vantage 3.1 API Documentation
Home
Modules
Namespaces
Classes
Files
Libraries
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
sensorFx
include
ssBuffer.h
Go to the documentation of this file.
1
2
// Copyright JRM Enterprises, Inc. 2004
3
// All rights reserved.
4
//
5
// This code is the intellectual property of JRM Enterprises, Inc.
6
// It may not be used or released as source or compiled binary form
7
// without the prior written consent of JRM Enterprises, Inc.
8
//
9
// Original Author: Tim George Date: July 2004
11
12
#ifndef _ssBuffer_
13
#define _ssBuffer_
14
15
#define NUM_BUFFERS 2
16
17
template
<
class
dataType>
18
class
ssBuffer
19
{
20
private
:
21
int
*
_size
;
22
int
_numBuf
;
23
int
_curBuffer
;
24
dataType
**
_data
;
25
26
public
:
27
ssBuffer
(
int
size
,
int
numBuf)
28
{
29
_curBuffer
= 0;
30
_numBuf
= 0;
31
_size
= NULL;
32
_data
= NULL;
33
34
if
(numBuf<1)
return
;
35
36
_size
=
new
int
[numBuf];
37
_data
=
new
dataType
*[numBuf];
38
_numBuf
= numBuf;
39
40
for
(
int
i = 0; i <
_numBuf
; i++)
41
{
42
_data
[i] =
new
dataType
[
size
];
43
_size
[i] =
size
;
44
}
45
46
return
;
47
};
48
49
ssBuffer
&
operator=
(
const
ssBuffer
&
copy
)
50
{
51
_numBuf
= copy.
_numBuf
;
52
_curBuffer
= (copy.
_curBuffer
%
_numBuf
);
53
54
delete
[]
_size
;
55
_size
=
new
int
[
_numBuf
];
56
57
delete
[]
_data
;
58
_data
=
new
dataType
[
_numBuf
];
59
60
for
(
int
i = 0; i <
_numBuf
; i++)
61
{
62
_size
[i] = copy.
_size
[i];
63
_data
[i] =
new
dataType
[copy.size[i]];
64
memcpy(
_data
[i], copy.
_data
[i], copy.size[i]);
65
}
66
67
return
*
this
;
68
}
69
70
ssBuffer
(
const
ssBuffer
&
copy
)
71
{
72
_numBuf
= copy.
_numBuf
;
73
_curBuffer
= (copy.
_curBuffer
%
_numBuf
);
74
75
_size
=
new
int
[
_numBuf
];
76
_data
=
new
dataType
[
_numBuf
];
77
78
for
(
int
i = 0; i <
_numBuf
; i++)
79
{
80
_size
[i] = copy.
_size
[i];
81
_data
[i] =
new
dataType
[copy.size[i]];
82
memcpy(
_data
[i], copy.
_data
[i], copy.size[i]);
83
}
84
}
85
86
~ssBuffer
()
87
{
88
for
(
int
i = 0; i <
_numBuf
; i++)
89
{
90
delete
[]
_data
[i];
91
}
92
delete
[]
_data
;
93
delete
[]
_size
;
94
};
95
96
void
addData
(
int
size
)
97
{
98
if
(!
_data
)
return
;
99
if
(!
_size
)
return
;
100
int
nextBuf = ((
_curBuffer
+ 1) %
_numBuf
);
101
if
(
_data
[nextBuf])
delete
[]
_data
[nextBuf];
102
_size
[nextBuf] =
size
;
103
_data
[nextBuf] =
new
dataType
[
size
];
104
}
105
106
dataType
*
getNextData
()
107
{
108
if
(!
_data
)
return
NULL;
109
int
nextBuf = ((
_curBuffer
+ 1) %
_numBuf
);
110
return
_data
[nextBuf];
111
};
112
113
void
useNextData
()
114
{
115
_curBuffer
= ((
_curBuffer
+ 1) %
_numBuf
);
116
}
117
118
void
copy
(
dataType
*
copy
)
119
{
120
if
(!
_size
)
return
;
121
if
(!
_data
)
return
;
122
int
nextBuf = ((
_curBuffer
+ 1) %
_numBuf
);
123
if
(!(
_data
[nextBuf]))
return
;
124
for
(
int
i = 0; i <
_size
[nextBuf]; i++)
125
{
126
_data
[nextBuf][i] = copy[i];
127
}
128
_curBuffer
= nextBuf;
129
}
130
131
dataType
*
getDataPtr
()
132
{
133
if
(!
_data
)
return
NULL;
134
if
(
_curBuffer
>
_numBuf
-1)
return
NULL;
135
return
_data
[
_curBuffer
];
136
}
137
138
dataType
&
operator []
(
const
int
nIdx)
139
{
140
if
(!
_data
)
return
0;
141
if
(
_curBuffer
>
_numBuf
-1)
return
0;
142
if
(!(
_data
[
_curBuffer
]))
return
0;
143
if
(!
_size
)
return
0;
144
if
(nIdx<
_size
[_curBuffer]-1)
return
0;
145
return
_data
[
_curBuffer
][nIdx];
146
};
147
148
149
};
150
151
#endif
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (
www.mak.com
)