OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | Friends | List of all members
olb::XMLreader Class Reference

#include <xmlReader.h>

+ Collaboration diagram for olb::XMLreader:

Public Member Functions

 XMLreader (TiXmlNode *pParent, OutputChannel outputChannel=OutputChannel::ERRCHANNEL)
 Constructs a new XMLreader from another XMLreader.
 
 XMLreader (const std::string &fName, OutputChannel outputChannel=OutputChannel::ERRCHANNEL)
 Constructs a new XMLreader from a XML file fName.
 
 ~XMLreader ()
 destructor
 
template<typename T >
bool read (T &value, bool verboseOn=true, bool exitIfMissing=false) const
 Prints out the XML structure read in, mostly for debugging purposes.
 
template<typename T , unsigned DIM>
bool read (util::ADf< T, DIM > &value, bool verboseOn=true, bool exitIfMissing=false) const
 
template<typename T >
bool read (std::vector< T > &value, bool verboseOn=true, bool exitIfMissing=false) const
 
template<typename T >
get (bool verboseOn=true, bool exitIfMissing=false) const
 
template<typename ParameterType >
bool readOrWarn (std::string name_parameter_1, std::string name_parameter_2, std::string name_parameter_3, ParameterType &var, bool defaultAvailable=true, bool exitIfMissing=false, bool showWarning=true) const
 This wrapper function reads the given parameter from the "type_parameter" and "name_parameter_1" or "name_parameter_2" tag and prints a warning, if the parameter can not be read.
 
template<typename ParameterType >
bool readOrWarn (std::string name_parameter_1, std::string name_parameter_2, std::string name_parameter_3, std::string name_parameter_4, ParameterType &var, bool defaultAvailable=true, bool exitIfMissing=false, bool showWarning=true) const
 
XMLreader const & operator[] (std::string name) const
 
std::vector< XMLreader * >::const_iterator begin () const
 Returns an iterator.begin() of the child XMLreader This means an iterator to the next level on an XML tree.
 
std::vector< XMLreader * >::const_iterator end () const
 Returns an iterator.end() of the child XMLreader This means an iterator to the next level on an XML tree.
 
void setWarningsOn (bool warnings) const
 switch warnings on/off
 
std::string getName () const
 return the name of the element
 
std::string getText () const
 return the text of the element
 
std::string getAttribute (const std::string &aName) const
 
template<>
bool read (bool &value, bool verboseOn, bool exitIfMissing) const
 
template<>
bool read (int &value, bool verboseOn, bool exitIfMissing) const
 
template<>
bool read (double &value, bool verboseOn, bool exitIfMissing) const
 
template<>
bool read (long double &value, bool verboseOn, bool exitIfMissing) const
 
template<>
bool read (float &value, bool verboseOn, bool exitIfMissing) const
 

Public Attributes

XMLreaderOutput _output
 handling all the output for the XMLreader
 

Protected Attributes

std::map< std::string, std::string > _attributes
 
std::vector< XMLreader * > _children
 

Friends

class olb::XMLreaderOutput
 

Detailed Description

Definition at line 49 of file xmlReader.h.

Constructor & Destructor Documentation

◆ XMLreader() [1/2]

olb::XMLreader::XMLreader ( TiXmlNode * pParent,
OutputChannel outputChannel = OutputChannel::ERRCHANNEL )

Constructs a new XMLreader from another XMLreader.

Parameters
pParentThe new root node for the XMLreader

Definition at line 244 of file xmlReader.h.

244 : _output(outputChannel)
245{
246 _outputChannel = outputChannel;
247 _warningsOn = true;
248
249 if (singleton::mpi().isMainProcessor()) {
250 mainProcessorIni(pParent);
251 }
252 else {
253 slaveProcessorIni();
254 }
255}
XMLreaderOutput _output
handling all the output for the XMLreader
Definition xmlReader.h:106
MpiManager & mpi()

References olb::singleton::mpi().

+ Here is the call graph for this function:

◆ XMLreader() [2/2]

olb::XMLreader::XMLreader ( const std::string & fName,
OutputChannel outputChannel = OutputChannel::ERRCHANNEL )

Constructs a new XMLreader from a XML file fName.

Definition at line 257 of file xmlReader.h.

