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
std::map< std::string, std::vector< std::string > > AttrAccumType
Definition: DDXMLElement.h:46
virtual ~DDXMLElement(void)=default
Destructor.
std::string parentElement_
Definition: DDXMLElement.h:186
std::vector< DDXMLAttribute >::const_iterator & operator++(int inc)
Allow the elements of this type to be iterated over using ++ operator.
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
void appendText(const std::string &inText)
append to the current (i.e. most recently added)
void setParent(const std::string &pename)
Set parent element name to central list of names.
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
virtual void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
virtual bool gotText(void) const
gotText()? kind of like gotMilk? Yes = text has already been encountered.
void appendAttributes(std::vector< std::string > &tv, const std::string &name)
behind the scenes appending to pAttributes...
virtual bool isEmpty(void) const
Have any elements of this type been encountered but not processed?
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
virtual size_t size(void) const
Number of elements accumulated.
const std::string names[nVars_]
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
virtual void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Called by loadAttributes AFTER attributes are loaded.
Definition: DDXMLElement.cc:20
void loadText(const std::string &inText)
Used to load both text and XML comments into this object.
virtual void stream(std::ostream &os) const
Allow for the elements to have their own streaming method, but also provide a default.
void setSelf(const std::string &sename)
Set self element name to central list of names.
virtual std::vector< DDXMLAttribute >::const_iterator end(void)
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
std::vector< DDXMLAttribute >::const_iterator myIter_
Definition: DDXMLElement.h:184
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
std::vector< DDXMLAttribute > attributes_
Definition: DDXMLElement.h:180
friend std::ostream & operator<<(std::ostream &os, const DDXMLElement &element)
std::string myElement_
Definition: DDXMLElement.h:185
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.
AttrAccumType attributeAccumulator_
Definition: DDXMLElement.h:182
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
virtual std::vector< DDXMLAttribute >::const_iterator begin(void)
const std::string & parent(void) const
access to parent element name
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:40
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
virtual const std::string & getAttribute(const std::string &name) const
Access to attributes by name.
Definition: DDXMLElement.cc:47
DDXMLElement(DDLElementRegistry *myreg)
Constructor.
Definition: DDXMLElement.cc:14
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
const std::string getText(size_t tindex=0) const
retrieve the text blob.
std::vector< std::string > text_
Definition: DDXMLElement.h:181