tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
ICClass.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 "ICClass.hpp"
20 #include <tobicore/TCTools.hpp>
21 #include <tobicore/TCException.hpp>
22 #include <string.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <sstream>
26 
27 #ifdef __BORLANDC__
28 using namespace std;
29 #endif
30 
32  this->SetValue(value);
33  this->SetLabel(label);
34 }
35 
36 ICClass::ICClass(unsigned int label, ICValue value) {
37  this->SetValue(value);
38  this->SetLabel(label);
39 }
40 
42 }
43 
45  return this->_value;
46 }
47 
49  return this->_label;
50 }
51 
52 unsigned int ICClass::GetLabelUInt(void) const {
53  return atoi(this->_label.c_str());
54 }
55 
57  this->_value = value;
58  return this;
59 }
60 
62  if(label.size() > ICCLASS_CHLABEL_SIZE)
63  throw TCException("ICCLASS_CHLABEL_SIZE exceeded",
64  #ifdef _WIN32
65  __FUNCSIG__
66  #else
67  __PRETTY_FUNCTION__
68  #endif
69  );
70 
71  this->_label = label;
72  return this;
73 }
74 
75 ICClass* ICClass::SetLabel(unsigned int label) {
76  std::stringstream stream;
77  stream << label;
78 
79  return this->SetLabel(stream.str());
80 }
81 
82 const char* ICClass::GetChLabel(void) {
83  memset(this->_chlabel, 0, ICCLASS_CHLABEL_SIZE* sizeof(char));
84  strcpy(this->_chlabel, this->_label.c_str());
85  return (const char*)(this->_chlabel);
86 }
87 
88 const char* ICClass::GetChValue(void) {
89  memset(this->_chvalue, 0, ICCLASS_CHVALUE_SIZE * sizeof(char));
90  TCTools::ftoa(this->_value, this->_chvalue);
91  return (const char*)(this->_chvalue);
92 }
93