257 : _output(outputChannel)
258{
259 _outputChannel = outputChannel;
260 _warningsOn = true;
261
262 TiXmlDocument* doc = nullptr;
263 int loadOK = false;
264#ifdef PARALLEL_MODE_MPI // parallel program execution
265 if (singleton::mpi().isMainProcessor()) {
266#endif
267 std::string docName = std::string(fName); // call copy constructor
268 doc = new TiXmlDocument(docName.c_str());
269 loadOK = doc->LoadFile();
270 _output.loadFile(loadOK, fName);
271#ifdef PARALLEL_MODE_MPI // parallel program execution
272 }
273 if (singleton::mpi().isMainProcessor()) {
274#endif
275 mainProcessorIni(doc);
276 delete doc;
277#ifdef PARALLEL_MODE_MPI // parallel program execution
278 }
279 else {
280 slaveProcessorIni();
281 }
282#endif
283}
void loadFile(bool loadOK, std::string fName) const

References _output, olb::XMLreaderOutput::loadFile(), and olb::singleton::mpi().

+ Here is the call graph for this function:

◆ ~XMLreader()

olb::XMLreader::~XMLreader ( )

destructor

Definition at line 285 of file xmlReader.h.

286{
287 for (unsigned int iNode=0; iNode<_children.size(); ++iNode) {
288 delete _children[iNode];
289 }
290}
std::vector< XMLreader * > _children
Definition xmlReader.h:119

References _children.

Member Function Documentation

◆ begin()

std::vector< XMLreader * >::const_iterator olb::XMLreader::begin ( ) const

Returns an iterator.begin() of the child XMLreader This means an iterator to the next level on an XML tree.

Definition at line 392 of file xmlReader.h.

393{
394 return _children.begin();
395}

References _children, and begin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ end()

std::vector< XMLreader * >::const_iterator olb::XMLreader::end ( ) const

Returns an iterator.end() of the child XMLreader This means an iterator to the next level on an XML tree.

Definition at line 397 of file xmlReader.h.

398{
399 return _children.end();
400}

References _children.

+ Here is the caller graph for this function:

◆ get()

template<typename T >
T olb::XMLreader::get ( bool verboseOn = true,
bool exitIfMissing = false ) const

Definition at line 163 of file xmlReader.h.

164{
165 std::stringstream valueStr(_text);
166 T tmp = T();
167 if (!(valueStr >> tmp)) {
168// if ( verboseOn ) {
169// clout << "Error: cannot read value from XML element " << _name << std::endl;
170// }
171 _output.printWarning(_name, typeid(T).name(), "", verboseOn, exitIfMissing);
172 }
173 return tmp;
174}
void printWarning(std::string name, std::string typeName, std::string value, bool verboseOn, bool exitIfMissing) const
print warning if verbose mode is on and exit, if exItMissing is true
std::string name()
Returns distinct name on GCC, Clang and ICC but may return arbitrary garbage as per the standard.
Definition meta.h:100

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ getAttribute()

std::string olb::XMLreader::getAttribute ( const std::string & aName) const
Returns
the value of attribute

Definition at line 541 of file xmlReader.h.

542{
543 std::map<std::string, std::string>::const_iterator it = _attributes.find(aName);
544 if ( it == _attributes.end()) {
545 return "Attribute not found.";
546 }
547 return it->second;
548 //return attributes[aName];
549}
std::map< std::string, std::string > _attributes
Definition xmlReader.h:118

References _attributes.

+ Here is the caller graph for this function:

◆ getName()

std::string olb::XMLreader::getName ( ) const

return the name of the element

Definition at line 402 of file xmlReader.h.

403{
404 return _name;
405}
+ Here is the caller graph for this function:

◆ getText()

std::string olb::XMLreader::getText ( ) const

return the text of the element

Definition at line 407 of file xmlReader.h.

408{
409 return _text;
410}

◆ operator[]()

XMLreader const & olb::XMLreader::operator[] ( std::string name) const
Returns
a Subtree placed at name
Parameters
nameThe name from which to take the subtree

Definition at line 381 of file xmlReader.h.

382{
383 for (unsigned int iNode=0; iNode<_children.size(); ++iNode) {
384 if (_children[iNode]->_name == fName) {
385 return *_children[iNode];
386 }
387 }
388 _output.readValue(_warningsOn, _name, fName);
389 return _notFound;
390}
void readValue(bool warningsOn, std::string name, std::string fName) const

References _children, _output, and olb::XMLreaderOutput::readValue().

+ Here is the call graph for this function:

◆ read() [1/8]

template<>
bool olb::XMLreader::read ( bool & value,
bool verboseOn,
bool exitIfMissing ) const

Definition at line 422 of file xmlReader.h.

