CMS 3D CMS Logo

DDLSAX2FileHandler.cc
Go to the documentation of this file.
6 
7 using namespace cms::xerces;
8 
9 class DDCompactView;
10 
11 // XERCES_CPP_NAMESPACE_USE
12 
14  : cpv_(cpv), registry_{reg}
15 {
16  init();
17 }
18 
19 void
21 {
22  namesMap_.emplace_back("*** root ***");
23  names_.emplace_back(namesMap_.size() - 1);
24 }
25 
27 {}
28 
29 void
30 DDLSAX2FileHandler::startElement( const XMLCh* const uri,
31  const XMLCh* const localname,
32  const XMLCh* const qname,
33  const Attributes& attrs )
34 {
35  std::string myElementName(cStr(qname).ptr());
36  size_t i = 0;
37  for (; i < namesMap_.size(); ++i) {
38  if ( myElementName == namesMap_.at(i) ) {
39  names_.emplace_back(i);
40  break;
41  }
42  }
43  if (i >= namesMap_.size()) {
44  namesMap_.emplace_back(myElementName);
45  names_.emplace_back(namesMap_.size() - 1);
46  }
47 
48  auto myElement = registry_.getElement(myElementName);
49 
50  unsigned int numAtts = attrs.getLength();
51  std::vector<std::string> attrNames, attrValues;
52 
53  for (unsigned int i = 0; i < numAtts; ++i)
54  {
55  attrNames.emplace_back(std::string(cStr(attrs.getLocalName(i)).ptr()));
56  attrValues.emplace_back(std::string(cStr(attrs.getValue(i)).ptr()));
57  }
58 
59  myElement->loadAttributes(myElementName, attrNames, attrValues, nmspace_, cpv_);
60  // initialize text
61  myElement->loadText(std::string());
62 }
63 
64 void
65 DDLSAX2FileHandler::endElement( const XMLCh* const uri,
66  const XMLCh* const localname,
67  const XMLCh* const qname )
68 {
69  std::string ts(cStr(qname).ptr());
70  const std::string& myElementName = self();
71 
72  auto myElement = registry_.getElement(myElementName);
73 
74  std::string nmspace = nmspace_;
75  // The need for processElement to have the nmspace so that it can
76  // do the necessary gymnastics made things more complicated in the
77  // effort to allow fully user-controlled namespaces. So the "magic"
78  // trick of setting nmspace to "!" is used :(... I don't like this magic trick
79  // -- Michael Case 2008-11-06
80  // OPTIMISE in the near future, like the current nmspace_ impl.
81  // just set nmspace_ to "!" from Parser based on userNS_ so
82  // userNS_ is set by parser ONCE and no if nec. here. MEC: 2009-06-22
83  if ( userNS_ ) {
84  nmspace = "!";
85  }
86 
87  DDCurrentNamespace::ns() = nmspace;
88  // tell the element it's parent name for recording/reporting purposes
89  myElement->setParent(parent());
90  myElement->setSelf(self());
91  myElement->processElement(myElementName, nmspace, cpv_);
92 
93  names_.pop_back();
94 }
95 
96 void
97 DDLSAX2FileHandler::characters( const XMLCh* const chars,
98  const XMLSize_t length )
99 {
100  auto myElement = registry_.getElement(self());
101  std::string inString = "";
102  for (XMLSize_t i = 0; i < length; ++i)
103  {
104  char s = chars[i];
105  inString = inString + s;
106  }
107  if (myElement->gotText())
108  myElement->appendText(inString);
109  else
110  myElement->loadText(inString);
111 }
112 
113 void
114 DDLSAX2FileHandler::comment( const XMLCh* const chars,
115  const XMLSize_t length )
116 {}
117 
118 void
120 {
122 }
123 
124 const std::string&
126 {
127  if (names_.size() > 2)
128  {
129  return namesMap_.at(names_.at(names_.size() - 2));
130  }
131  return namesMap_[0];//.at(names_.at(0));
132 }
133 
134 const std::string&
136 {
137  if (names_.size() > 1) {
138  return namesMap_.at(names_.at(names_.size() - 1));
139  }
140  return namesMap_[0];//.at(names_.at(0));
141 }
virtual const std::string & parent() const
void comment(const XMLCh *chars, XMLSize_t length) override
virtual const std::string & self() const
static std::string & ns()
std::vector< std::string > namesMap_
DDLElementRegistry & registry_
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
ClhepEvaluator & evaluator()
~DDLSAX2FileHandler() override
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
ZStr< char > cStr(XMLCh const *str)
std::string nmspace_
static void createConstantsFromEvaluator(ClhepEvaluator &)
creates all DDConstants from the variables of the ClhepEvaluator
Definition: DDConstant.cc:40
std::vector< size_t > names_
DDCompactView & cpv_
void endElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname) override
XERCES_CPP_NAMESPACE::Attributes Attributes
The main class for processing parsed elements.
void startElement(const XMLCh *uri, const XMLCh *localname, const XMLCh *qname, const Attributes &attrs) override
DDLSAX2FileHandler(DDCompactView &cpv, DDLElementRegistry &)
void characters(const XMLCh *chars, XMLSize_t length) override
void createDDConstants() const
creates all DDConstant from the evaluator which has been already &#39;filled&#39; in the first scan of the do...