ATLAS Offline Software
DOMNode.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 #include <map>
15 
16 #include "DOMNode.h"
17 
18 CoreParser::DOMNode::DOMNode () : m_type (DOCUMENT_NODE), m_parent (0)
19 {
20 }
21 
23  m_type (type), m_name (name), m_parent (parent)
24 {
25  if (parent != 0)
26  {
27  parent->m_siblings.push_back (this);
28  }
29 
30  if (type == COMMENT_NODE)
31  {
32  m_value = name;
33  m_name = "";
34  }
35 }
36 
37 CoreParser::DOMNode::DOMNode (NodeType type, const std::string& name, const std::string& value, DOMNode* parent) :
38  m_type (type), m_name (name), m_value (value), m_parent (parent)
39 {
40  if (parent != 0)
41  {
42  parent->m_siblings.push_back (this);
43  }
44 
45  if (type == COMMENT_NODE)
46  {
47  m_value = name;
48  m_name = "";
49  }
50 }
51 
53 {
55 
56  for (sit = m_siblings.begin (); sit != m_siblings.end (); ++sit)
57  {
58  const DOMNode* n = *sit;
59 
60  delete n;
61  }
62 }
63 
65 {
66  return (m_type);
67 }
68 
70 {
71  return (m_attributes);
72 }
73 
74 const std::string& CoreParser::DOMNode::get_name () const
75 {
76  return (m_name);
77 }
78 
79 const std::string& CoreParser::DOMNode::get_value () const
80 {
81  return (m_value);
82 }
83 
85 {
86  return (m_siblings);
87 }
88 
90 {
91  return (m_siblings.size ());
92 }
93 
95 {
96  m_it = m_siblings.begin ();
97  if (m_it == m_siblings.end ()) return (0);
98  return (*m_it);
99 }
100 
102 {
103  if (m_it == m_siblings.end ()) return (0);
104  ++m_it;
105  if (m_it == m_siblings.end ()) return (0);
106  return (*m_it);
107 }
108 
109 void CoreParser::DOMNode::print (const std::string& header,
110  int depth /*= 0*/) const
111 {
112  if (header != "")
113  {
114  std::cout << header << std::endl;
115  }
116 
117  int i;
118 
119  if (m_type == COMMENT_NODE)
120  {
121  for (i = 0; i < depth; i++) std::cout << " ";
122  std::cout << "<!--" << m_value << "-->" << std::endl;
123  }
124  /*
125  else if (m_type == DOCUMENT_NODE)
126  {
127  }
128  */
129  else
130  {
131  for (i = 0; i < depth; i++) std::cout << " ";
132  std::cout << "<" << m_name;
133 
134  std::map <std::string, std::string>::const_iterator ait;
135 
136  for (ait = m_attributes.begin (); ait != m_attributes.end (); ++ait)
137  {
138  const std::string& n = (*ait).first;
139  const std::string& v = (*ait).second;
140 
141  std::cout << " " << n << "='" << v << "'";
142  }
143 
144  std::cout << ">" << std::endl;
145 
146  DOMSiblings::const_iterator sit;
147 
148  for (sit = m_siblings.begin (); sit != m_siblings.end (); ++sit)
149  {
150  const DOMNode* n = *sit;
151 
152  n->print ("", depth+1);
153  }
154 
155  for (i = 0; i < depth; i++) std::cout << " ";
156  std::cout << "</" << m_name << ">" << std::endl;
157  }
158 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CoreParser::DOMNode::get_type
NodeType get_type() const
Definition: DOMNode.cxx:64
egammaParameters::depth
@ depth
pointing depth of the shower as calculated in egammaqgcld
Definition: egammaParamDefs.h:276
header
Definition: hcg.cxx:526
CoreParser::DOMSiblings
std::vector< DOMNode * > DOMSiblings
Definition: DOMNode.h:18
CoreParser::DOMNode::get_siblings
const DOMSiblings & get_siblings() const
Definition: DOMNode.cxx:84
CoreParser::DOMNamedNodeMap
std::map< std::string, std::string > DOMNamedNodeMap
Definition: DOMNode.h:15
athena.value
value
Definition: athena.py:122
CoreParser::DOMNode
Definition: DOMNode.h:21
CoreParser::DOMNode::DOMNode
DOMNode()
Definition: DOMNode.cxx:18
CoreParser::DOMNode::sibling_number
unsigned int sibling_number() const
Definition: DOMNode.cxx:89
CoreParser::DOMNode::get_first_child
DOMNode * get_first_child()
Definition: DOMNode.cxx:94
DOMNode.h
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
CoreParser::DOMNode::COMMENT_NODE
@ COMMENT_NODE
Definition: DOMNode.h:27
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
CoreParser::DOMNode::~DOMNode
~DOMNode()
Definition: DOMNode.cxx:52
CoreParser::DOMNode::get_value
const std::string & get_value() const
Definition: DOMNode.cxx:79
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CoreParser::DOMNode::m_value
std::string m_value
Definition: DOMNode.h:48
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CoreParser::DOMNode::m_name
std::string m_name
Definition: DOMNode.h:47
CoreParser::DOMNode::get_attributes
const DOMNamedNodeMap & get_attributes() const
Definition: DOMNode.cxx:69
python.PyAthena.v
v
Definition: PyAthena.py:157
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
CoreParser::DOMNode::get_next_sibling
DOMNode * get_next_sibling()
Definition: DOMNode.cxx:101
CoreParser::DOMNode::NodeType
NodeType
Definition: DOMNode.h:24
CoreParser::DOMNode::print
void print(const std::string &header="", int depth=0) const
Definition: DOMNode.cxx:109
CoreParser::DOMNode::get_name
const std::string & get_name() const
Definition: DOMNode.cxx:74