ATLAS Offline Software
Loading...
Searching...
No Matches
TBXMLWriterToolBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
7
8#include <iostream>
9
11// XML writer implementation //
13
14const std::string TBXMLWriterToolBase::m_doubleQuote = "\042";
15
16// dictionary
17void
19 const std::string& dictName,
20 const std::vector<std::string>&
21 listOfElements)
22{
23 // clean up
24 m_elementList.clear();
25 m_dictionary = dictName;
26
27 // write header
28 outStream << "<?XML version=" << m_doubleQuote
29 << "1" << m_doubleQuote << "?>" << std::endl;
30
31 // write begin of dictionary
32 outStream << "<!DOCTYPE " << dictName
33 << " [" << std::endl;
34
35 // add doctype as element
36 this->addDictElement(outStream,dictName,listOfElements);
37}
38
39// template <typename DATA>
40void
42 const std::string& dictName)
43{
44 std::vector<std::string> emptyList;
45 this->openDictionary(outStream,dictName, emptyList);
46}
47
48// template <typename DATA>
49void
51{
52 outStream << "]>" << std::endl;
53}
54
55//template <typename DATA>
56void
58 const std::string& theElement,
59 const std::vector<std::string>&
60 listOfElements)
61{
62 outStream << "<!ELEMENT " << theElement;
63 // add document as element
64 if ( listOfElements.size() == 0 )
65 {
66 outStream << ">" << std::endl;
67 }
68 else
69 {
70 // store elements
71 if ( listOfElements[0] == "ANY" ||
72 listOfElements[0] == "EMPTY" ||
73 listOfElements[0] == "ALL" )
74 {
75 outStream << " " << listOfElements[0] << " >" << std::endl;
76 }
77 else
78 {
79 outStream << " (" << listOfElements[0];
80 for ( unsigned int i=1; i<listOfElements.size(); i++ )
81 {
82 outStream << "," << listOfElements[i];
83 }
84 outStream << ") >" << std::endl;
85 }
86 }
87}
88
89// template <typename DATA>
90void
91TBXMLWriterToolBase::addAttributes(std::ostream& outStream,
92 const std::string& theElement,
93 const std::vector<std::string>&
94 listOfAttr)
95{
96 outStream << " <!ATTLIST " << theElement << std::endl;
97 for ( unsigned int i=0; i<listOfAttr.size(); i++ )
98 {
99 outStream << " " << listOfAttr[i] << std::endl;
100 }
101 outStream << ">" << std::endl;
102}
103
104// template <typename DATA>
105void
106TBXMLWriterToolBase::openElement(std::ostream& outStream,
107 std::string_view theElement,
108 const std::vector<std::string>&
109 listOfAttr,
110 const std::vector<std::string>&
111 listOfValues)
112{
113 m_elementList.emplace_back(theElement);
114 outStream << "<" << theElement;
115 if ( listOfAttr.size() > 0 && listOfValues.size() == listOfAttr.size() )
116 {
117 for ( unsigned int i=0; i<listOfAttr.size(); i++ )
118 {
119 outStream << " " << listOfAttr[i] << "="
120 << m_doubleQuote
121 << listOfValues[i]
122 << m_doubleQuote;
123 }
124 }
125 outStream << ">" << std::endl;
126}
127
128// template <typename DATA>
129void
130TBXMLWriterToolBase::closeElement(std::ostream& outStream)
131{
132 unsigned int thisSize = m_elementList.size() - 1;
133 outStream << "</" << m_elementList[thisSize] << ">" << std::endl;
134 m_elementList.resize(thisSize);
135}
136
137// template <typename DATA>
138void
139TBXMLWriterToolBase::closeElement(std::ostream& outStream,
140 const std::string& theElement)
141{
142 std::vector<std::string>::iterator inVec =
143 find( m_elementList.begin(), m_elementList.end(), theElement);
144 if ( inVec != m_elementList.end() )
145 {
146 outStream << "</" << (*inVec) << ">" << std::endl;
147 m_elementList.erase(inVec);
148 }
149 else
150 {
151 outStream << "<!-- XML Structural Problem! \n\n"
152 << " cannot find an element " << theElement << "!\n\n"
153 << "-->" << std::endl;
154 }
155}
156
157// template <typename DATA>
158void
160{
161 for ( int i=m_elementList.size()-1; i>=0; i-- )
162 {
163 outStream << "</" << m_elementList[i] << ">" << std::endl;
164 }
165 m_elementList.clear();
166}
167
virtual void closeAllElements(std::ostream &outStream)
virtual void openDictionary(std::ostream &outStream, const std::string &dictName, const std::vector< std::string > &listOfElements)
std::vector< std::string > m_elementList
virtual void closeElement(std::ostream &outStream, const std::string &theElement)
virtual void addDictElement(std::ostream &outStream, const std::string &theElement, const std::vector< std::string > &listOfElements)
virtual void closeDictionary(std::ostream &outStream)
virtual void openElement(std::ostream &outStream, std::string_view theElement, const std::vector< std::string > &listOfAttr, const std::vector< std::string > &listOfValues)
static const std::string m_doubleQuote
virtual void addAttributes(std::ostream &outStream, const std::string &theElement, const std::vector< std::string > &listOfAttributes)
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140