DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
XMLElements.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef XML_XMLELEMENTS_H
14 #define XML_XMLELEMENTS_H
15 
16 // C/C++ include files
17 #include <cmath>
18 #include <string>
19 #include <vector>
20 #include <stdexcept>
21 
22 // Framework include files
23 #include <XML/config.h>
24 
25 #ifndef RAD_2_DEGREE
26 #define RAD_2_DEGREE 57.295779513082320876798154814105
27 #endif
28 #ifndef M_PI
29 #define M_PI 3.14159265358979323846
30 #endif
31 
33 namespace dd4hep {
34 
36  namespace xml {
37 
38  typedef const XmlAttr* Attribute;
39 
41 
51  class XmlString {
52  public:
54  static XmlChar* replicate(const XmlChar* c);
56  static XmlChar* transcode(const char* c);
58  static void release(char** p);
60  static size_t length(const char* s);
61 #ifndef __TIXML__
62  static size_t length(const XmlChar* s);
65  static char* transcode(const XmlChar* c);
67  static void release(XmlChar** p);
68 #endif
69  };
70 
71 #ifdef __TIXML__
72 
81  class XmlException {
82  public:
83  std::string msg;
84  XmlException() : msg() {}
85  XmlException(const std::string& m) : msg(m) {}
86  XmlException(const XmlException& e) : msg(e.msg) {}
87  virtual ~XmlException() {}
88  XmlException& operator=(const XmlException& c) {
89  if ( &c != this ) msg = c.msg;
90  return *this;
91  }
92  };
93 #endif
94 
95  typedef const std::string& CSTR;
96 
98  void dumpTree(XmlDocument* doc);
99 
101  int set_float_precision(int precision);
103  int get_float_precision();
104 
106  std::string _toString(const Attribute attr);
108  std::string _toString(const XmlChar *toTranscode);
110  std::string _toString(const char* s);
112  std::string _toString(const std::string& s);
114  std::string _toString(unsigned long i, const char* fmt = "%lu");
116  std::string _toString(unsigned int i, const char* fmt = "%u");
118  std::string _toString(int i, const char* fmt = "%d");
120  std::string _toString(long i, const char* fmt = "%ld");
122  std::string _toString(float d, const char* fmt = "%.17e");
124  std::string _toString(double d, const char* fmt = "%.17e");
126  std::string _ptrToString(const void* p, const char* fmt = "%p");
128  template <typename T> std::string _toString(const T* p, const char* fmt = "%p")
129  { return _ptrToString((void*)p,fmt); }
130 
132  void _toDictionary(const XmlChar* name, const XmlChar* value);
134  template <typename T> void _toDictionary(const XmlChar* name, T value);
135 
137  void _toDictionary(const XmlChar* name, float value);
139  void _toDictionary(const XmlChar* name, double value);
140 
142  bool _toBool(const XmlChar* value);
144  int _toInt(const XmlChar* value);
146  unsigned int _toUInt(const XmlChar* value);
148  long _toLong(const XmlChar* value);
150  unsigned long _toULong(const XmlChar* value);
152  float _toFloat(const XmlChar* value);
154  double _toDouble(const XmlChar* value);
155 
157  std::string getEnviron(const std::string& env);
159  bool enableEnvironResolution(bool new_value);
160 
162 
170  class Strng_t {
171  public:
174 #ifndef __TIXML__
175  Strng_t(const XmlChar* c) {
178  }
180  Strng_t& operator=(const XmlChar* s);
181 #endif
182  Strng_t(const char* c) {
185  }
187  Strng_t(const std::string& c) {
188  m_xml = XmlString::transcode(c.c_str());
189  }
191  Strng_t(const Strng_t& c) {
193  }
196  if (m_xml)
198  }
200  operator const XmlChar*() const {
201  return m_xml;
202  }
204  const XmlChar* ptr() const {
205  return m_xml;
206  }
208  size_t length() const {
209  return XmlString::length(m_xml);
210  }
212  Strng_t& operator=(const char* s);
214  Strng_t& operator=(const Strng_t& s);
216  Strng_t& operator=(const std::string& s);
217  };
218 
220  Strng_t operator+(const Strng_t& a, const char* b);
222  Strng_t operator+(const Strng_t& a, const std::string& b);
224  Strng_t operator+(const Strng_t& a, const Strng_t& b);
226  Strng_t operator+(const char* a, const Strng_t& b);
228  Strng_t operator+(const std::string& a, const Strng_t& b);
229 
230 #ifndef __TIXML__
231  Strng_t operator+(const Strng_t& a, const XmlChar* b);
234  Strng_t operator+(const XmlChar* a, const Strng_t& b);
236  Strng_t operator+(const XmlChar* a, const std::string& b);
238  Strng_t operator+(const std::string& a, const XmlChar* b);
239 
240 #endif
241 
243 
254  class Tag_t : public Strng_t {
255  public:
257  std::string m_str;
258 #ifndef __TIXML__
259  Tag_t(const char* s)
261  : Strng_t(s), m_str(s) {
262  }
263 #endif
264  Tag_t(const XmlChar* s)
266  : Strng_t(s), m_str(_toString(s)) {
267  }
269  Tag_t(const Strng_t& s)
270  : Strng_t(s), m_str(_toString(s)) {
271  }
273  Tag_t(const std::string& s)
274  : Strng_t(s), m_str(s) {
275  }
278  Tag_t(const std::string& v, const std::string& s, void (*register_func)(const std::string&, Tag_t*))
279  : Strng_t(s), m_str(s) {
280  register_func(v, this);
281  }
283  Tag_t(const Tag_t& c)
284  : Strng_t(c), m_str(c.m_str) {
285  }
287  ~Tag_t() {
288  }
289 
291  Tag_t& operator=(const char* s);
293  Tag_t& operator=(const Tag_t& s);
295  Tag_t& operator=(const Strng_t& s);
297  Tag_t& operator=(const std::string& s);
298 
300  operator const std::string&() const {
301  return m_str;
302  }
304  const std::string& str() const {
305  return m_str;
306  }
308  const char* c_str() const {
309  return m_str.c_str();
310  }
311  };
312 
314  Tag_t operator+(const Tag_t& a, const char* b);
316  Tag_t operator+(const char* a, const Tag_t& b);
318  Tag_t operator+(const Tag_t& a, const XmlChar* b);
320  Tag_t operator+(const Tag_t& a, const Strng_t& b);
322  Tag_t operator+(const Tag_t& a, const std::string& b);
324  inline bool operator==(const std::string& c, const Tag_t& b) {
325  return c == b.m_str;
326  }
327 
329  std::string _toString(const Strng_t& s);
331  std::string _toString(const Tag_t& s);
333  void _toDictionary(const XmlChar* name, const Strng_t& s);
335  void _toDictionary(const XmlChar* name, const Tag_t& t);
336 
338 
349  class NodeList {
350  public:
352  XmlElement* m_node;
353  mutable XmlElement* m_ptr;
354 
356  NodeList(const NodeList& l);
358  NodeList(XmlElement* frst, const XmlChar* t);
360  ~NodeList();
362  XmlElement* reset();
364  XmlElement* next() const;
366  XmlElement* previous() const;
368  NodeList& operator=(const NodeList& l);
369  };
370 
372 
380  class Handle_t {
381  public:
382  // Abbreviation for internal use
383  typedef XmlElement* Elt_t;
384 
386  mutable Elt_t m_node;
387 
390  : m_node(e) {
391  }
393  Elt_t operator->() const {
394  return m_node;
395  }
397  operator Elt_t() const {
398  return m_node;
399  }
401  Elt_t ptr() const {
402  return m_node;
403  }
405  Handle_t clone(XmlDocument* new_doc) const;
406 
408  const XmlChar* rawTag() const;
410  const XmlChar* rawText() const;
412  const XmlChar* rawValue() const;
414  std::string tag() const {
415  return _toString(rawTag());
416  }
418  std::string text() const {
419  return _toString(rawText());
420  }
422  std::string value() const {
423  return _toString(rawValue());
424  }
426  void setValue(const XmlChar* text) const;
428  void setValue(const std::string& text) const;
430  void setText(const XmlChar* text) const;
432  void setText(const std::string& text) const;
433 
434  /*** DOM Attribute handling
435  */
437  const XmlChar* attr_name(const Attribute attr) const;
439  const XmlChar* attr_value(const Attribute attr) const;
441  const XmlChar* attr_value(const XmlChar* attr) const;
443  const XmlChar* attr_value_nothrow(const XmlChar* attr) const;
444 
446  Attribute attr_ptr(const XmlChar* attr) const;
448  Attribute attr_nothrow(const XmlChar* tag) const;
450  bool hasAttr(const XmlChar* t) const;
452  std::vector<Attribute> attributes() const;
454  template <class T> T attr(const Attribute a) const {
455  return this->attr<T>(this->attr_name(a));
456  }
458  void removeAttrs() const;
460  void setAttrs(Handle_t e) const;
462  template <class T> T attr(const XmlChar* name) const;
464  template <class T> T attr(const XmlChar* name, T default_value) const;
465 
467  Attribute setAttr(const XmlChar* t, const XmlChar* v) const;
469  Attribute setAttr(const XmlChar* t, const Attribute v) const;
471  Attribute setAttr(const XmlChar* t, int val) const;
473  Attribute setAttr(const XmlChar* t, bool val) const;
475  Attribute setAttr(const XmlChar* t, float val) const;
477  Attribute setAttr(const XmlChar* t, double val) const;
479  Attribute setAttr(const XmlChar* t, const std::string& val) const;
480 #ifndef __TIXML__
481  bool hasAttr(const char* t) const {
483  return hasAttr(Strng_t(t));
484  }
486  template <class T> T attr(const char* name) const {
487  return this->attr<T>(Strng_t(name));
488  }
490  template <class T> T attr(const char* name, const T& default_value) const {
491  Strng_t tag(name);
492  return this->hasAttr(tag) ? this->attr<T>(tag) : default_value;
493  }
495  Attribute setAttr(const XmlChar* t, const char* v) const;
496 #endif
497 
499  Handle_t setRef(const XmlChar* tag, const XmlChar* ref);
501  Handle_t setRef(const XmlChar* tag, const std::string& ref);
502 
503  /*** DOM Element child handling
504  */
506  bool hasChild(const XmlChar* tag) const;
508  Handle_t child(const XmlChar* tag, bool throw_exception = true) const;
510  NodeList children(const XmlChar* tag) const;
512  size_t numChildren(const XmlChar* tag, bool throw_exception) const;
514  Handle_t remove(Handle_t e) const;
516  void removeChildren(const XmlChar* tag) const;
518  void append(Handle_t e) const;
520  Handle_t parent() const;
522  unsigned int checksum(unsigned int param, unsigned int (fcn)(unsigned int param, const XmlChar*, size_t)=0) const;
523  };
524 
525 #define INLINE inline
526  typedef const XmlChar* cpXmlChar;
527 
528  template <> INLINE Attribute Handle_t::attr<Attribute>(const XmlChar* tag_value) const {
529  return attr_ptr(tag_value);
530  }
531 
532  template <> INLINE cpXmlChar Handle_t::attr<cpXmlChar>(const XmlChar* tag_value) const {
533  return attr_value(tag_value);
534  }
535 
536  template <> INLINE bool Handle_t::attr<bool>(const XmlChar* tag_value) const {
537  return _toBool(attr_value(tag_value));
538  }
539 
540  template <> INLINE int Handle_t::attr<int>(const XmlChar* tag_value) const {
541  return _toInt(attr_value(tag_value));
542  }
543 
544  template <> INLINE unsigned int Handle_t::attr<unsigned int>(const XmlChar* tag_value) const {
545  return _toUInt(attr_value(tag_value));
546  }
547 
548  template <> INLINE long Handle_t::attr<long>(const XmlChar* tag_value) const {
549  return _toLong(attr_value(tag_value));
550  }
551 
552  template <> INLINE unsigned long Handle_t::attr<unsigned long>(const XmlChar* tag_value) const {
553  return _toULong(attr_value(tag_value));
554  }
555 
556  template <> INLINE float Handle_t::attr<float>(const XmlChar* tag_value) const {
557  return _toFloat(attr_value(tag_value));
558  }
559 
560  template <> INLINE double Handle_t::attr<double>(const XmlChar* tag_value) const {
561  return _toDouble(attr_value(tag_value));
562  }
563 
564  template <> INLINE std::string Handle_t::attr<std::string>(const XmlChar* tag_value) const {
565  return _toString(attr_value(tag_value));
566  }
567 
568  template <> INLINE Attribute Handle_t::attr<Attribute>(const XmlChar* tag_value, Attribute default_value) const {
569  Attribute a = attr_nothrow(tag_value);
570  return a ? a : std::move(default_value);
571  }
572 
573  template <> INLINE bool Handle_t::attr<bool>(const XmlChar* tag_value, bool default_value) const {
574  Attribute a = attr_nothrow(tag_value);
575  return a ? _toBool(attr_value(a)) : default_value;
576  }
577 
578  template <> INLINE int Handle_t::attr<int>(const XmlChar* tag_value, int default_value) const {
579  Attribute a = attr_nothrow(tag_value);
580  return a ? _toInt(attr_value(a)) : default_value;
581  }
582 
583  template <> INLINE unsigned int Handle_t::attr<unsigned int>(const XmlChar* tag_value, unsigned int default_value) const {
584  Attribute a = attr_nothrow(tag_value);
585  return a ? _toUInt(attr_value(a)) : default_value;
586  }
587 
588  template <> INLINE long Handle_t::attr<long>(const XmlChar* tag_value, long default_value) const {
589  Attribute a = attr_nothrow(tag_value);
590  return a ? _toLong(attr_value(a)) : default_value;
591  }
592 
593  template <> INLINE unsigned long Handle_t::attr<unsigned long>(const XmlChar* tag_value, unsigned long default_value) const {
594  Attribute a = attr_nothrow(tag_value);
595  return a ? _toULong(attr_value(a)) : default_value;
596  }
597 
598  template <> INLINE float Handle_t::attr<float>(const XmlChar* tag_value, float default_value) const {
599  Attribute a = attr_nothrow(tag_value);
600  return a ? _toFloat(attr_value(a)) : default_value;
601  }
602 
603  template <> INLINE double Handle_t::attr<double>(const XmlChar* tag_value, double default_value) const {
604  Attribute a = attr_nothrow(tag_value);
605  return a ? _toDouble(attr_value(a)) : default_value;
606  }
607 
608  template <> INLINE std::string Handle_t::attr<std::string>(const XmlChar* tag_value, std::string default_value) const {
609  Attribute a = attr_nothrow(tag_value);
610  return a ? _toString(attr_value(a)) : std::move(default_value);
611  }
612 
613 #if 0
614  template<> INLINE bool Handle_t::attr<bool>(const Attribute tag_value) const
615  { return _toBool(attr_value(tag_value));}
616 
617  template<> INLINE int Handle_t::attr<int>(const Attribute tag_value) const
618  { return _toInt(attr_value(tag_value));}
619 
620  template<> INLINE float Handle_t::attr<float>(const Attribute tag_value) const
621  { return _toFloat(attr_value(tag_value));}
622 
623  template<> INLINE double Handle_t::attr<double>(const Attribute tag_value) const
624  { return _toDouble(attr_value(tag_value));}
625 
626  template<> INLINE std::string Handle_t::attr<std::string>(const Attribute tag_value) const
627  { return _toString(attr_value(tag_value));}
628 #endif
629 
631 
636  class Collection_t : public Handle_t {
637  public:
640 #ifndef __TIXML__
641  Collection_t(Handle_t node, const XmlChar* tag);
643 #endif
644  Collection_t(Handle_t node, const char* tag);
649  Collection_t& reset();
651  size_t size() const;
653  void operator++() const;
655  void operator++(int) const;
657  void operator--() const;
659  void operator--(int) const;
661  Elt_t current() const {
662  return m_node;
663  }
665  void throw_loop_exception(const std::exception& e) const;
667  template <class T> void for_each(T oper) const {
668  try {
669  for (const Collection_t& c = *this; c; ++c)
670  oper(*this);
671  }
672  catch (const std::exception& e) {
674  }
675  }
677  template <class T> void for_each(const XmlChar* tag_name, T oper) const {
678  try {
679  for (const Collection_t& c = *this; c; ++c)
680  Collection_t(c.m_node, tag_name).for_each(oper);
681  }
682  catch (const std::exception& e) {
684  }
685  }
686  };
687 
689 
697  class Document {
698  public:
699  typedef XmlDocument* DOC;
701 
703  Document() : m_doc(0) {}
705  Document(DOC d) : m_doc(d) {}
707  Document(const Document& d) = default;
709  Document& operator=(const Document& d) = default;
711  ~Document() = default;
713  operator DOC() const { return m_doc; }
715  DOC operator->() const { return m_doc; }
717  DOC ptr() const { return m_doc; }
718 
720  Handle_t root() const;
722  Handle_t createElt(const XmlChar* tag) const;
724  Handle_t clone(Handle_t source) const;
726  std::string uri() const;
727  };
728 
730 
741  class DocumentHolder : public Document {
742  public:
744  DocumentHolder() = default;
754  virtual ~DocumentHolder();
755  };
756 
758 
769  class Element {
770  public:
773 
776 
778  Element(const Handle_t& e) : m_element(e) { }
780  Element(const Element& e) : m_element(e.m_element) { }
782  Element(const Document& document, const XmlChar* type);
784  Document document() const;
785 
787  operator bool() const {
788  return 0 != m_element.ptr();
789  }
791  bool operator!() const {
792  return 0 == m_element.ptr();
793  }
795  Element& operator=(const Element& c) {
796  m_element = c.m_element;
797  return *this;
798  }
801  m_element = handle;
802  return *this;
803  }
805  operator Handle_t() const {
806  return m_element;
807  }
809  operator Elt_t() const {
810  return m_element;
811  }
813  Elt_t ptr() const {
814  return m_element;
815  }
817  Handle_t parent() const {
818  return m_element.parent();
819  }
821  Elt_t parentElement() const;
823  std::string tag() const {
824  return m_element.tag();
825  }
827  const XmlChar* tagName() const {
828  return m_element.rawTag();
829  }
831  std::string text() const {
832  return m_element.text();
833  }
835  void text(const std::string value) const {
836  return m_element.setText(value);
837  }
839  void append(Handle_t handle) const {
841  }
843  Handle_t clone(const Document& new_doc) const {
844  return new_doc.clone(m_element);
845  }
847  bool hasAttr(const XmlChar* name) const {
848  return m_element.hasAttr(name);
849  }
851  template <class T> T attr(const XmlAttr* att) const {
852  return m_element.attr<T>(att);
853  }
855  template <class T> T attr(const XmlChar* tag_value) const {
856  return m_element.attr<T>(tag_value);
857  }
859  template <class T> T attr(const XmlChar* tag_value, T default_value) const {
860  return m_element.attr<T>(tag_value, default_value);
861  }
862 #ifndef __TIXML__
863  template <class T> T attr(const char* name) const {
865  return this->attr<T>(Strng_t(name));
866  }
868  template <class T> T attr(const char* name, T default_value) const {
869  return this->attr<T>(Strng_t(name), default_value);
870  }
871 #endif
872  const XmlChar* attr_name(const Attribute a) const {
874  return m_element.attr_name(a);
875  }
877  const XmlChar* attr_value(const Attribute a) const {
878  return m_element.attr_value(a);
879  }
881  size_t numChildren(const XmlChar* tag_value, bool exc = true) const {
882  return m_element.numChildren(tag_value, exc);
883  }
885  void setAttrs(Handle_t e) const {
886  return m_element.setAttrs(e);
887  }
889  void removeAttrs() const {
891  }
893  std::vector<Attribute> attributes() const {
894  return m_element.attributes();
895  }
897  Attribute getAttr(const XmlChar* name) const;
899  template <class T>
900  Attribute setAttr(const XmlChar* nam, const T& val) const {
901  return m_element.setAttr(nam, val);
902  }
904  template <class T> void setValue(const T& val) const {
905  m_element.setValue(val);
906  }
908  Handle_t clone(Handle_t h) const;
910  Handle_t addChild(const XmlChar* tag) const;
912  Handle_t setChild(const XmlChar* tag) const;
914  Handle_t child(const Strng_t& tag_value, bool except = true) const {
915  return m_element.child(tag_value, except);
916  }
918  Handle_t remove(Handle_t node) const {
919  return m_element.remove(node);
920  }
922  bool hasChild(const XmlChar* tag_value) const {
923  return m_element.hasChild(tag_value);
924  }
926  Attribute setRef(const XmlChar* tag, const XmlChar* refname) const;
928  Attribute setRef(const XmlChar* tag, const std::string& refname) const;
930  const XmlChar* getRef(const XmlChar* tag) const;
931 #ifndef __TIXML__
932  void addComment(const XmlChar* text) const;
934 #endif
935  void addComment(const char* text) const;
938  void addComment(const std::string& text_value) const;
939  };
940 
942 
953  class RefElement : public Element {
954  public:
958  RefElement(const Handle_t& e);
960  RefElement(const RefElement& e);
962  RefElement(const Document& d, const XmlChar* type, const XmlChar* name);
964  RefElement& operator=(const RefElement& e);
966  const XmlChar* name() const;
968  const XmlChar* refName() const;
970  void setName(const XmlChar* new_name);
971  };
972 
973 #undef INLINE
974 
976  class DocumentHandler;
977 
979  void dump_tree(Handle_t elt);
981  void dump_tree(Handle_t elt, std::ostream& os);
983  void dump_tree(Document doc);
985  void dump_tree(Document doc, std::ostream& os);
986 
987  }
988 } /* End namespace dd4hep */
989 #endif // XML_XMLELEMENTS_H
dd4hep::xml::Collection_t::throw_loop_exception
void throw_loop_exception(const std::exception &e) const
Helper function to throw an exception.
Definition: XMLElements.cpp:1223
dd4hep::xml::Handle_t::setValue
void setValue(const XmlChar *text) const
Set the element's value.
Definition: XMLElements.cpp:769
dd4hep::xml::Tag_t::Tag_t
Tag_t(const std::string &s)
Constructor from STL string.
Definition: XMLElements.h:273
dd4hep::xml::XmlString::replicate
static XmlChar * replicate(const XmlChar *c)
Replicate string: internally allocates new string, which must be free'ed with release.
Definition: XMLElements.cpp:139
dd4hep::xml::Element::hasChild
bool hasChild(const XmlChar *tag_value) const
Check the existence of a child with a given tag name.
Definition: XMLElements.h:922
dd4hep::xml::Element::document
Document document() const
Access the hosting document handle of this DOM element.
Definition: XMLElements.cpp:1089
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::xml::Element::setChild
Handle_t setChild(const XmlChar *tag) const
Check if a child with the required tag exists - if not create it and add it to the current node.
Definition: XMLElements.cpp:1128
dd4hep::xml::Tag_t::m_str
std::string m_str
STL string buffer.
Definition: XMLElements.h:257
dd4hep::xml::Element::setAttrs
void setAttrs(Handle_t e) const
Remove own attributes and copy all attributes from handle 'e'.
Definition: XMLElements.h:885
dd4hep::xml::Element::getRef
const XmlChar * getRef(const XmlChar *tag) const
Access the value of the reference attribute of the node (attribute ref="ref-name")
Definition: XMLElements.cpp:1116
dd4hep::xml::Tag_t::Tag_t
Tag_t(const std::string &v, const std::string &s, void(*register_func)(const std::string &, Tag_t *))
Definition: XMLElements.h:278
dd4hep::xml::NodeList::next
XmlElement * next() const
Advance to next element.
Definition: XMLElements.cpp:587
dd4hep::xml::DocumentHolder::DocumentHolder
DocumentHolder(DOC d)
Constructor.
Definition: XMLElements.h:748
dd4hep::xml::Element::text
std::string text() const
Access the tag name of this DOM element.
Definition: XMLElements.h:831
dd4hep::xml::Handle_t::tag
std::string tag() const
Text access to the element's tag.
Definition: XMLElements.h:414
dd4hep::xml::Document::uri
std::string uri() const
Acces the document URI.
Definition: XMLElements.cpp:1047
dd4hep::xml::_toDouble
double _toDouble(const XmlChar *value)
Conversion function from raw unicode string to double.
Definition: XMLElements.cpp:357
dd4hep::xml::Handle_t::attr
T attr(const XmlChar *name, T default_value) const
Access typed attribute value by its unicode name. If not existing returns default value.
dd4hep::xml::RefElement::setName
void setName(const XmlChar *new_name)
Change/set the object's name.
Definition: XMLElements.cpp:1189
dd4hep::xml::XmlException
xercesc::DOMException XmlException
Definition: DetectorImp.cpp:53
dd4hep::xml::cpXmlChar
const XmlChar * cpXmlChar
Definition: XMLElements.h:526
dd4hep::xml::Element::Element
Element(const Element &e)
Constructor from XmlElement handle.
Definition: XMLElements.h:780
dd4hep::xml::Element::append
void append(Handle_t handle) const
Append a new element to the existing tree.
Definition: XMLElements.h:839
dd4hep::xml::Document::operator->
DOC operator->() const
Accessot to DOM document behaviour using arrow operator.
Definition: XMLElements.h:715
v
View * v
Definition: MultiView.cpp:28
dd4hep::xml::NodeList::operator=
NodeList & operator=(const NodeList &l)
Assignment operator.
Definition: XMLElements.cpp:621
dd4hep::xml::NodeList
Class describing a list of XML nodes.
Definition: XMLElements.h:349
dd4hep::xml::Handle_t::clone
Handle_t clone(XmlDocument *new_doc) const
Clone the DOMelement - with the option of a deep copy.
Definition: XMLElements.cpp:646
dd4hep::exception
void exception(const std::string &src, const std::string &msg)
Definition: RootDictionary.h:69
dd4hep::xml::_toUInt
unsigned int _toUInt(const XmlChar *value)
Conversion function from raw unicode string to unsigned int.
Definition: XMLElements.cpp:334
dd4hep::xml::Handle_t::attr_value_nothrow
const XmlChar * attr_value_nothrow(const XmlChar *attr) const
Access attribute value by the attribute's unicode name (no exception thrown if not present)
Definition: XMLElements.cpp:869
dd4hep::xml::Element::m_element
Handle_t m_element
The underlying object holding the XmlElement pointer.
Definition: XMLElements.h:775
dd4hep::xml::Attribute
const XmlAttr * Attribute
Definition: XMLElements.h:38
dd4hep::xml::NodeList::previous
XmlElement * previous() const
Go back to previous element.
Definition: XMLElements.cpp:604
dd4hep::xml::Element::tag
std::string tag() const
Access the tag name of this DOM element.
Definition: XMLElements.h:823
dd4hep::xml::Handle_t::setRef
Handle_t setRef(const XmlChar *tag, const XmlChar *ref)
Add reference child as a new child node. The obj must have the "name" attribute!
Definition: XMLElements.cpp:937
dd4hep::xml::Document::DOC
XmlDocument * DOC
Definition: XMLElements.h:699
dd4hep::xml::Handle_t::append
void append(Handle_t e) const
Append a DOM element to the current node.
Definition: XMLElements.cpp:727
dd4hep::xml::Tag_t::operator=
Tag_t & operator=(const char *s)
Assignment of a normal ASCII string.
Definition: XMLElements.cpp:528
dd4hep::xml::Handle_t::parent
Handle_t parent() const
Access the element's parent element.
Definition: XMLElements.cpp:663
dd4hep::xml::_toLong
long _toLong(const XmlChar *value)
Conversion function from raw unicode string to long.
Definition: XMLElements.cpp:315
dd4hep::xml::Element::addChild
Handle_t addChild(const XmlChar *tag) const
Add a new child to the DOM node.
Definition: XMLElements.cpp:1121
dd4hep::xml::Element::numChildren
size_t numChildren(const XmlChar *tag_value, bool exc=true) const
Access the number of children of this DOM element with a given tag name.
Definition: XMLElements.h:881
dd4hep::xml::Element::attr_value
const XmlChar * attr_value(const Attribute a) const
Access attribute value by the attribute (throws exception if not present)
Definition: XMLElements.h:877
dd4hep::xml::Document::m_doc
DOC m_doc
Definition: XMLElements.h:700
dd4hep::xml::XmlString::length
static size_t length(const char *s)
String length in native representation.
Definition: XMLElements.cpp:154
dd4hep::xml::Document::createElt
Handle_t createElt(const XmlChar *tag) const
Create DOM element.
Definition: XMLElements.cpp:1031
dd4hep::xml::Handle_t::remove
Handle_t remove(Handle_t e) const
Remove a single child node identified by its handle from the tree of the element.
Definition: XMLElements.cpp:732
dd4hep::xml::Tag_t::c_str
const char * c_str() const
Access data buffer of STL string.
Definition: XMLElements.h:308
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::xml::DocumentHolder::DocumentHolder
DocumentHolder()=default
Default Constructor.
dd4hep::xml::enableEnvironResolution
bool enableEnvironResolution(bool new_value)
Enable/disable environment resolution when parsing strings.
Definition: XMLElements.cpp:408
dd4hep::xml::Handle_t::setAttrs
void setAttrs(Handle_t e) const
Set attributes as in argument handle.
Definition: XMLElements.cpp:823
dd4hep::xml::Handle_t::Handle_t
Handle_t(Elt_t e=0)
Initializing constructor.
Definition: XMLElements.h:389
INLINE
#define INLINE
Definition: XMLElements.h:525
dd4hep::xml::NodeList::reset
XmlElement * reset()
Reset the nodelist - e.g. restart iteration from beginning.
Definition: XMLElements.cpp:582
dd4hep::xml::_toDictionary
void _toDictionary(const XmlChar *name, const XmlChar *value)
Helper function to populate the evaluator dictionary.
Definition: XMLElements.cpp:365
dd4hep::xml::NodeList::~NodeList
~NodeList()
Default destructor.
Definition: XMLElements.cpp:578
dd4hep::xml::Strng_t::Strng_t
Strng_t(const std::string &c)
Initializing constructor from STL string.
Definition: XMLElements.h:187
dd4hep::xml::Element::setValue
void setValue(const T &val) const
Set element value.
Definition: XMLElements.h:904
dd4hep::xml::Handle_t::numChildren
size_t numChildren(const XmlChar *tag, bool throw_exception) const
Access the number of children of this DOM element with a given tag name.
Definition: XMLElements.cpp:695
dd4hep::xml::Tag_t::Tag_t
Tag_t(const Tag_t &c)
Copy constructor.
Definition: XMLElements.h:283
dd4hep::xml::Element::Elt_t
Handle_t::Elt_t Elt_t
Simplification type declarations.
Definition: XMLElements.h:772
dd4hep::xml::Element::operator=
Element & operator=(const Element &c)
Assignment operator.
Definition: XMLElements.h:795
dd4hep::xml::Handle_t::attr_name
const XmlChar * attr_name(const Attribute attr) const
Access attribute name (throws exception if not present)
Definition: XMLElements.cpp:851
dd4hep::xml::NodeList::NodeList
NodeList(const NodeList &l)
Copy constructor.
Definition: XMLElements.cpp:564
dd4hep::xml::Handle_t::rawText
const XmlChar * rawText() const
Unicode text access to the element's text.
Definition: XMLElements.cpp:636
dd4hep::xml::Tag_t
Class to support both way translation between C++ and XML strings.
Definition: XMLElements.h:254
dd4hep::xml::Handle_t::hasChild
bool hasChild(const XmlChar *tag) const
Check the existence of a child with a given tag name.
Definition: XMLElements.cpp:764
dd4hep::xml::get_float_precision
int get_float_precision()
Access floating point precision on conversion to string.
Definition: XMLElements.cpp:229
dd4hep::xml::NodeList::m_ptr
XmlElement * m_ptr
Definition: XMLElements.h:353
dd4hep::xml::RefElement::refName
const XmlChar * refName() const
Access the object's reference name in unicode (same as name)
Definition: XMLElements.cpp:1183
dd4hep::xml::NodeList::m_node
XmlElement * m_node
Definition: XMLElements.h:352
dd4hep::xml::Collection_t::reset
Collection_t & reset()
Reset the collection object to restart the iteration.
Definition: XMLElements.cpp:1212
dd4hep::xml::Handle_t::removeChildren
void removeChildren(const XmlChar *tag) const
Remove children with a given tag name from the DOM node.
Definition: XMLElements.cpp:752
dd4hep::xml::Document::~Document
~Document()=default
Destructor.
dd4hep::xml::Strng_t::m_xml
XmlChar * m_xml
Pointer to unicode string.
Definition: XMLElements.h:173
dd4hep::xml::Handle_t::attr_value
const XmlChar * attr_value(const Attribute attr) const
Access attribute value by the attribute (throws exception if not present)
Definition: XMLElements.cpp:864
dd4hep::xml::Collection_t::for_each
void for_each(T oper) const
Loop processor using function object.
Definition: XMLElements.h:667
dd4hep::xml::Handle_t::attr
T attr(const XmlChar *name) const
Access typed attribute value by its unicode name.
dd4hep::xml::Element::child
Handle_t child(const Strng_t &tag_value, bool except=true) const
Access child by tag name. Thow an exception if required in case the child is not present.
Definition: XMLElements.h:914
dd4hep::xml::operator==
bool operator==(const std::string &c, const Tag_t &b)
Equality operator between tag object and STL string.
Definition: XMLElements.h:324
dd4hep::xml::set_float_precision
int set_float_precision(int precision)
Change floating point precision on conversion to string.
Definition: XMLElements.cpp:222
dd4hep::xml::_toInt
int _toInt(const XmlChar *value)
Conversion function from raw unicode string to int.
Definition: XMLElements.cpp:330
config.h
dd4hep::xml::DocumentHolder::~DocumentHolder
virtual ~DocumentHolder()
Standard destructor - releases the document.
Definition: XMLElements.cpp:1070
dd4hep::xml::Strng_t::Strng_t
Strng_t(const XmlChar *c)
Initializing constructor from unicode string.
Definition: XMLElements.h:176
dd4hep::xml
Namespace for the AIDA detector description toolkit supporting XML utilities.
Definition: ConditionsTags.h:27
dd4hep::xml::Element::setRef
Attribute setRef(const XmlChar *tag, const XmlChar *refname) const
Set the reference attribute to the node (adds attribute ref="ref-name")
Definition: XMLElements.cpp:1106
dd4hep::xml::Handle_t::attr
T attr(const char *name, const T &default_value) const
Access typed attribute value by its name.
Definition: XMLElements.h:490
dd4hep::xml::RefElement::m_name
Attribute m_name
Attribute holding thre name.
Definition: XMLElements.h:956
dd4hep::xml::Tag_t::~Tag_t
~Tag_t()
Destructor.
Definition: XMLElements.h:287
dd4hep::xml::Handle_t::children
NodeList children(const XmlChar *tag) const
Access a group of children identified by the same tag name.
Definition: XMLElements.cpp:722
dd4hep::xml::Element::removeAttrs
void removeAttrs() const
Remove all attributes of this element.
Definition: XMLElements.h:889
dd4hep::xml::RefElement::name
const XmlChar * name() const
Access the object's name in unicode.
Definition: XMLElements.cpp:1177
dd4hep::xml::Document::ptr
DOC ptr() const
Accessot to DOM document behaviour.
Definition: XMLElements.h:717
dd4hep::xml::XmlString::release
static void release(char **p)
Release string.
Definition: XMLElements.cpp:151
dd4hep::xml::Handle_t::attr_ptr
Attribute attr_ptr(const XmlChar *attr) const
Access attribute pointer by the attribute's unicode name (throws exception if not present)
Definition: XMLElements.cpp:838
dd4hep::xml::Element::ptr
Elt_t ptr() const
Access to XmlElement pointer.
Definition: XMLElements.h:813
dd4hep::xml::Collection_t::for_each
void for_each(const XmlChar *tag_name, T oper) const
Loop processor using function object.
Definition: XMLElements.h:677
dd4hep::xml::Element::Element
Element(const Handle_t &e)
Constructor from XmlElement handle.
Definition: XMLElements.h:778
dd4hep::xml::Element::getAttr
Attribute getAttr(const XmlChar *name) const
Access single attribute by its name.
Definition: XMLElements.cpp:1101
dd4hep::xml::Element::attr
T attr(const char *name, T default_value) const
Access typed attribute value by its name.
Definition: XMLElements.h:868
dd4hep::xml::_toString
std::string _toString(const Attribute attr)
Convert xml attribute to STL string.
Definition: XMLElements.cpp:234
dd4hep::xml::Strng_t::length
size_t length() const
String length in native representation.
Definition: XMLElements.h:208
dd4hep::xml::XmlString::transcode
static XmlChar * transcode(const char *c)
Transcode string.
Definition: XMLElements.cpp:145
dd4hep::xml::Document::operator=
Document & operator=(const Document &d)=default
Assignment.
dd4hep::xml::Strng_t::operator=
Strng_t & operator=(const XmlChar *s)
Assignment opertor from unicode string.
Definition: XMLElements.cpp:487
dd4hep::xml::Strng_t
Helper class to encapsulate a unicode string.
Definition: XMLElements.h:170
dd4hep::xml::Handle_t::Elt_t
XmlElement * Elt_t
Definition: XMLElements.h:383
dd4hep::xml::DocumentHolder
Class supporting the basic functionality of an XML document including ownership.
Definition: XMLElements.h:741
dd4hep::xml::Handle_t::child
Handle_t child(const XmlChar *tag, bool throw_exception=true) const
Access a single child by its tag name (unicode)
Definition: XMLElements.cpp:710
dd4hep::xml::Element::clone
Handle_t clone(const Document &new_doc) const
Clone the DOMelement.
Definition: XMLElements.h:843
dd4hep::xml::Handle_t::setText
void setText(const XmlChar *text) const
Set the element's text.
Definition: XMLElements.cpp:783
dd4hep::xml::Element::attr
T attr(const XmlChar *tag_value, T default_value) const
Access attribute with implicit return type conversion.
Definition: XMLElements.h:859
dd4hep::xml::Element::hasAttr
bool hasAttr(const XmlChar *name) const
Check for the existence of a named attribute.
Definition: XMLElements.h:847
dd4hep::xml::Document::clone
Handle_t clone(Handle_t source) const
Clone a DOM element / sub-tree.
Definition: XMLElements.cpp:1260
dd4hep::xml::DocumentHolder::assign
DocumentHolder & assign(DOC d)
Assign new document. Old document is dropped.
Definition: XMLElements.cpp:1056
dd4hep::xml::Document
Class supporting the basic functionality of an XML document.
Definition: XMLElements.h:697
dd4hep::xml::Document::Document
Document()
Default Constructor.
Definition: XMLElements.h:703
dd4hep::xml::RefElement::RefElement
RefElement(const Handle_t &e)
Construction from existing object handle.
Definition: XMLElements.cpp:1161
dd4hep::xml::operator+
Strng_t operator+(const Strng_t &a, const char *b)
Unicode string concatenation of a normal ASCII string from right side.
Definition: XMLElements.cpp:429
dd4hep::xml::Element::parentElement
Elt_t parentElement() const
Access the XmlElements parent.
Definition: XMLElements.cpp:1080
dd4hep::xml::Element::attr_name
const XmlChar * attr_name(const Attribute a) const
Access attribute name (throws exception if not present)
Definition: XMLElements.h:873
dd4hep::xml::RefElement::operator=
RefElement & operator=(const RefElement &e)
Assignment operator.
Definition: XMLElements.cpp:1172
dd4hep::xml::Collection_t::size
size_t size() const
Access the collection size. Avoid this call – sloooow!
Definition: XMLElements.cpp:1218
dd4hep::xml::Tag_t::Tag_t
Tag_t(const char *s)
Constructor from normal ASCII string.
Definition: XMLElements.h:260
dd4hep::xml::Handle_t::m_node
Elt_t m_node
The pointer to the XmlElement.
Definition: XMLElements.h:386
dd4hep::xml::RefElement
User abstraction class to manipulate named XML elements (references) within a document.
Definition: XMLElements.h:953
dd4hep::xml::Handle_t::attr
T attr(const char *name) const
Access typed attribute value by its name.
Definition: XMLElements.h:486
dd4hep::xml::Strng_t::ptr
const XmlChar * ptr() const
Accessor to unicode string.
Definition: XMLElements.h:204
dd4hep::xml::CSTR
const std::string & CSTR
Definition: XMLElements.h:95
dd4hep::xml::Document::Document
Document(DOC d)
Initializing Constructor.
Definition: XMLElements.h:705
dd4hep::xml::_toULong
unsigned long _toULong(const XmlChar *value)
Conversion function from raw unicode string to unsigned long.
Definition: XMLElements.cpp:323
dd4hep::xml::DocumentHolder::operator=
DocumentHolder & operator=(const DocumentHolder &copy)=delete
Assignment operator.
dd4hep::xml::Element::tagName
const XmlChar * tagName() const
Access the tag name of this DOM element.
Definition: XMLElements.h:827
dd4hep::xml::Strng_t::~Strng_t
~Strng_t()
Default destructor - release unicode string.
Definition: XMLElements.h:195
dd4hep::xml::DocumentHandler
Class supporting to read and parse XML documents.
Definition: DocumentHandler.h:39
dd4hep::xml::Collection_t::Collection_t
Collection_t(Handle_t node, const XmlChar *tag)
Constructor over XmlElements with a given tag name.
Definition: XMLElements.cpp:1194
dd4hep::xml::Tag_t::Tag_t
Tag_t(const Strng_t &s)
Constructor from internal XML string.
Definition: XMLElements.h:269
dd4hep::xml::Element::operator!
bool operator!() const
operator NOT: check handle validity
Definition: XMLElements.h:791
dd4hep::xml::Handle_t::rawTag
const XmlChar * rawTag() const
Unicode text access to the element's tag. Tis must be wrong ....
Definition: XMLElements.cpp:631
dd4hep::xml::Element::remove
Handle_t remove(Handle_t node) const
Remove a child node identified by its handle.
Definition: XMLElements.h:918
dd4hep::xml::_toFloat
float _toFloat(const XmlChar *value)
Conversion function from raw unicode string to float.
Definition: XMLElements.cpp:349
dd4hep::xml::XmlChar
XERCES_XMLCH_T XmlChar
Use the definition from the autoconf header of Xerces:
Definition: config.h:53
dd4hep::xml::Element
User abstraction class to manipulate XML elements within a document.
Definition: XMLElements.h:769
dd4hep::xml::dump_tree
void dump_tree(Handle_t elt)
Dump partial or full XML trees to stdout.
Definition: DocumentHandler.cpp:699
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::xml::Tag_t::str
const std::string & str() const
Access writable STL string.
Definition: XMLElements.h:304
dd4hep::xml::Handle_t::attributes
std::vector< Attribute > attributes() const
Retrieve a collection of all attributes of this DOM element.
Definition: XMLElements.cpp:678
dd4hep::xml::Element::setAttr
Attribute setAttr(const XmlChar *nam, const T &val) const
Set single attribute.
Definition: XMLElements.h:900
dd4hep::xml::Element::attr
T attr(const XmlChar *tag_value) const
Access attribute with implicit return type conversion.
Definition: XMLElements.h:855
dd4hep::xml::XmlString
Definition of the XmlString class.
Definition: XMLElements.h:51
dd4hep::xml::_ptrToString
std::string _ptrToString(const void *p, const char *fmt="%p")
Format void pointer (64 bits) to string with arbitrary format.
Definition: XMLElements.cpp:311
dd4hep::xml::getEnviron
std::string getEnviron(const std::string &env)
Helper function to lookup environment from the expression evaluator.
Definition: XMLElements.cpp:403
dd4hep::xml::NodeList::m_tag
Tag_t m_tag
Definition: XMLElements.h:351
dd4hep::xml::Document::Document
Document(const Document &d)=default
Copy constructor.
dd4hep::xml::Element::operator=
Element & operator=(Handle_t handle)
Assignment operator.
Definition: XMLElements.h:800
dd4hep::xml::Collection_t::m_children
NodeList m_children
Reference to the list of child nodes.
Definition: XMLElements.h:639
dd4hep::xml::Handle_t::setAttr
Attribute setAttr(const XmlChar *t, const XmlChar *v) const
Generic attribute setter with unicode value.
Definition: XMLElements.cpp:919
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::xml::dumpTree
void dumpTree(XmlDocument *doc)
Dump DOM tree of a document.
dd4hep::xml::Handle_t::checksum
unsigned int checksum(unsigned int param, unsigned int(fcn)(unsigned int param, const XmlChar *, size_t)=0) const
Checksum (sub-)tree of a xml document/tree. Default will pick up the adler32 checksum.
Definition: XMLElements.cpp:990
dd4hep::xml::Handle_t::hasAttr
bool hasAttr(const XmlChar *t) const
Check for the existence of a named attribute.
Definition: XMLElements.cpp:673
dd4hep::xml::Element::attributes
std::vector< Attribute > attributes() const
Retrieve a collection of all attributes of this DOM element.
Definition: XMLElements.h:893
dd4hep::xml::Collection_t::operator++
void operator++() const
Operator to advance the collection (pre increment)
Definition: XMLElements.cpp:1230
dd4hep::xml::Element::parent
Handle_t parent() const
Access the XmlElements parent.
Definition: XMLElements.h:817
dd4hep::xml::Handle_t::rawValue
const XmlChar * rawValue() const
Unicode text access to the element's value.
Definition: XMLElements.cpp:641
dd4hep::xml::DocumentHolder::DocumentHolder
DocumentHolder(const DocumentHolder &copy)=delete
Default Constructor.
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
dd4hep::xml::Handle_t::value
std::string value() const
Text access to the element's value.
Definition: XMLElements.h:422
dd4hep::xml::_toBool
bool _toBool(const XmlChar *value)
Conversion function from raw unicode string to bool.
Definition: XMLElements.cpp:338
dd4hep::xml::Element::attr
T attr(const XmlAttr *att) const
Access attribute with implicit return type conversion.
Definition: XMLElements.h:851
dd4hep::xml::Handle_t::ptr
Elt_t ptr() const
Direct access to the XmlElement by function.
Definition: XMLElements.h:401
dd4hep::xml::Strng_t::Strng_t
Strng_t(const Strng_t &c)
Copy constructor.
Definition: XMLElements.h:191
dd4hep::xml::Element::text
void text(const std::string value) const
Set text attribute to the XML node.
Definition: XMLElements.h:835
handle
void handle(const O *o, const C &c, F pmf)
Definition: LCDDConverter.cpp:1105
dd4hep::xml::Collection_t::operator--
void operator--() const
Operator to advance the collection (pre decrement)
Definition: XMLElements.cpp:1241
dd4hep::xml::Handle_t::removeAttrs
void removeAttrs() const
Remove all attributes of this element.
Definition: XMLElements.cpp:801
dd4hep::xml::Collection_t::current
Elt_t current() const
Access to current element.
Definition: XMLElements.h:661
dd4hep::xml::Handle_t::text
std::string text() const
Text access to the element's text.
Definition: XMLElements.h:418
dd4hep::xml::Handle_t::operator->
Elt_t operator->() const
Direct access to the XmlElement using the operator->
Definition: XMLElements.h:393
dd4hep::xml::Element::addComment
void addComment(const XmlChar *text) const
Add comment node to the element.
Definition: XMLElements.cpp:1135
dd4hep::xml::Handle_t::attr_nothrow
Attribute attr_nothrow(const XmlChar *tag) const
Access attribute pointer by the attribute's unicode name (no exception thrown if not present)
Definition: XMLElements.cpp:668
dd4hep::xml::Document::root
Handle_t root() const
Access the ROOT eleemnt of the DOM document.
Definition: XMLElements.cpp:1040