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