Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Properties.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef PROPERTIES_H
27 #define PROPERTIES_H
28 
29 #include <libxml/tree.h>
30 //#include <libxml/parser.h>
31 
32 #include "PhysicalModelIO.h"
33 #include <string>
34 #include <sstream>
35 #include <map>
36 class PhysicalModel;
57 class Properties {
58 
59 public:
61  Properties(const std::string n="");
62 
64  Properties(PhysicalModel *, const std::string n="");
65 
67  virtual ~Properties();
68 
70  std::string getName() const;
71 
73  void setName(std::string);
74 
77 
80 
83  void domToFields(xmlNodePtr node);
85 
87  unsigned int numberOfFields() const;
88 
90  bool isAField(std::string attName) const;
91 
95  std::string getField(unsigned int) const;
96 
98  double getDouble(std::string attName);
99 
101  int getInt(std::string attName) const;
102 
104  bool getBool(std::string attName) const;
105 
107  std::string getString(std::string attName) const;
108 
110  void get(std::string attName, std::string &attVal) const;
111 
113  void set(std::string attName, double val);
114 
116  void set(std::string attName, int val);
117 
119  void set(std::string attName, bool val);
120 
122  void set(std::string attName, std::string val);
124 
125 protected :
127  std::map<std::string, std::string> fields;
128 
129 private:
131  std::string name;
132 
135 
136 };
137 
138 inline bool Properties::isAField(std::string attName) const {
139  std::map<std::string, std::string>::const_iterator it = fields.find(attName);
140  return (it != fields.end());
141 }
142 
143 inline double Properties::getDouble(std::string attName) {
144  std::map<std::string, std::string>::iterator it = fields.find(attName);
145 
146  if (it != fields.end())
147  return atof( it->second.c_str());
148  else
149  return 0.0;
150 }
151 
152 inline int Properties::getInt(std::string attName) const{
153  std::map<std::string, std::string>::const_iterator it = fields.find(attName);
154 
155  if (it != fields.end())
156  return atoi( it->second.c_str());
157  else
158  return 0;
159 }
160 
161 inline bool Properties::getBool(std::string attName) const {
162  std::map<std::string, std::string>::const_iterator it = fields.find(attName);
163 
164  if(it == fields.end() || it->second =="false" || it->second =="0")
165  return false;
166  else
167  return true;
168 }
169 
170 inline std::string Properties::getString(std::string attName) const {
171  std::map<std::string, std::string>::const_iterator it = fields.find(attName);
172 
173  if (it != fields.end())
174  return it->second;
175  else
176  return "";
177 }
178 
179 inline void Properties::get(std::string attName, std::string &attVal) const {
180  std::map<std::string, std::string>::const_iterator it = fields.find(attName);
181 
182  if (it != fields.end())
183  attVal = it->second;
184  else
185  attVal = "";
186 }
187 
188 inline void Properties::set(std::string attName, double val) {
189  std::ostringstream oss;
190  oss << val;
191  std::map<std::string, std::string>::iterator it = fields.find(attName);
192 
193  if (it != fields.end())
194  it->second = oss.str();
195  else
196  fields.insert(std::pair<std::string, std::string>(attName, oss.str()));
197 }
198 
199 inline void Properties::set(std::string attName, int val) {
200  std::ostringstream oss;
201  oss << val;
202  std::map<std::string, std::string>::iterator it = fields.find(attName);
203 
204  if (it != fields.end())
205  it->second = oss.str() ;
206  else
207  fields.insert(std::pair<std::string, std::string>(attName, oss.str()));
208 }
209 
210 inline void Properties::set(std::string attName, bool val) {
211  std::ostringstream oss;
212  oss << val;
213  std::map<std::string, std::string>::iterator it = fields.find(attName);
214 
215  if (it != fields.end())
216  it->second = oss.str() ;
217  else
218  fields.insert(std::pair<std::string, std::string>(attName, oss.str()));
219 }
220 
221 inline void Properties::set(std::string attName, std::string val) {
222  std::map<std::string, std::string>::iterator it = fields.find(attName);
223 
224  if (it != fields.end())
225  it->second = val ;
226  else
227  fields.insert(std::pair<std::string, std::string>(attName, val));
228 }
229 
230 inline std::string Properties::getName() const {
231  return name;
232 }
233 
234 inline void Properties::setName(std::string n) {
235  name = std::string(n);
236 }
237 
239  myPM = pm;
240 }
241 
243  return myPM;
244 }
245 
246 #endif //PROPERTIES_H
void domToFields(xmlNodePtr node)
convert the xml node parameters to data fields
void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: Properties.h:238
int getInt(std::string attName) const
field accessor: get the field attName as an int value, if field does not exist, 0 is return ...
Definition: Properties.h:152
Properties(const std::string n="")
A nice simple constructor, with a given name.
void setName(std::string)
set the name (use the string = operator)
Definition: Properties.h:234
bool isAField(std::string attName) const
check if the field exist in the XML document, return false if it does not
Definition: Properties.h:138
std::string getName() const
get the name (be careful, this method DOES NOT return a copy, so you got the direct ptr to the name!!...
Definition: Properties.h:230
virtual ~Properties()
The default destructor.
void set(std::string attName, double val)
field modificator: set field attName using a double value
Definition: Properties.h:188
Describes the properties common to all structures and components.
Definition: Properties.h:57
std::string getField(unsigned int) const
get the name of field of given index
std::map< std::string, std::string > fields
map containing all the different fields (name, value stored as string )
Definition: Properties.h:127
bool getBool(std::string attName) const
field accessor: get the field attName as a bool value, if field does not exist, false is return ...
Definition: Properties.h:161
unsigned int numberOfFields() const
get the number of extra fields found in the PML
PhysicalModel * myPM
pointer to the physical model the object is in
Definition: Properties.h:134
double getDouble(std::string attName)
field accessor: get the field attName as a double value, if field does not exist, 0...
Definition: Properties.h:143
This is the main class of this project.
Definition: PhysicalModel.h:74
std::string name
name of the physical model object
Definition: Properties.h:131
std::string getString(std::string attName) const
field accessor: get the field attName as a string value, if field does not exist, empty string is ret...
Definition: Properties.h:170
PhysicalModel * getPhysicalModel() const
get the physical model
Definition: Properties.h:242
void get(std::string attName, std::string &attVal) const
field accessor: get the field attName as a string value in attVal, if field does not exist...
Definition: Properties.h:179