tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
ICClassifier.cpp
1 /*
2  Copyright (C) 2009-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
3  Michele Tavella <michele.tavella@epfl.ch>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "ICClassifier.hpp"
20 #include <tobicore/TCException.hpp>
21 #include <string.h>
22 
23 #ifdef __BORLANDC__
24 using namespace std;
25 #endif
26 
27 std::string ICClassifier::TxtLabelUndef("LabelUndef");
28 std::string ICClassifier::TxtLabelBiosig("LabelBiosig");
29 std::string ICClassifier::TxtLabelCustom("LabelCustom");
30 std::string ICClassifier::TxtLabelClass("LabelClass");
31 std::string ICClassifier::TxtValueUndef("ValueUndef");
32 std::string ICClassifier::TxtValueProb("ValueProb");
33 std::string ICClassifier::TxtValueDist("ValueDist");
34 std::string ICClassifier::TxtValueCLbl("ValueCLbl");
35 std::string ICClassifier::TxtValueRCoe("ValueRCoe");
36 
37 ICClassifier::ICClassifier(const std::string& name, const std::string& desc) {
38  this->_name = name;
39  this->_desc = desc;
40  this->_vtype = ICClassifier::ValueUndef;
41  this->_ltype = ICClassifier::LabelUndef;
42 }
43 
44 ICClassifier::ICClassifier(const std::string& name, const std::string& desc,
45  ICVtype vtype, ICLtype ltype) {
46  this->_name = name;
47  this->_desc = desc;
48  this->_vtype = vtype;
49  this->_ltype = ltype;
50 }
51 
52 ICClassifier::~ICClassifier() {
53 }
54 
55 std::string ICClassifier::GetName(void) const {
56  return this->_name;
57 }
58 
59 std::string ICClassifier::GetDescription(void) const {
60  return this->_desc;
61 }
62 
63 const char* ICClassifier::GetChName(void) {
64  if(this->_name.size() > ICCLASSIFIER_CHNAME_SIZE)
65  throw TCException("ICCLASSIFIER_CHNAME_SIZE exceeded",
66  #ifdef _WIN32
67  __FUNCSIG__
68  #else
69  __PRETTY_FUNCTION__
70  #endif
71  );
72 
73  strcpy(this->_chname, this->_name.c_str());
74  return this->_chname;
75 }
76 
77 const char* ICClassifier::GetChDescription(void) {
78  if(this->_desc.size() > ICCLASSIFIER_CHDESC_SIZE)
79  throw TCException("ICCLASSIFIER_CHDESC_SIZE exceeded",
80  #ifdef _WIN32
81  __FUNCSIG__
82  #else
83  __PRETTY_FUNCTION__
84  #endif
85  );
86 
87  strcpy(this->_chdesc, this->_desc.c_str());
88  return this->_chdesc;
89 }
90 
92  if(vtype < ICClassifier::ValueUndef || vtype > ICClassifier::ValueRCoe)
93  return false;
94  this->_vtype = vtype;
95  return true;
96 }
97 
99  if(ltype < ICClassifier::LabelUndef || ltype > ICClassifier::LabelClass)
100  return false;
101  this->_ltype = ltype;
102  return true;
103 }
104 
105 bool ICClassifier::SetValueType(std::string vtype) {
106  if(vtype.compare(ICClassifier::TxtValueUndef) == 0)
107  this->_vtype = ICClassifier::ValueUndef;
108  else if(vtype.compare(ICClassifier::TxtValueProb) == 0)
109  this->_vtype = ICClassifier::ValueProb;
110  else if(vtype.compare(ICClassifier::TxtValueDist) == 0)
111  this->_vtype = ICClassifier::ValueDist;
112  else if(vtype.compare(ICClassifier::TxtValueCLbl) == 0)
113  this->_vtype = ICClassifier::ValueCLbl;
114  else if(vtype.compare(ICClassifier::TxtValueRCoe) == 0)
115  this->_vtype = ICClassifier::ValueRCoe;
116  else
117  return false;
118  return true;
119 }
120 
121 bool ICClassifier::SetLabelType(std::string ltype) {
122  if(ltype.compare(TxtLabelUndef) == 0)
123  this->_ltype = ICClassifier::LabelUndef;
124  else if(ltype.compare(TxtLabelBiosig) == 0)
125  this->_ltype = ICClassifier::LabelBiosig;
126  else if(ltype.compare(TxtLabelCustom) == 0)
127  this->_ltype = ICClassifier::LabelCustom;
128  else if(ltype.compare(TxtLabelClass) == 0)
129  this->_ltype = ICClassifier::LabelClass;
130  else
131  return false;
132  return true;
133 }
134 
135 
137  return this->_vtype;
138 }
139 
141  return this->_ltype;
142 }
143 
144 ICVtype ICClassifier::ValueType(const std::string& vtype) {
146 
147  if(vtype.compare(ICTYPES_ENTRY_PROB) == 0)
148  cvtype = ICClassifier::ValueProb;
149  else if(vtype.compare(ICTYPES_ENTRY_DIST) == 0)
150  cvtype = ICClassifier::ValueDist;
151  else if(vtype.compare(ICTYPES_ENTRY_CLBL) == 0)
152  cvtype = ICClassifier::ValueCLbl;
153  else if(vtype.compare(ICTYPES_ENTRY_RCOE) == 0)
154  cvtype = ICClassifier::ValueRCoe;
155 
156  return cvtype;
157 }
158 
159 ICLtype ICClassifier::LabelType(const std::string& ltype) {
161 
162  if(ltype.compare(ICTYPES_LABEL_CUSTOM) == 0)
163  cltype = ICClassifier::LabelCustom;
164  else if(ltype.compare(ICTYPES_LABEL_BIOSIG) == 0)
165  cltype = ICClassifier::LabelBiosig;
166  else if(ltype.compare(ICTYPES_LABEL_CLASS) == 0)
167  cltype = ICClassifier::LabelClass;
168 
169  return cltype;
170 }
171 
172 ICVtype ICClassifier::ValueChType(const char* vtype) {
173  if(vtype == NULL)
174  throw TCException("vtype is NULL",
175  #ifdef _WIN32
176  __FUNCSIG__
177  #else
178  __PRETTY_FUNCTION__
179  #endif
180  );
182 
183  if(strcmp(vtype, ICTYPES_ENTRY_PROB) == 0)
184  cvtype = ICClassifier::ValueProb;
185  else if(strcmp(vtype, ICTYPES_ENTRY_DIST) == 0)
186  cvtype = ICClassifier::ValueDist;
187  else if(strcmp(vtype, ICTYPES_ENTRY_CLBL) == 0)
188  cvtype = ICClassifier::ValueCLbl;
189  else if(strcmp(vtype, ICTYPES_ENTRY_RCOE) == 0)
190  cvtype = ICClassifier::ValueRCoe;
191 
192  return cvtype;
193 }
194 
195 ICLtype ICClassifier::LabelChType(const char* ltype) {
196  if(ltype == NULL)
197  throw TCException("ltype is NULL",
198  #ifdef _WIN32
199  __FUNCSIG__
200  #else
201  __PRETTY_FUNCTION__
202  #endif
203  );
205 
206  if(strcmp(ltype, ICTYPES_LABEL_CUSTOM) == 0)
207  cltype = ICClassifier::LabelCustom;
208  else if(strcmp(ltype, ICTYPES_LABEL_BIOSIG) == 0)
209  cltype = ICClassifier::LabelBiosig;
210  else if(strcmp(ltype, ICTYPES_LABEL_CLASS) == 0)
211  cltype = ICClassifier::LabelClass;
212 
213  return cltype;
214 }