CEBL
2.1
Main Page
Namespaces
Data Structures
Files
File List
Globals
Param.hpp
Go to the documentation of this file.
1
/*
2
* CEBL : CSU EEG Brain-Computer Interface Lab
3
*
4
* Author: Jeshua Bratman - jeshuabratman@gmail.com
5
*
6
* This file is part of CEBL.
7
*
8
* CEBL is free software; you can redistribute it and/or modify it.
9
* We only ask that if you use our code that you cite the source in
10
* your project or publication.
11
*
12
* EEG Group (www.cs.colostate.edu/eeg)
13
* Department of Computer Science
14
* Colorado State University
15
*
16
*/
17
23
#ifndef PARAM_H
24
#define PARAM_H
25
#include <string>
26
#include <values.h>
27
using
std::string;
28
29
namespace
CEBL
30
{
31
32
enum
ParamID
33
{
34
PARAM_BOOLEAN
,
35
PARAM_INTEGER
,
36
PARAM_DOUBLE
,
37
PARAM_STRING
38
};
39
40
union
ParamDataUnion
41
{
42
double
d
;
43
int
i
;
44
bool
b
;
45
};
46
47
//Paramater type
48
class
Param
49
{
50
private
:
51
ParamID
id;
52
ParamDataUnion
data;
53
ParamDataUnion
max;
54
ParamDataUnion
min;
55
ParamDataUnion
step;
56
string
s;
57
58
public
:
59
60
std::string
name
;
61
std::string
description
;
62
63
//constructors for different data types
64
Param
()
65
{
66
67
}
68
69
Param
(std::string
name
, std::string
description
,
double
value)
70
{
71
this->name =
name
;
72
this->description =
description
;
73
data.
d
= value;
74
min.
d
= -MAXDOUBLE;
75
max.
d
= MAXDOUBLE;
76
step.
d
= .5;
77
id
=
PARAM_DOUBLE
;
78
}
79
80
Param
(std::string
name
, std::string
description
,
string
value)
81
{
82
this->name =
name
;
83
this->description =
description
;
84
s = value;
85
id
=
PARAM_STRING
;
86
}
87
88
Param
(std::string
name
, std::string
description
,
int
value)
89
{
90
this->name =
name
;
91
this->description =
description
;
92
data.
i
= value;
93
min.
i
= -MAXINT;
94
max.
i
= MAXINT;
95
step.
i
= 1;
96
id
=
PARAM_INTEGER
;
97
}
98
99
Param
(std::string
name
, std::string
description
,
bool
value)
100
{
101
this->name =
name
;
102
this->description =
description
;
103
data.
b
= value;
104
id
=
PARAM_BOOLEAN
;
105
}
106
107
Param
(std::string
name
, std::string
description
,
ParamID
value)
108
{
109
this->name =
name
;
110
this->description =
description
;
111
id
= value;
112
}
113
114
Param
(
const
Param
&p)
115
{
116
this->
name
= p.
name
;
117
this->
description
= p.
description
;
118
this->
id
= p.id;
119
this->data = p.data;
120
this->s = p.s;
121
this->max = p.max;
122
this->min = p.min;
123
this->step = p.step;
124
}
125
126
void
setDouble
(
double
value)
127
{
128
data.
d
= value;
129
}
130
131
void
setInt
(
int
value)
132
{
133
data.
i
= value;
134
}
135
136
void
setBool
(
bool
value)
137
{
138
data.
b
= value;
139
}
140
141
void
setString
(
string
value)
142
{
143
s = value;
144
}
145
146
double
getDouble
()
const
147
{
148
return
data.
d
;
149
}
150
151
int
getInt
()
const
152
{
153
return
data.
i
;
154
}
155
156
bool
getBool
()
const
157
{
158
return
data.
b
;
159
}
160
161
string
getString
()
const
162
{
163
return
s;
164
}
165
166
167
//check what type of data this is
168
bool
operator==
(
ParamID
id
)
169
{
170
return
id
==this->id;
171
}
172
173
void
setMax
(
double
max)
174
{
175
this->max.d = max;
176
}
177
178
void
setMin
(
double
min)
179
{
180
this->min.d = min;
181
}
182
183
void
setStep
(
double
step)
184
{
185
this->step.d = step;
186
}
187
188
void
setMax
(
int
max)
189
{
190
this->max.i = max;
191
}
192
193
void
setMin
(
int
min)
194
{
195
this->min.i = min;
196
}
197
198
void
setStep
(
int
step)
199
{
200
this->step.i = step;
201
}
202
203
//return max and min
204
double
getMax
()
const
205
{
206
switch
(
id
)
207
{
208
case
PARAM_DOUBLE
:
209
return
max.
d
;
210
default
:
211
return
this->max.
i
;
212
}
213
}
214
215
double
getMin
()
const
216
{
217
switch
(
id
)
218
{
219
case
PARAM_DOUBLE
:
220
return
min.
d
;
221
default
:
222
return
min.
i
;
223
}
224
}
225
226
double
getStep
()
const
227
{
228
switch
(
id
)
229
{
230
case
PARAM_DOUBLE
:
231
return
step.
d
;
232
default
:
233
return
step.
i
;
234
}
235
}
236
};
237
}
238
#endif
Generated by
1.8.1.1