46 template <
class T,
unsigned DIM>
class ADf;
69 template <
typename T>
bool read(T& value,
bool verboseOn =
true,
bool exitIfMissing=
false)
const;
70 template <
typename T,
unsigned DIM>
bool read(
util::ADf<T,DIM>& value,
bool verboseOn =
true,
bool exitIfMissing=
false)
const;
71 template <
typename T>
bool read(std::vector<T>& value,
bool verboseOn =
true,
bool exitIfMissing=
false)
const;
72 template <
typename T> T
get(
bool verboseOn =
true,
bool exitIfMissing=
false)
const;
75 template<
typename ParameterType>
77 std::string name_parameter_2, std::string name_parameter_3,
78 ParameterType& var,
bool defaultAvailable =
true,
bool exitIfMissing =
false,
bool showWarning =
true)
const;
80 template<
typename ParameterType>
82 std::string name_parameter_2, std::string name_parameter_3, std::string name_parameter_4,
83 ParameterType& var,
bool defaultAvailable =
true,
bool exitIfMissing =
false,
bool showWarning =
true)
const;
90 std::vector<XMLreader*>::const_iterator
begin()
const;
95 std::vector<XMLreader*>::const_iterator
end()
const;
103 std::string
getAttribute(
const std::string& aName)
const;
108 void mainProcessorIni(TiXmlNode* pParent);
109 void slaveProcessorIni();
112 mutable bool _warningsOn;
124template <
typename T,
unsigned DIM>
127 std::stringstream valueStr(_text);
129 if (!(valueStr >> tmp)) {
141bool XMLreader::read(std::vector<T>& values,
bool verboseOn,
bool exitIfMissing )
const
143 std::stringstream multiValueStr(_text);
145 std::vector<T> tmp(values);
146 while (multiValueStr>>word) {
147 std::stringstream valueStr(word);
149 if (!(valueStr >> value)) {
156 tmp.push_back(value);
165 std::stringstream valueStr(_text);
167 if (!(valueStr >> tmp)) {
177template<
typename ParameterType>
179 std::string name_parameter_2, std::string name_parameter_3,
180 ParameterType& var,
bool defaultAvailable,
bool exitIfMissing,
bool showWarning)
const
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);
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);
202template<
typename ParameterType>
204 std::string name_parameter_2, std::string name_parameter_3, std::string name_parameter_4,
205 ParameterType& var,
bool defaultAvailable,
bool exitIfMissing,
bool showWarning)
const
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);
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);
224 if (!(*
this)[name_parameter_1][name_parameter_2][name_parameter_3][name_parameter_4].read<ParameterType>(var,
false)) {
226 var, defaultAvailable, exitIfMissing, showWarning);
237XMLreader::XMLreader()
239 _name =
"XML node not found";
244XMLreader::XMLreader( TiXmlNode* pParent,
OutputChannel outputChannel) : _output(outputChannel)
246 _outputChannel = outputChannel;
250 mainProcessorIni(pParent);
257XMLreader::XMLreader(
const std::string& fName,
OutputChannel outputChannel) : _output(outputChannel)
259 _outputChannel = outputChannel;
262 TiXmlDocument* doc =
nullptr;
264#ifdef PARALLEL_MODE_MPI
267 std::string docName = std::string(fName);
268 doc =
new TiXmlDocument(docName.c_str());
269 loadOK = doc->LoadFile();
271#ifdef PARALLEL_MODE_MPI
275 mainProcessorIni(doc);
277#ifdef PARALLEL_MODE_MPI
287 for (
unsigned int iNode=0; iNode<
_children.size(); ++iNode) {
292void XMLreader::mainProcessorIni( TiXmlNode* pParent )
294 assert (pParent->Type()==TiXmlNode::TINYXML_DOCUMENT || pParent->Type()==TiXmlNode::TINYXML_ELEMENT );
295 if (pParent->Type() == TiXmlNode::TINYXML_DOCUMENT) {
297 pParent = pParent->FirstChildElement();
300 _name = pParent->ValueStr();
301#ifdef PARALLEL_MODE_MPI
305 TiXmlAttribute* attr = pParent->ToElement()->FirstAttribute();
306 while (attr !=
nullptr) {
307#ifdef PARALLEL_MODE_MPI
309 std::string* key =
const_cast<std::string*
>(&attr->NameTStr());
311 std::string* value =
const_cast<std::string*
>(&attr->ValueStr());
317#ifdef PARALLEL_MODE_MPI
318 std::string tmpstr =
"";
327 for ( pChild = pParent->FirstChild(); pChild !=
nullptr; pChild = pChild->NextSibling()) {
328 type = pChild->Type();
329#ifdef PARALLEL_MODE_MPI
332 if ( type==TiXmlNode::TINYXML_ELEMENT ) {
335 else if ( type==TiXmlNode::TINYXML_TEXT ) {
336 _text = pChild->ToText()->ValueStr();
337#ifdef PARALLEL_MODE_MPI
342 type = TiXmlNode::TINYXML_UNKNOWN;
343#ifdef PARALLEL_MODE_MPI
348void XMLreader::slaveProcessorIni()
350#ifdef PARALLEL_MODE_MPI
353 std::string key =
"";
354 std::string
value =
"";
366#ifdef PARALLEL_MODE_MPI
369 if ( type==TiXmlNode::TINYXML_ELEMENT ) {
372 else if ( type==TiXmlNode::TINYXML_TEXT ) {
373#ifdef PARALLEL_MODE_MPI
378 while (type != TiXmlNode::TINYXML_UNKNOWN);
383 for (
unsigned int iNode=0; iNode<
_children.size(); ++iNode) {
414 _warningsOn = warnings;
415 for (
unsigned int iNode=0; iNode<
_children.size(); ++iNode) {
416 _children[iNode]->setWarningsOn(warnings);
422bool XMLreader::read<bool>(
bool& value,
bool verboseOn,
bool exitIfMissing)
const
424 std::stringstream valueStr(_text);
428 std::transform(word.begin(), word.end(), word.begin(), ::tolower);
429 if (!word.compare(
"true") || (word==
"1")) {
433 else if (!word.compare(
"false") || (word==
"0")) {
439 std::stringstream ss;
440 ss << ( value ?
"true" :
"false" );
449bool XMLreader::read<int>(
int& value,
bool verboseOn,
bool exitIfMissing)
const
451 std::stringstream valueStr(_text);
453 if (!(valueStr >> tmp)) {
454 std::stringstream ss;
465bool XMLreader::read<std::size_t>(std::size_t& value,
bool verboseOn,
bool exitIfMissing)
const
467 std::stringstream valueStr(_text);
468 std::size_t tmp = std::size_t();
469 if (!(valueStr >> tmp)) {
470 std::stringstream ss;
472 _output.printWarning(_name,
"std::size_t", ss.str(), verboseOn, exitIfMissing);
481bool XMLreader::read<double>(
double& value,
bool verboseOn,
bool exitIfMissing)
const
483 std::stringstream valueStr(_text);
484 double tmp = double();
485 if (!(valueStr >> tmp)) {
495bool XMLreader::read<long double>(
long double& value,
bool verboseOn,
bool exitIfMissing)
const
497 std::stringstream valueStr(_text);
499 if (!(valueStr >> tmp)) {
500 _output.
printWarning(_name,
"long double", std::to_string(value), verboseOn, exitIfMissing);
503 value = std::stold(tmp);
508bool XMLreader::read<float>(
float& value,
bool verboseOn,
bool exitIfMissing)
const
510 std::stringstream valueStr(_text);
512 if (!(valueStr >> tmp)) {
513 std::stringstream ss;
523bool XMLreader::read<std::string>(std::string& entry,
bool verboseOn,
bool exitIfMissing)
const
525 if (_name ==
"XML node not found") {
528 std::stringstream valueStr(_text);
529 std::string tmp = std::string();
530 if (!(valueStr >> tmp)) {
531 std::stringstream ss;
533 _output.printWarning(_name,
"string", ss.str(), verboseOn, exitIfMissing);
543 std::map<std::string, std::string>::const_iterator it =
_attributes.find(aName);
545 return "Attribute not found.";
void loadFile(bool loadOK, std::string fName) const
void parameterReading(std::vector< std::string > parameters, ParameterType &var, bool defaultAvailable, bool exitIfMissing, bool showWarning) const
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
void readValue(bool warningsOn, std::string name, std::string fName) const
std::string getAttribute(const std::string &aName) const
std::vector< XMLreader * > _children
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...
std::string getName() const
return the name of the element
friend class olb::XMLreaderOutput
T get(bool verboseOn=true, bool exitIfMissing=false) const
XMLreaderOutput _output
handling all the output for the XMLreader
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 "...
void setWarningsOn(bool warnings) const
switch warnings on/off
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 t...
bool read(T &value, bool verboseOn=true, bool exitIfMissing=false) const
Prints out the XML structure read in, mostly for debugging purposes.
XMLreader const & operator[](std::string name) const
std::map< std::string, std::string > _attributes
std::string getText() const
return the text of the element
XMLreader(TiXmlNode *pParent, OutputChannel outputChannel=OutputChannel::ERRCHANNEL)
Constructs a new XMLreader from another XMLreader.
void bCast(T *sendBuf, int sendCount, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Broadcast data from one processor to multiple processors.
Definition of a description of a algoritmic differentiation data type using the forward method.
Wrapper functions that simplify the use of MPI.
Top level namespace for all of OpenLB.