423{
424 std::stringstream valueStr(_text);
425 std::string word;
426 valueStr >> word;
427 // Transform to lower-case, so that "true" and "false" are case-insensitive.
428 std::transform(word.begin(), word.end(), word.begin(), ::tolower);
429 if (!word.compare("true") || (word=="1")) {
430 value = true;
431 return true;
432 }
433 else if (!word.compare("false") || (word=="0")) {
434 value=false;
435 return true;
436 }
437 else {
438 if ( verboseOn ) {
439 std::stringstream ss;
440 ss << ( value ? "true" : "false" );
441 _output.printWarning(_name, "bool", ss.str(), verboseOn, exitIfMissing);
442 }
443 }
444 return false;
445}
typename std::integral_constant< TYPE, VALUE >::type value
Identity type to wrap non-type template arguments.
Definition meta.h:96

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ read() [2/8]

template<>
bool olb::XMLreader::read ( double & value,
bool verboseOn,
bool exitIfMissing ) const

Definition at line 481 of file xmlReader.h.

482{
483 std::stringstream valueStr(_text);
484 double tmp = double();
485 if (!(valueStr >> tmp)) {
486 _output.printWarning(_name, "double", std::to_string(value), verboseOn, exitIfMissing);
487 return false;
488 }
489 value = tmp;
490 return true;
491}

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ read() [3/8]

template<>
bool olb::XMLreader::read ( float & value,
bool verboseOn,
bool exitIfMissing ) const

Definition at line 508 of file xmlReader.h.

509{
510 std::stringstream valueStr(_text);
511 float tmp = float();
512 if (!(valueStr >> tmp)) {
513 std::stringstream ss;
514 ss << value;
515 _output.printWarning(_name, "float", ss.str(), verboseOn, exitIfMissing);
516 return false;
517 }
518 value = tmp;
519 return true;
520}

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ read() [4/8]

template<>
bool olb::XMLreader::read ( int & value,
bool verboseOn,
bool exitIfMissing ) const

Definition at line 449 of file xmlReader.h.

450{
451 std::stringstream valueStr(_text);
452 int tmp = int();
453 if (!(valueStr >> tmp)) {
454 std::stringstream ss;
455 ss << value;
456 _output.printWarning(_name, "int", ss.str(), verboseOn, exitIfMissing);
457 return false;
458 }
459 value = tmp;
460 return true;
461}

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ read() [5/8]

template<>
bool olb::XMLreader::read ( long double & value,
bool verboseOn,
bool exitIfMissing ) const

Definition at line 495 of file xmlReader.h.

496{
497 std::stringstream valueStr(_text);
498 std::string tmp {};
499 if (!(valueStr >> tmp)) {
500 _output.printWarning(_name, "long double", std::to_string(value), verboseOn, exitIfMissing);
501 return false;
502 }
503 value = std::stold(tmp);
504 return true;
505}

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ read() [6/8]

template<typename T >
bool olb::XMLreader::read ( std::vector< T > & value,
bool verboseOn = true,
bool exitIfMissing = false ) const

Definition at line 141 of file xmlReader.h.

142{
143 std::stringstream multiValueStr(_text);
144 std::string word;
145 std::vector<T> tmp(values);
146 while (multiValueStr>>word) {
147 std::stringstream valueStr(word);
148 T value;
149 if (!(valueStr >> value)) {
150// if ( verboseOn ) {
151// clout << std::string("Error: cannot read value array from XML element ") << _name << std::endl;
152// }
153 _output.printWarning(_name, "std::vector", "", verboseOn, exitIfMissing);
154 return false;
155 }
156 tmp.push_back(value);
157 }
158 values.swap(tmp);
159 return true;
160}

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ read() [7/8]

template<typename T >
bool olb::XMLreader::read ( T & value,
bool verboseOn = true,
bool exitIfMissing = false ) const

Prints out the XML structure read in, mostly for debugging purposes.

Read a value from the xml file

Parameters
referenceto return the value
Returns
returns the value
+ Here is the caller graph for this function:

◆ read() [8/8]

template<typename T , unsigned DIM>
bool olb::XMLreader::read ( util::ADf< T, DIM > & value,
bool verboseOn = true,
bool exitIfMissing = false ) const

Definition at line 125 of file xmlReader.h.

126{
127 std::stringstream valueStr(_text);
128 T tmp = T();
129 if (!(valueStr >> tmp)) {
130// if ( _verboseOn ) {
131// clout << std::string("Error: cannot read value from XML element ") << _name << std::endl;
132// }
133 _output.printWarning(_name, "ADf vector", "", verboseOn, exitIfMissing);
134 return false;
135 }
136 value = util::ADf<T,DIM>(tmp);
137 return true;
138}

References _output, and olb::XMLreaderOutput::printWarning().

+ Here is the call graph for this function:

◆ readOrWarn() [1/2]

