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