DD4hep  1.28.0
Detector Description Toolkit for High Energy Physics
XMLElements.cpp
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 
14 // Framework include files
15 #ifdef DD4HEP_USE_TINYXML
16 #include "XML/tinyxml.h"
17 #else
18 #include <xercesc/util/Xerces_autoconf_config.hpp>
19 #include "xercesc/util/XMLString.hpp"
20 #include "xercesc/dom/DOMElement.hpp"
21 #include "xercesc/dom/DOMDocument.hpp"
22 #include "xercesc/dom/DOMNodeList.hpp"
23 #include "xercesc/dom/DOM.hpp"
24 #include "XML/config.h"
25 #endif
26 
27 #include "XML/XMLElements.h"
28 #include "XML/Printout.h"
29 #include "XML/XMLTags.h"
30 
31 // C/C++ include files
32 #include <iostream>
33 #include <stdexcept>
34 #include <cstdio>
35 #include <map>
36 
37 using namespace dd4hep::xml;
38 static const size_t INVALID_NODE = ~0U;
39 static int s_float_precision = -1;
40 
41 // Forward declarations
42 namespace dd4hep {
43  std::pair<int, double> _toInteger(const std::string& value);
44  std::pair<int, double> _toFloatingPoint(const std::string& value);
45  void _toDictionary(const std::string& name, const std::string& value, const std::string& typ);
46  std::string _getEnviron(const std::string& env);
47 }
48 
49 // Static storage
50 namespace {
51  bool s_resolve_environment = true;
52  std::string _checkEnviron(const std::string& env) {
53  if ( s_resolve_environment ) {
54  std::string r = dd4hep::_getEnviron(env);
55  return r.empty() ? env : r;
56  }
57  return env;
58  }
59 }
60 
61 // Shortcuts
62 #define _D(x) Xml(x).d
63 #define _E(x) Xml(x).e
64 #define _N(x) Xml(x).n
65 #define _L(x) Xml(x).l
66 #define _XE(x) Xml(x).xe
67 
68 #ifdef DD4HEP_USE_TINYXML
69 #define ELEMENT_NODE_TYPE TiXmlNode::ELEMENT
70 #define getTagName Value
71 #define getTextContent GetText
72 #define getName Name
73 #define getValue Value
74 #define getNodeValue Value
75 #define getNodeType Type
76 #define setNodeValue SetValue
77 #define getParentNode Parent()->ToElement
78 #define getAttributeNode(x) AttributeNode(x)
79 #define appendChild LinkEndChild
80 #define getOwnerDocument GetDocument
81 #define getDocumentElement RootElement
82 #define getDocumentURI Value
83 
85 union Xml {
86  Xml(const void* ptr) : p(ptr) {}
87  const void* p;
88  TiXmlNode* n;
89  TiXmlElement* e;
90  TiXmlAttribute* a;
91  TiXmlDocument* d;
92  XmlElement* xe;
93 };
94 
95 namespace {
96  XmlElement* node_first(XmlElement* e, const Tag_t& t) {
97  if ( t.str()=="*" ) return e ? (XmlElement*)_E(e)->FirstChildElement() : 0;
98  return e ? (XmlElement*)_E(e)->FirstChildElement(t.str()) : 0;
99  }
100  size_t node_count(XmlElement* elt, const Tag_t& t) {
101  size_t cnt = 0;
102  TiXmlElement* e = Xml(elt).e;
103  if ( t.str()=="*" )
104  for(e=e->FirstChildElement();e; e=e->NextSiblingElement()) ++cnt;
105  else
106  for(e=e->FirstChildElement(t.str());e; e=e->NextSiblingElement(t.str())) ++cnt;
107  return cnt;
108  }
109 }
111  return c ? ::strdup(c) : 0;
112 }
113 XmlChar* dd4hep::xml::XmlString::transcode(const char* c) {return c ? ::strdup(c) : 0;
114 }
115 void dd4hep::xml::XmlString::release(char** p) {
116  if(p && *p) {::free(*p); *p=0;}
117 }
118 size_t dd4hep::xml::XmlString::length(const char* p) {
119  return p ? ::strlen(p) : 0;
120 }
121 
122 #else
123 #define ELEMENT_NODE_TYPE xercesc::DOMNode::ELEMENT_NODE
124 
126 union Xml {
127  Xml(const void* ptr)
128  : p(ptr) {
129  }
130  const void* p;
131  xercesc::DOMNode* n;
132  xercesc::DOMAttr* a;
133  xercesc::DOMElement* e;
134  xercesc::DOMDocument* d;
135  xercesc::DOMNodeList* l;
136  XmlElement* xe;
137 };
138 
140  return xercesc::XMLString::replicate(c);
141 }
143  return xercesc::XMLString::transcode(c);
144 }
146  return xercesc::XMLString::transcode(c);
147 }
149  return xercesc::XMLString::release(p);
150 }
152  return xercesc::XMLString::release(p);
153 }
154 size_t dd4hep::xml::XmlString::length(const char* p) {
155  return p ? xercesc::XMLString::stringLen(p) : 0;
156 }
158  return p ? xercesc::XMLString::stringLen(p) : 0;
159 }
160 
161 namespace {
162  size_t node_count(XmlElement* e, const Tag_t& t) {
163  size_t cnt = 0;
164  if ( e ) {
165  const std::string& tag = t;
166  xercesc::DOMElement *ee = Xml(e).e;
167  if ( ee ) {
168  for(xercesc::DOMElement* elt=ee->getFirstElementChild(); elt; elt=elt->getNextElementSibling()) {
169  if ( elt->getParentNode() == ee ) {
170  std::string child_tag = _toString(elt->getTagName());
171  if ( tag == "*" || child_tag == tag ) ++cnt;
172  }
173  }
174  }
175  }
176  return cnt;
177  }
178  XmlElement* node_first(XmlElement* e, const Tag_t& t) {
179  if ( e ) {
180  const std::string& tag = t;
181  xercesc::DOMElement* ee = Xml(e).e;
182  if ( ee ) {
183  for(xercesc::DOMElement* elt=ee->getFirstElementChild(); elt; elt=elt->getNextElementSibling()) {
184  if ( elt->getParentNode() == ee ) {
185  if ( tag == "*" ) return _XE(elt);
186  std::string child_tag = _toString(elt->getTagName());
187  if ( child_tag == tag ) return _XE(elt);
188  }
189  }
190  }
191  }
192  return 0;
193  }
194 }
195 
197 std::string dd4hep::xml::_toString(const XmlChar *toTranscode) {
198  char *buff = XmlString::transcode(toTranscode);
199  std::string tmp(buff == 0 ? "" : buff);
200  XmlString::release(&buff);
201  if ( tmp.length()<3 ) return tmp;
202  if ( !(tmp[0] == '$' && tmp[1] == '{') ) return tmp;
203  tmp = _checkEnviron(tmp);
204  return tmp;
205 }
206 #endif
207 
208 namespace {
209  Attribute attribute_node(XmlElement* n, const XmlChar* t) {
210  return Attribute(_E(n)->getAttributeNode(t));
211  }
212  const XmlChar* attribute_value(Attribute a) {
213  return Xml(a).a->getValue();
214  }
215 #if 0
216  int node_type(XmlNode* n) {return Xml(n).n->getNodeType();}
217  int node_type(Handle_t n) {return Xml(n.ptr()).n->getNodeType();}
218 #endif
219 }
220 
223  int tmp = s_float_precision;
224  s_float_precision = precision;
225  return tmp;
226 }
227 
230  return s_float_precision;
231 }
232 
235  if (attr)
236  return _toString(attribute_value(attr));
237  return "";
238 }
239 
240 template <typename T> static inline std::string __to_string(T value, const char* fmt) {
241  char text[128];
242  ::snprintf(text, sizeof(text), fmt, value);
243  return text;
244 }
245 
247 std::string dd4hep::xml::_toString(const char* s) {
248  if ( !s || *s == 0 ) return "";
249  else if ( !(*s == '$' && *(s+1) == '{') ) return s;
250  return _checkEnviron(s);
251 }
252 
254 std::string dd4hep::xml::_toString(const std::string& s) {
255  if ( s.length() < 3 || s[0] != '$' ) return s;
256  else if ( !(s[0] == '$' && s[1] == '{') ) return s;
257  return _checkEnviron(s);
258 }
259 
261 std::string dd4hep::xml::_toString(unsigned long v, const char* fmt) {
262  return __to_string(v, fmt);
263 }
264 
266 std::string dd4hep::xml::_toString(unsigned int v, const char* fmt) {
267  return __to_string(v, fmt);
268 }
269 
271 std::string dd4hep::xml::_toString(int v, const char* fmt) {
272  return __to_string(v, fmt);
273 }
274 
276 std::string dd4hep::xml::_toString(long v, const char* fmt) {
277  return __to_string(v, fmt);
278 }
279 
281 std::string dd4hep::xml::_toString(float v, const char* fmt) {
282  if ( s_float_precision >= 0 ) {
283  char format[32];
284  ::snprintf(format, sizeof(format), "%%.%de", s_float_precision);
285  return __to_string(v, format);
286  }
287  return __to_string(v, fmt);
288 }
289 
291 std::string dd4hep::xml::_toString(double v, const char* fmt) {
292  if ( s_float_precision >= 0 ) {
293  char format[32];
294  ::snprintf(format, sizeof(format), "%%.%de", s_float_precision);
295  return __to_string(v, format);
296  }
297  return __to_string(v, fmt);
298 }
299 
301 std::string dd4hep::xml::_toString(const Strng_t& s) {
302  return _toString(Tag_t(s));
303 }
304 
306 std::string dd4hep::xml::_toString(const Tag_t& s) {
307  return s.str();
308 }
309 
311 std::string dd4hep::xml::_ptrToString(const void* v, const char* fmt) {
312  return __to_string(v, fmt);
313 }
314 
315 long dd4hep::xml::_toLong(const XmlChar* value) {
316  if (value) {
317  std::string s = _toString(value);
318  return dd4hep::_toInteger(s).second;
319  }
320  return -1;
321 }
322 
323 unsigned long dd4hep::xml::_toULong(const XmlChar* value) {
324  long val = _toLong(value);
325  if ( val >= 0 ) return (unsigned long) val;
326  std::string s = _toString(value);
327  throw std::runtime_error("dd4hep: Severe error during expression evaluation of " + s);
328 }
329 
330 int dd4hep::xml::_toInt(const XmlChar* value) {
331  return (int)_toLong(value);
332 }
333 
334 unsigned int dd4hep::xml::_toUInt(const XmlChar* value) {
335  return (unsigned int)_toULong(value);
336 }
337 
338 bool dd4hep::xml::_toBool(const XmlChar* value) {
339  if (value) {
340  std::string s = _toString(value);
341  char c = ::toupper(s[0]);
342  if ( c == 'T' || c == '1' ) return true;
343  if ( c == 'F' || c == '0' ) return false;
344  return _toInt(value) != 0;
345  }
346  return false;
347 }
348 
349 float dd4hep::xml::_toFloat(const XmlChar* value) {
350  if (value) {
351  std::string s = _toString(value);
352  return (float) dd4hep::_toFloatingPoint(s).second;
353  }
354  return 0.0;
355 }
356 
357 double dd4hep::xml::_toDouble(const XmlChar* value) {
358  if (value) {
359  std::string s = _toString(value);
360  return dd4hep::_toFloatingPoint(s).second;
361  }
362  return 0.0;
363 }
364 
365 void dd4hep::xml::_toDictionary(const XmlChar* name, const XmlChar* value) {
366  std::string n = _toString(name).c_str(), v = _toString(value);
367  dd4hep::_toDictionary(n, v, "number");
368 }
369 
371 void dd4hep::xml::_toDictionary(const XmlChar* name, const Strng_t& s) {
372  return _toDictionary(name, s.ptr());
373 }
374 
376 void dd4hep::xml::_toDictionary(const XmlChar* name, const Tag_t& t) {
377  return _toDictionary(name, t.ptr());
378 }
379 
380 template <typename T>
381 void dd4hep::xml::_toDictionary(const XmlChar* name, T value) {
382  Strng_t item = _toString(value);
383  const XmlChar* item_value = item;
384  _toDictionary(name, item_value);
385 }
386 
387 #ifndef DD4HEP_USE_TINYXML
388 template void dd4hep::xml::_toDictionary(const XmlChar* name, const char* value);
389 #endif
390 template void dd4hep::xml::_toDictionary(const XmlChar* name, const Tag_t& value);
391 template void dd4hep::xml::_toDictionary(const XmlChar* name, const Strng_t& value);
392 template void dd4hep::xml::_toDictionary(const XmlChar* name, const std::string& value);
393 template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned long value);
394 template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned int value);
395 template void dd4hep::xml::_toDictionary(const XmlChar* name, unsigned short value);
396 template void dd4hep::xml::_toDictionary(const XmlChar* name, int value);
397 template void dd4hep::xml::_toDictionary(const XmlChar* name, long value);
398 template void dd4hep::xml::_toDictionary(const XmlChar* name, short value);
399 template void dd4hep::xml::_toDictionary(const XmlChar* name, float value);
400 template void dd4hep::xml::_toDictionary(const XmlChar* name, double value);
401 
403 std::string dd4hep::xml::getEnviron(const std::string& env) {
404  return dd4hep::_getEnviron(env);
405 }
406 
409  bool tmp = s_resolve_environment;
410  s_resolve_environment = new_value;
411  return tmp;
412 }
413 
414 template <typename B>
415 static inline std::string i_add(const std::string& a, B b) {
416  std::string r = a;
417  r += b;
418  return r;
419 }
420 
421 Strng_t dd4hep::xml::operator+(const Strng_t& a, const std::string& b) {
422  return _toString(a.ptr()) + b;
423 }
424 
425 Strng_t dd4hep::xml::operator+(const std::string& a, const Strng_t& b) {
426  return a + _toString(b.ptr());
427 }
428 
429 Strng_t dd4hep::xml::operator+(const Strng_t& a, const char* b) {
430  return _toString(a.ptr()) + b;
431 }
432 
433 Strng_t dd4hep::xml::operator+(const char* a, const Strng_t& b) {
434  return std::string(a) + _toString(b.ptr());
435 }
436 
438  return _toString(a.ptr()) + _toString(b.ptr());
439 }
440 
441 Tag_t dd4hep::xml::operator+(const Tag_t& a, const char* b) {
442  std::string res = a.str() + b;
443  return Tag_t(res);
444 }
445 
446 Tag_t dd4hep::xml::operator+(const char* a, const Tag_t& b) {
447  std::string res = a + b.str();
448  return Tag_t(res);
449 }
450 
452  std::string res = a.str() + _toString(b);
453  return Tag_t(res);
454 }
455 
456 Tag_t dd4hep::xml::operator+(const Tag_t& a, const std::string& b) {
457  std::string res = a.str() + b;
458  return Tag_t(res);
459 }
460 
461 #ifndef DD4HEP_USE_TINYXML
463  std::string res = _toString(a.ptr()) + _toString(b);
464  return Tag_t(res);
465 }
466 
468  std::string res = _toString(a) + _toString(b.ptr());
469  return Tag_t(res);
470 }
471 
472 Strng_t dd4hep::xml::operator+(const XmlChar* a, const std::string& b) {
473  std::string res = _toString(a) + b;
474  return Tag_t(res);
475 }
476 
477 Strng_t dd4hep::xml::operator+(const std::string& a, const XmlChar* b) {
478  std::string res = a + _toString(b);
479  return Tag_t(res);
480 }
481 
483  std::string res = a.str() + _toString(b);
484  return Tag_t(res);
485 }
486 
488  if (m_xml)
490  m_xml = s ? XmlString::replicate(s) : 0;
491  return *this;
492 }
493 #endif
494 
495 Strng_t& Strng_t::operator=(const char* s) {
496  if (m_xml)
498  m_xml = s ? XmlString::transcode(s) : 0;
499  return *this;
500 }
501 
503  if (this != &s) {
504  if (m_xml)
507  }
508  return *this;
509 }
510 
511 Strng_t& Strng_t::operator=(const std::string& s) {
512  if (m_xml)
514  m_xml = XmlString::transcode(s.c_str());
515  return *this;
516 }
517 
519  if (this != &s) {
520  m_str = s.m_str;
521  if (m_xml)
523  m_xml = XmlString::transcode(m_str.c_str());
524  }
525  return *this;
526 }
527 
528 Tag_t& Tag_t::operator=(const char* s) {
529  if (m_xml)
531  if (s) {
533  m_str = s;
534  }
535  else {
536  m_xml = 0;
537  m_str = "";
538  }
539  return *this;
540 }
541 
543  if (m_xml) {
545  }
546  char* ns = s.m_xml ? XmlString::transcode(s.m_xml) : 0;
547  m_str = ns ? ns : "";
548  m_xml = XmlString::transcode(m_str.c_str());
549  if (ns) {
551  }
552  return *this;
553 }
554 
555 Tag_t& Tag_t::operator=(const std::string& s) {
556  if (m_xml)
558  m_xml = XmlString::transcode(s.c_str());
559  m_str = s;
560  return *this;
561 }
562 
565  : m_tag(copy.m_tag), m_node(copy.m_node), m_ptr(0)
566 {
567  reset();
568 }
569 
571 NodeList::NodeList(XmlElement* node, const XmlChar* tag_value)
572  : m_tag(tag_value), m_node(node), m_ptr(0)
573 {
574  reset();
575 }
576 
579 }
580 
582 XmlElement* NodeList::reset() {
583  return m_ptr=node_first(m_node,m_tag);
584 }
585 
587 XmlElement* NodeList::next() const {
588 #ifdef DD4HEP_USE_TINYXML
589  if ( m_tag.str()=="*" )
590  return m_ptr =_XE(m_ptr ? _E(m_ptr)->NextSiblingElement() : 0);
591  return m_ptr = _XE(m_ptr ? _E(m_ptr)->NextSiblingElement(m_tag.str()) : 0);
592 #else
593  xercesc::DOMElement *elt = Xml(m_ptr).e;
594  for(elt=elt->getNextElementSibling(); elt; elt=elt->getNextElementSibling()) {
595  if ( m_tag.str() == "*" ) return m_ptr=Xml(elt).xe;
596  std::string child_tag = _toString(elt->getTagName());
597  if ( child_tag == m_tag ) return m_ptr=Xml(elt).xe;
598  }
599  return m_ptr=0;
600 #endif
601 }
602 
604 XmlElement* NodeList::previous() const {
605 #ifdef DD4HEP_USE_TINYXML
606  if ( m_tag.str()=="*" )
607  return m_ptr = _XE(m_ptr ? _E(m_ptr)->PreviousSiblingElement() : 0);
608  return m_ptr = _XE(m_ptr ? _E(m_ptr)->PreviousSiblingElement(m_tag) : 0);
609 #else
610  xercesc::DOMElement *elt = Xml(m_ptr).e;
611  for(elt=elt->getPreviousElementSibling(); elt; elt=elt->getPreviousElementSibling()) {
612  if ( m_tag.str()=="*" ) return m_ptr=Xml(elt).xe;
613  std::string child_tag = _toString(elt->getTagName());
614  if ( child_tag == m_tag ) return m_ptr=Xml(elt).xe;
615  }
616  return m_ptr=0;
617 #endif
618 }
619 
622  if (this != &l) {
623  m_tag = l.m_tag;
624  m_node = l.m_node;
625  reset();
626  }
627  return *this;
628 }
629 
631 const XmlChar* Handle_t::rawTag() const {
632  return _E(m_node)->getTagName();
633 }
634 
636 const XmlChar* Handle_t::rawText() const {
637  return _E(m_node)->getTextContent();
638 }
639 
641 const XmlChar* Handle_t::rawValue() const {
642  return _N(m_node)->getNodeValue();
643 }
644 
646 Handle_t Handle_t::clone(XmlDocument* new_doc) const {
647  if (m_node) {
648 #ifdef DD4HEP_USE_TINYXML
649  if ( new_doc ) {}
650  if ( _N(m_node)->Type() == ELEMENT_NODE_TYPE ) {
651  XmlElement* e = _XE(_N(m_node)->Clone()->ToElement());
652  if ( e ) return e;
653  }
654  throw std::runtime_error("TiXml: Handle_t::clone: Invalid source handle type [No element type].");
655 #else
656  return Elt_t(_D(new_doc)->importNode(_E(m_node), true));
657 #endif
658  }
659  throw std::runtime_error("Xml: Handle_t::clone: Invalid source handle.");
660 }
661 
664  return Elt_t(m_node ? _N(m_node)->getParentNode() : 0);
665 }
666 
668 Attribute Handle_t::attr_nothrow(const XmlChar* tag_value) const {
669  return attribute_node(m_node, tag_value);
670 }
671 
673 bool Handle_t::hasAttr(const XmlChar* tag_value) const {
674  return m_node && 0 != _E(m_node)->getAttributeNode(tag_value);
675 }
676 
678 std::vector<Attribute> Handle_t::attributes() const {
679  std::vector < Attribute > attrs;
680  if (m_node) {
681 #ifdef DD4HEP_USE_TINYXML
682  for(TiXmlAttribute* a=_E(m_node)->FirstAttribute(); a; a=a->Next())
683  attrs.emplace_back(Attribute(a));
684 #else
685  xercesc::DOMNamedNodeMap* l = _E(m_node)->getAttributes();
686  for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i) {
687  xercesc::DOMNode* attr_node = l->item(i);
688  attrs.emplace_back(Attribute(attr_node));
689  }
690 #endif
691  }
692  return attrs;
693 }
694 
695 size_t Handle_t::numChildren(const XmlChar* t, bool throw_exception) const {
696  size_t n = node_count(m_node, t);
697  if (n == INVALID_NODE && !throw_exception)
698  return 0;
699  else if (n != INVALID_NODE)
700  return n;
701  std::string msg = "Handle_t::numChildren: ";
702  if (m_node)
703  msg += "Element [" + tag() + "] has no children of type '" + _toString(t) + "'";
704  else
705  msg += "Element [INVALID] has no children of type '" + _toString(t) + "'";
706  throw std::runtime_error(msg);
707 }
708 
710 Handle_t Handle_t::child(const XmlChar* t, bool throw_exception) const {
711  Elt_t e = node_first(m_node, t);
712  if (e || !throw_exception)
713  return e;
714  std::string msg = "Handle_t::child: ";
715  if (m_node)
716  msg += "Element [" + tag() + "] has no child of type '" + _toString(t) + "'";
717  else
718  msg += "Element [INVALID]. Cannot remove child of type: '" + _toString(t) + "'";
719  throw std::runtime_error(msg);
720 }
721 
722 NodeList Handle_t::children(const XmlChar* tag_value) const {
723  return NodeList(m_node, tag_value);
724 }
725 
727 void Handle_t::append(Handle_t e) const {
728  _N(m_node)->appendChild(_N(e.ptr()));
729 }
730 
733 #ifdef DD4HEP_USE_TINYXML
734  bool e = (m_node && node.ptr() ? _N(m_node)->RemoveChild(_N(node.ptr())) : false);
735 #else
736  Elt_t e = Elt_t(m_node && node.ptr() ? _N(m_node)->removeChild(_N(node.ptr())) : 0);
737 #endif
738  if (e)
739  return node.ptr();
740  std::string msg = "Handle_t::remove: ";
741  if (m_node && node.ptr())
742  msg += "Element [" + tag() + "] has no child of type '" + node.tag() + "'";
743  else if (node)
744  msg += "Element [INVALID]. Cannot remove child of type: '" + node.tag() + "'";
745  else if (!node)
746  msg += "Element [INVALID]. Cannot remove [INVALID] child. Big Shit!!!!";
747 
748  throw std::runtime_error(msg);
749 }
750 
752 void Handle_t::removeChildren(const XmlChar* tag_value) const {
753 #ifdef DD4HEP_USE_TINYXML
754  for(TiXmlNode* n=_E(m_node)->FirstChildElement(tag_value);n;n=_E(m_node)->FirstChildElement(tag_value))
755  n->RemoveChild(n);
756 #else
757  xercesc::DOMElement* e = _E(m_node);
758  xercesc::DOMNodeList* l = e->getElementsByTagName(tag_value);
759  for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i)
760  e->removeChild(l->item(i));
761 #endif
762 }
763 
764 bool Handle_t::hasChild(const XmlChar* tag_value) const {
765  return node_first(m_node, tag_value) != 0;
766 }
767 
769 void Handle_t::setValue(const XmlChar* text_value) const {
770  _N(m_node)->setNodeValue(text_value);
771 }
772 
774 void Handle_t::setValue(const std::string& text_value) const {
775 #ifdef DD4HEP_USE_TINYXML
776  _N(m_node)->setNodeValue(text_value.c_str());
777 #else
778  _N(m_node)->setNodeValue(Strng_t(text_value));
779 #endif
780 }
781 
783 void Handle_t::setText(const XmlChar* text_value) const {
784 #ifdef DD4HEP_USE_TINYXML
785  _N(m_node)->LinkEndChild(new TiXmlText(text_value));
786 #else
787  _N(m_node)->setTextContent(text_value);
788 #endif
789 }
790 
792 void Handle_t::setText(const std::string& text_value) const {
793 #ifdef DD4HEP_USE_TINYXML
794  _N(m_node)->LinkEndChild(new TiXmlText(text_value.c_str()));
795 #else
796  _N(m_node)->setTextContent(Strng_t(text_value));
797 #endif
798 }
799 
801 void Handle_t::removeAttrs() const {
802 #ifdef DD4HEP_USE_TINYXML
803  _E(m_node)->ClearAttributes();
804 #else
805  xercesc::DOMElement* e = _E(m_node);
806  xercesc::DOMNamedNodeMap* l = e->getAttributes();
807  for (XmlSize_t i = 0, n = l->getLength(); i < n; ++i) {
808  xercesc::DOMAttr* a = (xercesc::DOMAttr*) l->item(i);
809  e->removeAttributeNode(a);
810  }
811 #endif
812 }
813 
815 #ifdef DD4HEP_USE_TINYXML
816 void Handle_t::setAttrs(Handle_t elt) const {
817  removeAttrs();
818  TiXmlElement* e = Xml(elt).e;
819  for(TiXmlAttribute* a=e->FirstAttribute(); a; a=a->Next())
820  e->SetAttribute(a->Name(),a->Value());
821 }
822 #else
823 void Handle_t::setAttrs(Handle_t /* elt */) const {
824  removeAttrs();
825  xercesc::DOMElement* e = _E(m_node);
826  xercesc::DOMNamedNodeMap* l = e->getAttributes();
827  for (XmlSize_t i = 0, len = l->getLength(); i < len; ++i) {
828  xercesc::DOMNode* n = l->item(i);
829  if (n->getNodeType() == xercesc::DOMNode::ATTRIBUTE_NODE) {
830  xercesc::DOMAttr* a = (xercesc::DOMAttr*) n;
831  e->setAttribute(a->getName(), a->getValue());
832  }
833  }
834 }
835 #endif
836 
839  Attribute a = attribute_node(m_node, t);
840  if (0 != a)
841  return a;
842  std::string msg = "Handle_t::attr_ptr: ";
843  if (m_node)
844  msg += "Element [" + tag() + "] has no attribute of type '" + _toString(t) + "'";
845  else
846  msg += "Element [INVALID] has no attribute of type '" + _toString(t) + "'";
847  throw std::runtime_error(msg);
848 }
849 
851 const XmlChar* Handle_t::attr_name(const Attribute a) const {
852  if (a) {
853  return Xml(a).a->getName();
854  }
855  throw std::runtime_error("Attempt to access invalid XML attribute object!");
856 }
857 
859 const XmlChar* Handle_t::attr_value(const XmlChar* attr_tag) const {
860  return attribute_value(attr_ptr(attr_tag));
861 }
862 
864 const XmlChar* Handle_t::attr_value(const Attribute attr_val) const {
865  return attribute_value(attr_val);
866 }
867 
869 const XmlChar* Handle_t::attr_value_nothrow(const XmlChar* attr_tag) const {
870  Attribute a = attr_nothrow(attr_tag);
871  return a ? attribute_value(a) : 0;
872 }
873 
875 Attribute Handle_t::setAttr(const XmlChar* nam, int val) const {
876  char txt[32];
877  ::snprintf(txt, sizeof(txt), "%d", val);
878  return setAttr(nam, Strng_t(txt));
879 }
880 
882 Attribute Handle_t::setAttr(const XmlChar* name, bool val) const {
883  char txt[32];
884  ::snprintf(txt, sizeof(txt), "%s", val ? "true" : "false");
885  return setAttr(name, Strng_t(txt));
886 }
887 
889 Attribute Handle_t::setAttr(const XmlChar* name, float val) const {
890  char txt[32];
891  ::snprintf(txt, sizeof(txt), "%.8e", val);
892  return setAttr(name, Strng_t(txt));
893 }
894 
896 Attribute Handle_t::setAttr(const XmlChar* name, double val) const {
897  char txt[32];
898  ::snprintf(txt, sizeof(txt), "%.8e", val);
899  return setAttr(name, Strng_t(txt));
900 }
901 
903 Attribute Handle_t::setAttr(const XmlChar* name, const std::string& val) const {
904  return setAttr(name, Strng_t(val.c_str()));
905 }
906 
907 #ifndef DD4HEP_USE_TINYXML
908 Attribute Handle_t::setAttr(const XmlChar* name, const char* v) const {
909  return setAttr(name, Strng_t(v));
910 }
911 #endif
912 
914 Attribute Handle_t::setAttr(const XmlChar* nam, const Attribute v) const {
915  return v ? setAttr(nam, attribute_value(v)) : 0;
916 }
917 
919 Attribute Handle_t::setAttr(const XmlChar* nam, const XmlChar* val) const {
920 #ifdef DD4HEP_USE_TINYXML
921  TiXmlElement* e = Xml(m_node).e;
922  e->SetAttribute(nam,val);
923  return Attribute(e->AttributeNode(nam));
924 #else
925  xercesc::DOMElement* e = _E(m_node);
926  xercesc::DOMAttr* a = e->getAttributeNode(nam);
927  if (!a) {
928  a = e->getOwnerDocument()->createAttribute(nam);
929  e->setAttributeNode(a);
930  }
931  a->setValue(val);
932  return Attribute(a);
933 #endif
934 }
935 
937 Handle_t Handle_t::setRef(const XmlChar* tag_value, const XmlChar* ref_name) {
938  Element me(*this);
939  Element ref(me.document(), tag_value);
940  ref.setAttr(Unicode_ref, ref_name);
941  me.append(ref);
942  return ref;
943 }
944 
946 Handle_t Handle_t::setRef(const XmlChar* tag_value, const std::string& ref_name) {
947  return setRef(tag_value, Strng_t(ref_name).ptr());
948 }
949 
951 static unsigned int adler32(unsigned int adler, const XmlChar* xml_buff, size_t len) {
952 #define DO1(buf,i) {s1 +=(unsigned char)buf[i]; s2 += s1;}
953 #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
954 #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
955 #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
956 #define DO16(buf) DO8(buf,0); DO8(buf,8);
957 
958  static const unsigned int BASE = 65521; /* largest prime smaller than 65536 */
959  /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
960  static const unsigned int NMAX = 5550;
961  unsigned int s1 = adler & 0xffff;
962  unsigned int s2 = (adler >> 16) & 0xffff;
963  const char* buf = (const char*)xml_buff;
964 
965  if (buf == NULL)
966  return 1;
967 
968  while (len > 0) {
969  int k = len < NMAX ? (int) len : NMAX;
970  len -= k;
971  while (k >= 16) {
972  DO16(buf);
973  buf += 16;
974  k -= 16;
975  }
976  if (k != 0)
977  do {
978  s1 += (unsigned char) *buf++;
979  s2 += s1;
980  } while (--k);
981  s1 %= BASE;
982  s2 %= BASE;
983  }
984  unsigned int result = (s2 << 16) | s1;
985  return result;
986 }
987 
989 typedef unsigned int (fcn_t)(unsigned int, const XmlChar*, size_t);
990 unsigned int Handle_t::checksum(unsigned int param, fcn_t fcn) const {
991 #ifdef DD4HEP_USE_TINYXML
992  typedef std::map<std::string, std::string> StringMap;
993  TiXmlNode* n = Xml(m_node).n;
994  if ( n ) {
995  if ( 0 == fcn ) fcn = adler32;
996  switch (n->Type()) {
997  case TiXmlNode::ELEMENT: {
998  std::map<std::string,std::string> m;
999  TiXmlElement* e = n->ToElement();
1001  for(; p; p=p->Next()) m.emplace(p->Name(),p->Value());
1002  param = (*fcn)(param,e->Value(),::strlen(e->Value()));
1003  for(StringMap::const_iterator i=m.begin();i!=m.end();++i) {
1004  param = (*fcn)(param,(*i).first.c_str(),(*i).first.length());
1005  param = (*fcn)(param,(*i).second.c_str(),(*i).second.length());
1006  }
1007  break;
1008  }
1009  case TiXmlNode::TEXT:
1010  param = (*fcn)(param,n->ToText()->Value(),::strlen(n->ToText()->Value()));
1011  break;
1012  case TiXmlNode::UNKNOWN:
1013  case TiXmlNode::COMMENT:
1014  case TiXmlNode::DOCUMENT:
1016  default:
1017  break;
1018  }
1019  for(TiXmlNode* c=n->FirstChild(); c; c=c->NextSibling())
1020  param = Handle_t((XmlElement*)c->ToElement()).checksum(param,fcn);
1021  }
1022 #else
1023  if ( 0 == fcn ) fcn = adler32;
1024  if ( 0 == fcn ) {
1025  }
1026 #endif
1027  return param;
1028 }
1029 
1031 Handle_t Document::createElt(const XmlChar* tag_value) const {
1032 #ifdef DD4HEP_USE_TINYXML
1033  return _XE(new TiXmlElement(tag_value));
1034 #else
1035  return _XE(_D(m_doc)->createElement(tag_value));
1036 #endif
1037 }
1038 
1041  if (m_doc)
1042  return _XE(_D(m_doc)->getDocumentElement());
1043  throw std::runtime_error("Document::root: Invalid handle!");
1044 }
1045 
1047 std::string Document::uri() const {
1048  if (m_doc) {
1049  Tag_t val(_D(m_doc)->getDocumentURI());
1050  return val;
1051  }
1052  throw std::runtime_error("Document::uri: Invalid handle!");
1053 }
1054 
1057  if (m_doc) {
1058  printout(DEBUG,"DocumentHolder","+++ Release DOM document....");
1059 #ifdef DD4HEP_USE_TINYXML
1060  delete _D(m_doc);
1061 #else
1062  _D(m_doc)->release();
1063 #endif
1064  }
1065  m_doc = d;
1066  return *this;
1067 }
1068 
1071  assign(0);
1072 }
1073 
1075 Element::Element(const Document& doc, const XmlChar* type)
1076  : m_element(Xml(doc.createElt(type)).xe) {
1077 }
1078 
1081  Handle_t p = m_element.parent();
1082  if ( p && _N(p.ptr())->getNodeType() == ELEMENT_NODE_TYPE ) {
1083  return Elt_t(p);
1084  }
1085  return Elt_t(0);
1086 }
1087 
1090  return Document((XmlDocument*) (m_element ? _N(m_element)->getOwnerDocument() : 0));
1091 }
1092 
1095  if (m_element && h) {
1096  return h.clone(Document::DOC(document()));
1097  }
1098  throw std::runtime_error("Element::clone: Invalid element pointer -- unable to clone node!");
1099 }
1100 
1101 Attribute Element::getAttr(const XmlChar* name) const {
1102  return m_element ? attribute_node(m_element, name) : 0;
1103 }
1104 
1106 Attribute Element::setRef(const XmlChar* tag_value, const XmlChar* ref_name) const {
1107  return setChild(tag_value).setAttr(Unicode_ref, ref_name);
1108 }
1109 
1111 Attribute Element::setRef(const XmlChar* tag_value, const std::string& ref_name) const {
1112  return setRef(tag_value, Strng_t(ref_name).ptr());
1113 }
1114 
1116 const XmlChar* Element::getRef(const XmlChar* tag_value) const {
1117  return child(tag_value).attr < cpXmlChar > (Unicode_ref);
1118 }
1119 
1121 Handle_t Element::addChild(const XmlChar* tag_value) const {
1122  Handle_t e = document().createElt(tag_value);
1123  m_element.append(e);
1124  return e;
1125 }
1126 
1129  Elt_t e = m_element.child(t, false);
1130  return e ? Handle_t(e) : addChild(t);
1131 }
1132 
1133 #ifndef DD4HEP_USE_TINYXML
1134 void Element::addComment(const XmlChar* text_value) const {
1136  _N(m_element)->appendChild(_D(document().m_doc)->createComment(text_value));
1137 }
1138 #endif
1139 
1141 void Element::addComment(const char* text_value) const {
1142 #ifdef DD4HEP_USE_TINYXML
1143  _N(m_element)->appendChild(new TiXmlComment(text_value));
1144 #else
1145  _N(m_element)->appendChild(_D(document().m_doc)->createComment(Strng_t(text_value)));
1146 #endif
1147 }
1148 
1150 void Element::addComment(const std::string& text_value) const {
1151  addComment(text_value.c_str());
1152 }
1153 
1155 RefElement::RefElement(const Document& doc, const XmlChar* typ, const XmlChar* nam)
1156  : Element(doc, typ) {
1157  m_name = nam ? setAttr(_U(name), nam) : 0;
1158 }
1159 
1162  : Element(e) {
1163  m_name = m_element ? getAttr(_U(name)) : 0;
1164 }
1165 
1168  : Element(e), m_name(e.m_name) {
1169 }
1170 
1173  m_element = e.m_element;
1174  return *this;
1175 }
1176 
1177 const XmlChar* RefElement::name() const {
1178  if (0 == m_name)
1179  std::cout << "Error:tag=" << m_element.tag() << std::endl;
1180  return attribute_value(m_name);
1181 }
1182 
1184  if (0 == m_name)
1185  std::cout << "Error:tag=" << m_element.tag() << std::endl;
1186  return attribute_value(m_name);
1187 }
1188 
1189 void RefElement::setName(const XmlChar* new_name) {
1190  setAttr(_U(name), new_name);
1191 }
1192 
1193 #ifndef DD4HEP_USE_TINYXML
1194 Collection_t::Collection_t(Handle_t element, const XmlChar* tag_value)
1195  : m_children(element, tag_value) {
1196  m_node = m_children.reset();
1197 }
1198 #endif
1199 
1200 Collection_t::Collection_t(Handle_t element, const char* tag_value)
1201  : m_children(element, Strng_t(tag_value)) {
1202  m_node = m_children.reset();
1203 }
1204 
1207  : m_children(node_list) {
1208  m_node = m_children.reset();
1209 }
1210 
1213  m_node = m_children.reset();
1214  return *this;
1215 }
1216 
1218 size_t Collection_t::size() const {
1219  return Handle_t(m_children.m_node).numChildren(m_children.m_tag, false);
1220 }
1221 
1224  if (m_node) {
1225  throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting XML nodes of type <" + tag() + "/>");
1226  }
1227  throw std::runtime_error(std::string(e.what()) + "\n" + "dd4hep: Error interpreting collections XML nodes.");
1228 }
1229 
1231  Elt_t e = this->parent();
1232  while (m_node) {
1233  m_node = m_children.next();
1234  if (m_node && _N(m_node)->getNodeType() == ELEMENT_NODE_TYPE) {
1235  if (this->parent() == e)
1236  return;
1237  }
1238  }
1239 }
1240 
1242  Elt_t e = this->parent();
1243  while (m_node) {
1245  if (m_node && _N(m_node)->getNodeType() == ELEMENT_NODE_TYPE) {
1246  if (this->parent() == e)
1247  return;
1248  }
1249  }
1250 }
1251 
1252 void Collection_t::operator++(int) const {
1253  ++(*this);
1254 }
1255 
1256 void Collection_t::operator--(int) const {
1257  --(*this);
1258 }
1259 
1261 #ifdef DD4HEP_USE_TINYXML
1262  return _XE(source.clone(0));
1263 #else
1264  return _XE(_D(m_doc)->importNode(_E(source.ptr()),true));
1265 #endif
1266 }
1267 
1268 #ifdef DD4HEP_USE_TINYXML
1269 #include "tinyxml_inl.h"
1270 #include "tinyxmlerror_inl.h"
1271 #include "tinyxmlparser_inl.h"
1272 #endif
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::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
TiXmlElement
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1069
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
TiXmlDocument
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1547
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::NodeList::next
XmlElement * next() const
Advance to next element.
Definition: XMLElements.cpp:587
DO16
#define DO16(buf)
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
_E
#define _E(x)
Definition: XMLElements.cpp:63
dd4hep::xml::_toDouble
double _toDouble(const XmlChar *value)
Conversion function from raw unicode string to double.
Definition: XMLElements.cpp:357
dd4hep::xml::RefElement::setName
void setName(const XmlChar *new_name)
Change/set the object's name.
Definition: XMLElements.cpp:1189
dd4hep::xml::cpXmlChar
const XmlChar * cpXmlChar
Definition: XMLElements.h:526
TiXmlNode::DECLARATION
@ DECLARATION
Definition: tinyxml.h:473
TiXmlNode::TEXT
@ TEXT
Definition: tinyxml.h:473
dd4hep::xml::Element::append
void append(Handle_t handle) const
Append a new element to the existing tree.
Definition: XMLElements.h:839
tinyxmlparser_inl.h
v
View * v
Definition: MultiView.cpp:28
dd4hep::xml::NodeList::operator=
NodeList & operator=(const NodeList &l)
Assignment operator.
Definition: XMLElements.cpp:621
ns
Helper structure to shortcut type definitions for the factories.
Definition: Factories.h:204
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
Xml::n
xercesc::DOMNode * n
Definition: XMLElements.cpp:131
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
tinyxml_inl.h
dd4hep::_toDictionary
void _toDictionary(const std::string &name, const std::string &value)
Enter name value pair to the dictionary. "value" must be a numerical expression, which is evaluated.
Definition: Handle.cpp:240
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
TiXmlNode::ELEMENT
@ ELEMENT
Definition: tinyxml.h:473
TiXmlNode::Type
int Type() const
Definition: tinyxml.h:758
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
Xml::e
xercesc::DOMElement * e
Definition: XMLElements.cpp:133
TiXmlNode::FirstChild
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
Definition: tinyxml.h:535
fcn_t
unsigned int() fcn_t(unsigned int, const XmlChar *, size_t)
Checksum (sub-)tree of a xml document/tree.
Definition: XMLElements.cpp:989
Xml::p
const void * p
Definition: XMLElements.cpp:130
TiXmlNode::ToElement
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:778
tinyxml.h
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::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
_D
#define _D(x)
Definition: XMLElements.cpp:62
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
dd4hep::xml::NodeList::reset
XmlElement * reset()
Reset the nodelist - e.g. restart iteration from beginning.
Definition: XMLElements.cpp:582
TiXmlAttribute::Value
const char * Value() const
Return the value of this attribute.
Definition: tinyxml.h:912
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::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::Element::Elt_t
Handle_t::Elt_t Elt_t
Simplification type declarations.
Definition: XMLElements.h:772
TiXmlNode::DOCUMENT
@ DOCUMENT
Definition: tinyxml.h:473
TiXmlComment
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1283
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
TiXmlElement::FirstAttribute
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
Definition: tinyxml.h:1193
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
Xml::l
xercesc::DOMNodeList * l
Definition: XMLElements.cpp:135
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
Xml::a
xercesc::DOMAttr * a
Definition: XMLElements.cpp:132
dd4hep::xml::Strng_t::m_xml
XmlChar * m_xml
Pointer to unicode string.
Definition: XMLElements.h:173
TiXmlAttribute
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:880
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
TiXmlNode::NextSiblingElement
const TiXmlElement * NextSiblingElement() const
Definition: tinyxml_inl.h:451
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::set_float_precision
int set_float_precision(int precision)
Change floating point precision on conversion to string.
Definition: XMLElements.cpp:222
dd4hep::_toInteger
std::pair< int, double > _toInteger(const std::string &value)
Definition: Handle.cpp:69
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
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
TiXmlElement::SetAttribute
void SetAttribute(const char *name, const char *_value)
Definition: tinyxml_inl.h:746
dd4hep::xml::RefElement::m_name
Attribute m_name
Attribute holding thre name.
Definition: XMLElements.h:956
ELEMENT_NODE_TYPE
#define ELEMENT_NODE_TYPE
Definition: XMLElements.cpp:123
_U
#define _U(a)
Definition: Tags.h:23
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::RefElement::name
const XmlChar * name() const
Access the object's name in unicode.
Definition: XMLElements.cpp:1177
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::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::_toFloatingPoint
std::pair< int, double > _toFloatingPoint(const std::string &value)
Definition: Handle.cpp:62
dd4hep::xml::_toString
std::string _toString(const Attribute attr)
Convert xml attribute to STL string.
Definition: XMLElements.cpp:234
TiXmlAttribute::Next
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
Definition: tinyxml_inl.h:1199
dd4hep::xml::XmlString::transcode
static XmlChar * transcode(const char *c)
Transcode string.
Definition: XMLElements.cpp:145
dd4hep::_getEnviron
std::string _getEnviron(const std::string &env)
Evaluate string constant using environment stored in the evaluator.
Definition: Handle.cpp:281
dd4hep::xml::Strng_t::operator=
Strng_t & operator=(const XmlChar *s)
Assignment opertor from unicode string.
Definition: XMLElements.cpp:487
TiXmlNode
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:434
Xml::xe
XmlElement * xe
Definition: XMLElements.cpp:136
dd4hep::xml::Strng_t
Helper class to encapsulate a unicode string.
Definition: XMLElements.h:170
Xml::d
xercesc::DOMDocument * d
Definition: XMLElements.cpp:134
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
TiXmlNode::UNKNOWN
@ UNKNOWN
Definition: tinyxml.h:473
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
TiXmlNode::FirstChildElement
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
Definition: tinyxml_inl.h:421
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::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
tinyxmlerror_inl.h
dd4hep::xml::Handle_t::m_node
Elt_t m_node
The pointer to the XmlElement.
Definition: XMLElements.h:386
Xml::Xml
Xml(const void *ptr)
Definition: XMLElements.cpp:127
dd4hep::xml::RefElement
User abstraction class to manipulate named XML elements (references) within a document.
Definition: XMLElements.h:953
dd4hep::xml::Strng_t::ptr
const XmlChar * ptr() const
Accessor to unicode string.
Definition: XMLElements.h:204
dd4hep::xml::_toULong
unsigned long _toULong(const XmlChar *value)
Conversion function from raw unicode string to unsigned long.
Definition: XMLElements.cpp:323
TiXmlNode::Value
const char * Value() const
Definition: tinyxml.h:490
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::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::_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
Xml
Union to ease castless object access when using XercesC.
Definition: XMLElements.cpp:126
XMLElements.h
dd4hep::xml::Element
User abstraction class to manipulate XML elements within a document.
Definition: XMLElements.h:769
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::_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
_XE
#define _XE(x)
Definition: XMLElements.cpp:66
dd4hep::xml::XmlSize_t
std::size_t XmlSize_t
Definition: config.h:47
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::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
TiXmlElement::AttributeNode
const TiXmlAttribute * AttributeNode(const char *name) const
Definition: tinyxml.h:1088
TiXmlAttribute::Name
const char * Name() const
Return the name of this attribute.
Definition: tinyxml.h:909
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
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
TiXmlNode::ToText
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
Definition: tinyxml.h:787
dd4hep::xml::Collection_t::operator++
void operator++() const
Operator to advance the collection (pre increment)
Definition: XMLElements.cpp:1230
XMLTags.h
TiXmlNode::NextSibling
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
Definition: tinyxml.h:666
dd4hep::xml::Handle_t::rawValue
const XmlChar * rawValue() const
Unicode text access to the element's value.
Definition: XMLElements.cpp:641
TiXmlNode::COMMENT
@ COMMENT
Definition: tinyxml.h:473
TiXmlText
TinyXML class. See http://www.grinninglizard.com/tinyxml.
Definition: tinyxml.h:1339
dd4hep::xml::Handle_t::attr
T attr(const Attribute a) const
Access typed attribute value by the XmlAttr.
Definition: XMLElements.h:454
_N
#define _N(x)
Definition: XMLElements.cpp:64
dd4hep::xml::_toBool
bool _toBool(const XmlChar *value)
Conversion function from raw unicode string to bool.
Definition: XMLElements.cpp:338
dd4hep::xml::Handle_t::ptr
Elt_t ptr() const
Direct access to the XmlElement by function.
Definition: XMLElements.h:401
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::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
Printout.h