ATLAS Offline Software
Loading...
Searching...
No Matches
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
21
22CoreParser::DOMNode::DOMNode (NodeType type, const std::string& name, DOMNode* parent) :
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
37CoreParser::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{
54 DOMSiblings::iterator sit;
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
68
73
74const std::string& CoreParser::DOMNode::get_name () const
75{
76 return (m_name);
77}
78
79const std::string& CoreParser::DOMNode::get_value () const
80{
81 return (m_value);
82}
83
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
109void 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}
DOMNamedNodeMap m_attributes
Definition DOMNode.h:48
void print(const std::string &header="", int depth=0) const
Definition DOMNode.cxx:109
DOMSiblings m_siblings
Definition DOMNode.h:49
const DOMNamedNodeMap & get_attributes() const
Definition DOMNode.cxx:69
unsigned int sibling_number() const
Definition DOMNode.cxx:89
std::string m_value
Definition DOMNode.h:47
const DOMSiblings & get_siblings() const
Definition DOMNode.cxx:84
std::string m_name
Definition DOMNode.h:46
DOMNode * m_parent
Definition DOMNode.h:51
DOMSiblings::iterator m_it
Definition DOMNode.h:50
NodeType get_type() const
Definition DOMNode.cxx:64
NodeType m_type
Definition DOMNode.h:45
const std::string & get_name() const
Definition DOMNode.cxx:74
DOMNode * get_next_sibling()
Definition DOMNode.cxx:101
DOMNode * get_first_child()
Definition DOMNode.cxx:94
const std::string & get_value() const
Definition DOMNode.cxx:79
std::string depth
tag string for intendation
Definition fastadd.cxx:46
std::vector< DOMNode * > DOMSiblings
Definition DOMNode.h:17
std::map< std::string, std::string > DOMNamedNodeMap
Definition DOMNode.h:16