33#include "rapidxml/rapidxml.hpp"
49 typedef rapidxml::xml_base<> t_XMLnode;
50 typedef rapidxml::xml_node<> t_XMLelement;
51 typedef rapidxml::xml_attribute<> t_XMLattribute;
52 typedef rapidxml::xml_document<> t_XMLdocument;
55 static const char *
const includeattrtag;
56 static const char *
const queryattrtag;
88 ENTITY_REFERENCE_Node=5,
90 PROCESSING_INSTRUCTION_Node=7,
93 DOCUMENT_TYPE_Node=10,
94 DOCUMENT_FRAGMENT_Node=11,
100 : m_xmlnode(NULL), m_nodepath(std::
string()), m_type(Unknown_Node)
107 : m_xmlnode(n.m_xmlnode), m_nodepath(n.m_nodepath), m_type(n.m_type)
114 {
return m_nodepath; }
136 {
if(m_xmlnode && ! m_xmlnode->parent())
return true;
else return false; }
146 template<
typename T>
bool getValue(T& value)
const;
177 bool value_bool(
bool defaultvalue=
false)
const;
184 { m_xmlnode=n.m_xmlnode; m_nodepath=n.m_nodepath;
return *
this; }
187 template<
typename T>
operator T()
const
188 { T value;
getValue(value);
return value; }
191 operator bool()
const
192 {
return m_xmlnode!=NULL && m_type!=Invalid_Node; }
197 void printXML(std::ostream& ostrm=std::cout)
const;
201 void print(std::ostream& ostrm=std::cout)
const;
204 m_xmlnode = node.m_xmlnode;
205 m_nodepath = node.m_nodepath;
206 m_type = node.m_type;
211 : m_xmlnode(xmlnode), m_nodepath(
nodepath), m_type(Unknown_Node)
212 {
if(!xmlnode) m_type=Invalid_Node; }
215 : m_xmlnode(xmlattribute), m_nodepath(
nodepath), m_type(ATTRIBUTE_Node)
216 {
if(!xmlattribute) m_type=Invalid_Node; }
223 const t_XMLnode* m_xmlnode;
247 : m_query(NULL), m_nodesidx(0) {}
248 long index()
const {
return m_nodesidx; }
251 operator bool()
const
252 {
return m_query!=NULL && m_nodesidx>=0 && m_nodesidx<long(m_query->
card()); }
257 {
if(m_nodesidx<
long(m_query->
card())) ++m_nodesidx;
return *
this; }
262 {
if(m_nodesidx<
long(m_query->
card())) m_nodesidx++;
return *
this; }
267 {
if(m_nodesidx>=0) --m_nodesidx;
return *
this; }
272 {
if(m_nodesidx>=0) m_nodesidx--;
return *
this; }
277 {
if(*
this)
return (*m_query)[m_nodesidx];
else return Node(); }
280 const Query* m_query;
284 : m_query(
query), m_nodesidx(idx) {}
290 Query() : m_xmlfile(NULL), m_nodes()
295 Query(
const Query& q) : m_xmlfile(q.m_xmlfile), m_nodes(q.m_nodes)
296 { xmlfile_register(); }
300 { xmlfile_unregister(); }
305 unsigned long card()
const {
return m_nodes.size(); }
310 {
return card()==0; }
314 { xmlfile_unregister(); m_xmlfile=NULL; m_nodes.clear(); }
319 {
return (*
this)[0]; }
328 operator unsigned long()
const
332 operator bool()
const
333 {
return m_xmlfile!=NULL; }
339 {
if(idx<m_nodes.size())
return Node(m_nodes[idx]);
else return Node(); }
370 template<
typename T>
unsigned long getNodeValue(T& value)
const;
382 {
int value=defaultvalue;
getNodeValue(value);
return value; }
388 {
long value=defaultvalue;
getNodeValue(value);
return value; }
394 {
float value=defaultvalue;
getNodeValue(value);
return value; }
400 {
double value=defaultvalue;
getNodeValue(value);
return value; }
406 {
bool value=defaultvalue;
getNodeValue(value);
return value; }
411 void printXML(std::ostream& ostrm=std::cout)
const;
415 void print(std::ostream& ostrm=std::cout)
const;
419 std::vector<Node> m_nodes;
425 void xmlfile_register()
426 {
if(m_xmlfile) m_xmlfile->registerQuery(
this); }
427 void xmlfile_unregister()
428 {
if(m_xmlfile) m_xmlfile->unregisterQuery(
this); }
432 friend void Query::xmlfile_register();
433 friend void Query::xmlfile_unregister();
492 template<
typename T>
unsigned long getNodeValue(
const char* nodepath, T& value)
const
589 void printXML(std::ostream& ostrm=std::cout)
const;
593 void print(std::ostream& ostrm=std::cout)
const;
613 {
return m_queries.size(); }
616 void setMPIdefaults(
int mpirootrank=0, MPI_Comm mpicomm=MPI_COMM_WORLD);
623 t_XMLdocument m_xmldoc;
625 mutable std::set<Query*> m_queries;
630 void initstring_local(
const char* xmlstring);
631 void expandincludes();
632 unsigned long query(std::list<Node>& nodeselection,
const std::string& querystring, Node startnode=Node())
const;
633 void insertcloneelement(
const t_XMLelement* src, t_XMLelement* dest_after);
635 void registerQuery(Query* q)
const
636 {
if(q) m_queries.insert(q); }
637 void unregisterQuery(Query* q)
const
638 { m_queries.erase(q); }
639 void invalidateQueries()
640 {
for(std::set<Query*>::iterator
pos=m_queries.begin();
pos!=m_queries.end();++
pos) (*pos)->invalidate(); m_queries.clear(); }
648 bool distributeXMLstring();
void print(std::ostream &ostrm=std::cout) const
print data to stream print the node data
Definition: xmlfile.cpp:689
void invalidate()
invalidate the node set the internal state to invalid
Definition: xmlfile.h:123
bool isRootNode() const
check, if node is root node return true, if node is a valid root node - false otherwise
Definition: xmlfile.h:135
const std::string & nodepath() const
get nodepath returns the full path of the node
Definition: xmlfile.h:113
NodeType type() const
get node type determine the node type (enumeration)
Definition: xmlfile.h:129
float value_float(float defaultvalue=0.) const
get the node float value returns the node value as float value or default value, if node is invalid
Definition: xmlfile.cpp:644
void printXML(std::ostream &ostrm=std::cout) const
print XML data to stream print the node content using XML syntax
Definition: xmlfile.cpp:674
int value_int(int defaultvalue=0) const
get the node int value returns the node value as int value or default value, if node is invalid
Definition: xmlfile.cpp:624
std::string value_string(std::string defaultvalue=std::string()) const
get the node string value returns the node value as string value or default value,...
Definition: xmlfile.cpp:614
Node()
XMLfile::Node constructor sets up an invalid node.
Definition: xmlfile.h:99
Node(const Node &n)
XMLfile::Node copy constructor duplicate a node.
Definition: xmlfile.h:106
bool isLeafNode() const
check, if node is leaf node return true, if node is a valid leaf node - false otherwise
Definition: xmlfile.cpp:524
NodeType
Node types enumeration associates a number to each XML node type.
Definition: xmlfile.h:82
double value_double(double defaultvalue=0.) const
get the node double value returns the node value as double value or default value,...
Definition: xmlfile.cpp:654
Node & operator=(const Node &n)
assignment operator copy/duplicate other node content to node
Definition: xmlfile.h:183
std::string name() const
get node name returns the name of the node, if node is valid - otherwise an empty string
Definition: xmlfile.h:118
long value_long(long defaultvalue=0) const
get the node long value returns the node value as long value or default value, if node is invalid
Definition: xmlfile.cpp:634
bool value_bool(bool defaultvalue=false) const
get the node bool value returns the node value as bool value or default value, if node is invalid
Definition: xmlfile.cpp:664
bool getValue(T &value) const
get the node value returns the node value converted to a given type
Definition: xmlfile.cpp:532
Definition: xmlfile.h:240
const_iterator & operator--()
prefix decrement operator decrement the index
Definition: xmlfile.h:266
Node operator*() const
access operator return the node, the iterator (index) actually points to or an invalid Node,...
Definition: xmlfile.h:276
const_iterator()
XMLfile::Query::const_iterator constructor sets up an invalid iterator.
Definition: xmlfile.h:246
const_iterator & operator++()
prefix increment operator put the index to the next position
Definition: xmlfile.h:256
Definition: xmlfile.h:232
Node operator[](unsigned long idx) const
indexing operator return the Node within the query at given index, or empty node, if query or index i...
Definition: xmlfile.h:338
void invalidate()
invalidate query unregister from XMLfile and invalidate the query
Definition: xmlfile.h:313
double getNodeValue_double(double defaultvalue=0.) const
get node value as double get the node content and convert it to a double
Definition: xmlfile.h:399
bool getNodeValue_bool(bool defaultvalue=false) const
get node value as bool get the node content and convert it to a bool
Definition: xmlfile.h:405
Query()
XMLfile::Query constructor sets up an invalid query.
Definition: xmlfile.h:290
long getNodeValue_long(long defaultvalue=0) const
get node value as long get the node content and convert it to a long
Definition: xmlfile.h:387
const_iterator begin() const
get starting iterator return an iterator to the first node
Definition: xmlfile.h:344
void printXML(std::ostream &ostrm=std::cout) const
print XML data to stream print the query content using XML syntax
Definition: xmlfile.cpp:762
int getNodeValue_int(int defaultvalue=0) const
get node value as int get the node content and convert it to an int
Definition: xmlfile.h:381
void print(std::ostream &ostrm=std::cout) const
print data to stream print the query content
Definition: xmlfile.cpp:768
bool end() const
get (dummy) iteration end for comparison return false (as dummy) to enable e.g. for(it=query....
Definition: xmlfile.h:355
const_iterator rbegin() const
get reverse starting iterator return an iterator to the last node
Definition: xmlfile.h:349
unsigned long card() const
get cardinality of query set return the size of the query set
Definition: xmlfile.h:305
bool empty() const
check ,if query set is empty return true if the query set is empty
Definition: xmlfile.h:309
float getNodeValue_float(float defaultvalue=0.) const
get node value as float get the node content and convert it to a float
Definition: xmlfile.h:393
Node front() const
get first query entry return the first Node of the query set (invalid Node, if there's none)
Definition: xmlfile.h:318
std::string getNodeValue_string(const std::string defaultvalue=std::string()) const
get node value as string get the node content
Definition: xmlfile.h:375
Query(const Query &q)
copy constructor duplicate a given query and register the new created one at the XMLfile
Definition: xmlfile.h:295
~Query()
XMLfile::Query destructor unregister the query.
Definition: xmlfile.h:299
Query & operator=(const Query &q)
assignment operator copy/duplicate other query content to query
Definition: xmlfile.cpp:738
unsigned long getNodeValue(T &value) const
get node value get the node content and convert it to a given type
Definition: xmlfile.cpp:747
XML file abstraction.
Definition: xmlfile.h:47
Query query(const std::string &querystr) const
perform a query return a query to a given query expression
void printXML(std::ostream &ostrm=std::cout) const
print node content as XML print node content to stream using XML
Definition: xmlfile.cpp:159
bool getNodeValue_bool(const std::string &nodepath, bool defaultvalue=false) const
get node value as bool get the node content and convert it to a bool (an alternative of using <tag>tr...
Definition: xmlfile.h:575
unsigned long getNodeValue(const char *nodepath, T &value) const
get node value get the node content and convert it to a given type
Definition: xmlfile.h:492
void print(std::ostream &ostrm=std::cout) const
print node content print node content and debug information to stream
Definition: xmlfile.cpp:164
long changecurrentnode(const std::string &nodepath=std::string("/"))
set current node set a node, relative queries start with
void save(std::string filepath=std::string())
save save node content as XML-file
Definition: xmlfile.cpp:113
long getNodeValue_long(const char *nodepath, long defaultvalue=0) const
get node value as long get the node content and convert it to a long
Definition: xmlfile.h:537
int getNodeValue_int(const std::string &nodepath, int defaultvalue=0) const
get node value as int get the node content and convert it to an integer
Definition: xmlfile.h:514
bool getNodeValue_bool(const char *nodepath, bool defaultvalue=false) const
get node value as bool get the node content and convert it to a bool
Definition: xmlfile.h:583
std::string getNodeValue_string(const std::string &nodepath, const std::string defaultvalue=std::string()) const
get node value as string get the node content
Definition: xmlfile.h:499
long getNodeValue_long(const std::string &nodepath, long defaultvalue=0) const
get node value as long get the node content and convert it to a long
Definition: xmlfile.h:529
const std::string getFilename() const
get XML filename if instantiated with a XML-file, return the filename (without directory part of path...
Definition: xmlfile.h:462
float getNodeValue_float(const char *nodepath, float defaultvalue=0.) const
get node value as float get the node content and convert it to a float
Definition: xmlfile.h:552
virtual ~XMLfile()
XMLfile default destructor.
Definition: xmlfile.h:438
bool initfile(const std::string &filepath)
initialize with XML-file instantiating with XML file
Definition: xmlfile.cpp:54
double getNodeValue_double(const char *nodepath, double defaultvalue=0.) const
get node value as double get the node content and convert it to a double
Definition: xmlfile.h:567
unsigned long getNodeValue(const std::string &nodepath, T &value) const
get node value get the node content and convert it to a given type
Definition: xmlfile.h:484
float getNodeValue_float(const std::string &nodepath, float defaultvalue=0.) const
get node value as float get the node content and convert it to a float
Definition: xmlfile.h:544
int getNodeValue_int(const char *nodepath, int defaultvalue=0) const
get node value as int get the node content and convert it to an integer
Definition: xmlfile.h:522
XMLfile(const std::string &filepath)
constructor for XML-file constructor calls initfile
XMLfile()
XMLfile default constructor.
Definition: xmlfile.cpp:37
double getNodeValue_double(const std::string &nodepath, double defaultvalue=0.) const
get node value as double get the node content and convert it to a double
Definition: xmlfile.h:559
const std::string getDir() const
get XML file directory if instantiated with a XML-file, return the directory
Definition: xmlfile.h:458
std::string getNodeValue_string(const char *nodepath, std::string defaultvalue=std::string()) const
get node value as string get the node content
Definition: xmlfile.h:507
size_t numqueries() const
number of registered queries return the number of active queries
Definition: xmlfile.h:612
void initstring(const char *xmlstring)
initialize with XML-string instantiating with XML-string
Definition: xmlfile.cpp:72
std::string getcurrentnodepath() const
get current node path
Definition: xmlfile.h:477
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270
Definition: FakedOptFFT.h:23
std::ostream & operator<<(std::ostream &ostrm, const XMLfile::Node &xmlnode)
write a node to a stream write XML node data to an output stream
Definition: xmlfile.h:659