VR-Vantage 3.0 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
_size
=
new
int
[numBuf];
31
_data
=
new
dataType
*[numBuf];
32
33
_numBuf
= numBuf;
34
35
if
(numBuf > 0)
36
{
37
for
(
int
i = 0; i <
_numBuf
; i++)
38
{
39
_data
[i] =
new
dataType
[
size
];
40
_size
[i] =
size
;
41
}
42
}
43
44
45
46
};
47
48
ssBuffer
&
operator=
(
const
ssBuffer
&
copy
)
49
{
50
_curBuffer
= copy.
_curBuffer
;
51
_numBuf
= copy.
_numBuf
;
52
53
delete
[]
_size
;
54
_size
=
new
int
[
_numBuf
];
55
56
delete
[]
_data
;
57
_data
=
new
dataType
[
_numBuf
];
58
59
for
(
int
i = 0; i <
_numBuf
; i++)
60
{
61
_size
[i] = copy.
_size
[i];
62
_data
[i] =
new
dataType
[copy.size[i]];
63
memcpy(
_data
[i], copy.
_data
[i], copy.size[i]);
64
}
65
66
return
*
this
;
67
}
68
69
ssBuffer
(
const
ssBuffer
&
copy
)
70
{
71
_curBuffer
= copy.
_curBuffer
;
72
_numBuf
= copy.
_numBuf
;
73
74
_size
=
new
int
[
_numBuf
];
75
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
~ssBuffer
()
86
{
87
for
(
int
i = 0; i <
_numBuf
; i++)
88
{
89
delete
[]
_data
[i];
90
}
91
delete
[]
_data
;
92
delete
[]
_size
;
93
};
94
95
void
addData
(
int
size
)
96
{
97
int
nextBuf = ((
_curBuffer
+ 1) %
_numBuf
);
98
delete
[]
_data
[nextBuf];
99
_size
[nextBuf] =
size
;
100
_data
[nextBuf] =
new
dataType
[
size
];
101
}
102
103
dataType
*
getNextData
()
104
{
105
int
nextBuf = ((
_curBuffer
+ 1) %
_numBuf
);
106
return
_data
[nextBuf];
107
};
108
void
useNextData
()
109
{
110
_curBuffer
= ((
_curBuffer
+ 1) %
_numBuf
);
111
}
112
void
copy
(
dataType
*
copy
)
113
{
114
int
nextBuf = ((
_curBuffer
+ 1) %
_numBuf
);
115
for
(
int
i = 0; i <
_size
[nextBuf]; i++)
116
{
117
_data
[nextBuf][i] = copy[i];
118
}
119
_curBuffer
= nextBuf;
120
};
121
122
dataType
*
getDataPtr
()
123
{
124
return
_data
[
_curBuffer
];
125
};
126
127
dataType
&
operator []
(
const
int
nIdx)
128
{
129
return
_data
[
_curBuffer
][nIdx];
130
};
131
132
133
};
134
135
#endif
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (
www.mak.com
)