CMS 3D CMS Logo

DDXMLElement.h
Go to the documentation of this file.
1 #ifndef DD_XMLElement_H
2 #define DD_XMLElement_H
3 
4 #include <cstddef>
5 #include <iosfwd>
6 #include <map>
7 #include <string>
8 #include <vector>
9 
13 
14 class DDCompactView;
15 class DDLElementRegistry;
16 
18 
45 typedef std::map<std::string, std::string> DDXMLAttribute;
46 typedef std::map<std::string, std::vector<std::string> > AttrAccumType;
47 
48 class DDXMLElement {
49  friend std::ostream& operator<<(std::ostream& os, const DDXMLElement& element);
50 
51 public:
54 
56  DDXMLElement(DDLElementRegistry* myreg, const bool& clearme);
57 
59  virtual ~DDXMLElement(void) = default; // inline
60 
62 
71  void loadAttributes(const std::string& elemName,
72  const std::vector<std::string>& names,
73  const std::vector<std::string>& values,
74  const std::string& nmspace,
75  DDCompactView& cpv);
76 
78 
86  void loadText(const std::string& inText);
87 
89  void appendText(const std::string& inText);
90 
92  const std::string getText(size_t tindex = 0) const;
93 
95  virtual bool gotText(void) const;
96 
98  virtual void clear(void);
99 
101  virtual const std::string& getAttribute(const std::string& name) const;
102 
104  virtual const DDXMLAttribute& getAttributeSet(size_t aIndex = 0) const;
105 
106  const virtual DDName getDDName(const std::string& defaultNS,
107  const std::string& attname = std::string("name"),
108  size_t aIndex = 0);
109 
110  /* /// Gets the value of the name part of an attribute of the form ns:name. */
111  /* const virtual std::string getName(const std::string& attname, size_t aIndex = 0); */
112 
113  /* /// Gets the namespace of an attribute of the form ns:name. */
114  /* virtual std::string getNameSpace(const std::string& defaultNS, const std::string& attname, size_t aIndex = 0); */
115 
117  virtual const std::string& get(const std::string& name, size_t aIndex = 0) const;
118 
120  virtual std::vector<std::string> getVectorAttribute(const std::string& name);
121 
123  virtual size_t size(void) const;
124 
125  virtual std::vector<DDXMLAttribute>::const_iterator begin(void);
126 
127  virtual std::vector<DDXMLAttribute>::const_iterator end(void);
128 
130  void setParent(const std::string& pename);
131 
133  void setSelf(const std::string& sename);
134 
136  const std::string& parent(void) const;
137 
139 
147  virtual void processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv);
148 
150 
158  virtual void preProcessElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv);
159 
161  virtual void stream(std::ostream& os) const;
162 
164  std::vector<DDXMLAttribute>::const_iterator& operator++(int inc);
165 
167  virtual bool isEmpty(void) const;
168 
170  void throwError(const std::string& keyMessage) const;
171 
172 protected:
174 
175 private:
177  void appendAttributes(std::vector<std::string>& tv, const std::string& name);
178 
179  std::vector<DDXMLAttribute>
180  attributes_; // std::vector of name-value std::map (i.e. multiple elements of the same type.
181  std::vector<std::string> text_; // accumulates text.. one per element of this type.
182  AttrAccumType attributeAccumulator_; // temporary holder for most recent accessed attributes_... remove later!
184  std::vector<DDXMLAttribute>::const_iterator myIter_;
187 };
188 
189 #endif
DDXMLElement::parent
const std::string & parent(void) const
access to parent element name
Definition: DDXMLElement.cc:201
DDXMLElement::clear
virtual void clear(void)
clear this element's contents.
Definition: DDXMLElement.cc:40
DDXMLElement::myElement_
std::string myElement_
Definition: DDXMLElement.h:185
DDXMLElement::operator<<
friend std::ostream & operator<<(std::ostream &os, const DDXMLElement &element)
Definition: DDXMLElement.cc:159
DDXMLElement::getVectorAttribute
virtual std::vector< std::string > getVectorAttribute(const std::string &name)
Returns a set of values as a std::vector of strings, given the attribute name.
Definition: DDXMLElement.cc:104
DDXMLElement::throwError
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
Definition: DDXMLElement.cc:209
AttrAccumType
std::map< std::string, std::vector< std::string > > AttrAccumType
Definition: DDXMLElement.h:46
DDName
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
DDXMLElement::~DDXMLElement
virtual ~DDXMLElement(void)=default
Destructor.
DDXMLElement::stream
virtual void stream(std::ostream &os) const
Allow for the elements to have their own streaming method, but also provide a default.
Definition: DDXMLElement.cc:164
DDLElementRegistry
The main class for processing parsed elements.
Definition: DDLElementRegistry.h:23
DDXMLElement::end
virtual std::vector< DDXMLAttribute >::const_iterator end(void)
Definition: DDXMLElement.cc:191
DDXMLElement::loadAttributes
void loadAttributes(const std::string &elemName, const std::vector< std::string > &names, const std::vector< std::string > &values, const std::string &nmspace, DDCompactView &cpv)
Load the element attributes.
Definition: DDXMLElement.cc:23
DDXMLElement::operator++
std::vector< DDXMLAttribute >::const_iterator & operator++(int inc)
Allow the elements of this type to be iterated over using ++ operator.
Definition: DDXMLElement.cc:196
DDXMLElement::attributes_
std::vector< DDXMLAttribute > attributes_
Definition: DDXMLElement.h:180
DDCompactView.h
DDXMLElement::getAttributeSet
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
DDXMLElement::appendText
void appendText(const std::string &inText)
append to the current (i.e. most recently added)
Definition: DDXMLElement.cc:134
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDXMLElement::DDXMLElement
DDXMLElement(DDLElementRegistry *myreg)
Constructor.
Definition: DDXMLElement.cc:14
DDXMLElement::processElement
virtual void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
Definition: DDXMLElement.cc:126
DDXMLElement::getAttribute
virtual const std::string & getAttribute(const std::string &name) const
Access to attributes by name.
Definition: DDXMLElement.cc:47
DDXMLElement::parentElement_
std::string parentElement_
Definition: DDXMLElement.h:186
DDXMLElement::appendAttributes
void appendAttributes(std::vector< std::string > &tv, const std::string &name)
behind the scenes appending to pAttributes...
Definition: DDXMLElement.cc:173
DDXMLElement::attributeAccumulator_
AttrAccumType attributeAccumulator_
Definition: DDXMLElement.h:182
DDXMLAttribute
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDXMLElement::preProcessElement
virtual void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Called by loadAttributes AFTER attributes are loaded.
Definition: DDXMLElement.cc:20
DDXMLElement::autoClear_
bool autoClear_
Definition: DDXMLElement.h:183
DDXMLElement::loadText
void loadText(const std::string &inText)
Used to load both text and XML comments into this object.
Definition: DDXMLElement.cc:132
DDXMLElement::setSelf
void setSelf(const std::string &sename)
Set self element name to central list of names.
Definition: DDXMLElement.cc:205
DDXMLElement::get
virtual const std::string & get(const std::string &name, size_t aIndex=0) const
Returns a specific value from the aIndex set of attributes.
Definition: DDXMLElement.cc:85
DDXMLElement
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DDXMLElement::setParent
void setParent(const std::string &pename)
Set parent element name to central list of names.
Definition: DDXMLElement.cc:203
DDXMLElement::begin
virtual std::vector< DDXMLAttribute >::const_iterator begin(void)
Definition: DDXMLElement.cc:186
DDLElementRegistry.h
DDXMLElement::isEmpty
virtual bool isEmpty(void) const
Have any elements of this type been encountered but not processed?
Definition: DDXMLElement.cc:207
DDXMLElement::getDDName
const virtual DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
DDXMLElement::gotText
virtual bool gotText(void) const
gotText()? kind of like gotMilk? Yes = text has already been encountered.
Definition: DDXMLElement.cc:153
DDXMLElement::getText
const std::string getText(size_t tindex=0) const
retrieve the text blob.
Definition: DDXMLElement.cc:145
DDXMLElement::text_
std::vector< std::string > text_
Definition: DDXMLElement.h:181
DDName.h
DDXMLElement::size
virtual size_t size(void) const
Number of elements accumulated.
Definition: DDXMLElement.cc:184
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DDXMLElement::myRegistry_
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
DDXMLElement::myIter_
std::vector< DDXMLAttribute >::const_iterator myIter_
Definition: DDXMLElement.h:184