template<typename ParameterType >
bool olb::XMLreader::readOrWarn ( std::string name_parameter_1,
std::string name_parameter_2,
std::string name_parameter_3,
ParameterType & var,
bool defaultAvailable = true,
bool exitIfMissing = false,
bool showWarning = true ) const

This wrapper function reads the given parameter from the "type_parameter" and "name_parameter_1" or "name_parameter_2" tag and prints a warning, if the parameter can not be read.

The warning contains the default value, if available. Will exit(1) if exitIfMissing == true. The warning is not displayed, if showWarning == false.

Definition at line 178 of file xmlReader.h.

181{
182 // deactivate default warnings and show default values instead
183 setWarningsOn(false);
184 if (name_parameter_3 == "") {
185 if (!(*this)[name_parameter_1][name_parameter_2].read<ParameterType>(var, false)) {
186 _output.parameterReading({name_parameter_1, name_parameter_2}, var, defaultAvailable, exitIfMissing, showWarning);
187 return false;
188 }
189 return true;
190 }
191 else{
192 if (!(*this)[name_parameter_1][name_parameter_2][name_parameter_3].read<ParameterType>(var, false)) {
193 _output.parameterReading({name_parameter_1, name_parameter_2, name_parameter_3}, var, defaultAvailable, exitIfMissing, showWarning);
194 return false;
195 }
196 return true;
197 }
198 // turn default warnings on again
199 setWarningsOn(true);
200}
void parameterReading(std::vector< std::string > parameters, ParameterType &var, bool defaultAvailable, bool exitIfMissing, bool showWarning) const
void setWarningsOn(bool warnings) const
switch warnings on/off
Definition xmlReader.h:412

References _output, olb::XMLreaderOutput::parameterReading(), and setWarningsOn().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readOrWarn() [2/2]

template<typename ParameterType >
bool olb::XMLreader::readOrWarn ( std::string name_parameter_1,
std::string name_parameter_2,
std::string name_parameter_3,
std::string name_parameter_4,
ParameterType & var,
bool defaultAvailable = true,
bool exitIfMissing = false,
bool showWarning = true ) const
Returns
a Subtree placed at name
Parameters
nameThe name from which to take the subtree

Definition at line 203 of file xmlReader.h.

206{
207 // deactivate default warnings and show default values instead
208 setWarningsOn(false);
209 if (name_parameter_3 == "") {
210 if (!(*this)[name_parameter_1][name_parameter_2].read<ParameterType>(var, false)) {
211 _output.parameterReading({name_parameter_1, name_parameter_2}, var, defaultAvailable, exitIfMissing, showWarning);
212 return false;
213 }
214 return true;
215 }
216 else if(name_parameter_4 == ""){
217 if (!(*this)[name_parameter_1][name_parameter_2][name_parameter_3].read<ParameterType>(var, false)) {
218 _output.parameterReading({name_parameter_1, name_parameter_2, name_parameter_3}, var, defaultAvailable, exitIfMissing, showWarning);
219 return false;
220 }
221 return true;
222 }
223 else {
224 if (!(*this)[name_parameter_1][name_parameter_2][name_parameter_3][name_parameter_4].read<ParameterType>(var, false)) {
225 _output.parameterReading({name_parameter_1, name_parameter_2,name_parameter_3,name_parameter_4},
226 var, defaultAvailable, exitIfMissing, showWarning);
227 return false;
228 }
229 return true;
230 }
231 // turn default warnings on again
232 setWarningsOn(true);
233}

References _output, olb::XMLreaderOutput::parameterReading(), and setWarningsOn().

+ Here is the call graph for this function:

◆ setWarningsOn()

void olb::XMLreader::setWarningsOn ( bool warnings) const

switch warnings on/off

Definition at line 412 of file xmlReader.h.

413{
414 _warningsOn = warnings;
415 for (unsigned int iNode=0; iNode<_children.size(); ++iNode) {
416 _children[iNode]->setWarningsOn(warnings);
417 }
418}

References _children.

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ olb::XMLreaderOutput

friend class olb::XMLreaderOutput
friend

Definition at line 50 of file xmlReader.h.

Member Data Documentation

◆ _attributes

std::map<std::string, std::string> olb::XMLreader::_attributes
protected

Definition at line 118 of file xmlReader.h.

◆ _children

std::vector<XMLreader*> olb::XMLreader::_children
protected

Definition at line 119 of file xmlReader.h.

◆ _output

XMLreaderOutput olb::XMLreader::_output

handling all the output for the XMLreader

Definition at line 106 of file xmlReader.h.


The documentation for this class was generated from the following file: