tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
ICSetClass.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 "ICSetClass.hpp"
20 #include <tobicore/TCException.hpp>
21 #include <tobicore/TCTools.hpp>
22 
23 #ifdef __BORLANDC__
24 using namespace std;
25 #endif
26 
28 }
29 
31  this->_map.clear();
32 }
33 
35  if(pclass == NULL)
36  throw TCException("pclass is NULL",
37  #ifdef _WIN32
38  __FUNCSIG__
39  #else
40  __PRETTY_FUNCTION__
41  #endif
42  );
43 
44  ICSetClassIter it = this->_map.find(pclass->GetLabel());
45  if(it != this->_map.end())
46  throw TCException("ICLabel already present",
47  #ifdef _WIN32
48  __FUNCSIG__
49  #else
50  __PRETTY_FUNCTION__
51  #endif
52  );
53 
54  this->_map[pclass->GetLabel()] = pclass;
55  return pclass;
56 }
57 
59  ICSetClassIter it = this->_map.find(lclass);
60  if(it == this->_map.end())
61  throw TCException("ICLabel not found",
62  #ifdef _WIN32
63  __FUNCSIG__
64  #else
65  __PRETTY_FUNCTION__
66  #endif
67  );
68 
69  ICClass* retval = (*it).second;
70  this->_map.erase(it);
71  return retval;
72 }
73 
74 ICClass* ICSetClass::Remove(unsigned int lclass) {
75  return this->Remove(TCTools::itos(lclass));
76 }
77 
79  if(pclass == NULL)
80  throw TCException("pclass is NULL",
81  #ifdef _WIN32
82  __FUNCSIG__
83  #else
84  __PRETTY_FUNCTION__
85  #endif
86  );
87 
88  return this->Remove(pclass->GetLabel());
89 }
90 
92  ICSetClassConstIter it = this->_map.find(lclass);
93  if(it == this->_map.end())
94  throw TCException("ICLabel not found",
95  #ifdef _WIN32
96  __FUNCSIG__
97  #else
98  __PRETTY_FUNCTION__
99  #endif
100  );
101 
102  ICClass* retval = (*it).second;
103  return retval;
104 }
105 
106 ICClass* ICSetClass::Get(unsigned int lclass) const {
107  return this->Get(TCTools::itos(lclass));
108 }
109 
110 ICClass* ICSetClass::Get(ICClass* pclass) const {
111  return this->Get(pclass->GetLabel());
112 }
113 
114 bool ICSetClass::Has(ICLabel name) const {
115  ICSetClassConstIter it = this->_map.find(name);
116  return(it != this->_map.end());
117 }
118 
119 bool ICSetClass::Has(unsigned int name) const {
120  return this->Has(TCTools::itos(name));
121 }
122 
123 bool ICSetClass::Has(ICClass* klass) const {
124  ICSetClassConstIter it = this->_map.find(klass->GetLabel());
125  return(it != this->_map.end());
126 }
127 
128 bool ICSetClass::Empty(void) const {
129  return this->_map.empty();
130 }
131 
132 unsigned int ICSetClass::Size(void) const {
133  return this->_map.size();
134 }
135 
136 void ICSetClass::Clear(void) {
137  this->_map.clear();
138 }
139 
141  ICSetClassIter kit = this->Begin();
142  while(kit != this->End()) {
143  ICClass* kptr = (*kit).second;
144  if(kptr != NULL)
145  delete kptr;
146  }
147  this->Clear();
148 }
149 
151  ICSetClassIter it = this->_map.begin();
152  return it;
153 }
154 
156  ICSetClassIter it = this->_map.end();
157  return it;
158 }
159 
161  ICSetClassConstIter it = this->_map.begin();
162  return it;
163 }
164 
166  ICSetClassConstIter it = this->_map.end();
167  return it;
168 }