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 
49 {
50  friend std::ostream & operator<<(std::ostream & os, const DDXMLElement & element);
51 
52 public:
53 
56 
58  DDXMLElement( DDLElementRegistry* myreg, const bool& clearme );
59 
61  virtual ~DDXMLElement( void ) = default; // inline
62 
64 
73  void loadAttributes(const std::string& elemName,
74  const std::vector<std::string> & names,
75  const std::vector<std::string> & values,
76  const std::string& nmspace, DDCompactView& cpv );
77 
79 
87  void loadText( const std::string& inText );
88 
90  void appendText( const std::string& inText );
91 
93  const std::string getText( size_t tindex = 0 ) const;
94 
96  virtual bool gotText( void ) const;
97 
99  virtual void clear( void );
100 
102  virtual const std::string & getAttribute( const std::string& name ) const;
103 
105  virtual const DDXMLAttribute& getAttributeSet( size_t aIndex = 0 ) const;
106 
107  const virtual DDName getDDName( const std::string& defaultNS, const std::string& attname = std::string( "name" ), size_t aIndex = 0 );
108 
109  /* /// Gets the value of the name part of an attribute of the form ns:name. */
110  /* const virtual std::string getName(const std::string& attname, size_t aIndex = 0); */
111 
112  /* /// Gets the namespace of an attribute of the form ns:name. */
113  /* virtual std::string getNameSpace(const std::string& defaultNS, const std::string& attname, size_t aIndex = 0); */
114 
116  virtual const std::string & get( const std::string& name, size_t aIndex = 0 ) const;
117 
119  virtual std::vector<std::string> getVectorAttribute( const std::string& name );
120 
122  virtual size_t size( void ) const;
123 
124  virtual std::vector<DDXMLAttribute>::const_iterator begin( void );
125 
126  virtual std::vector<DDXMLAttribute>::const_iterator end( void );
127 
129  void setParent( const std::string& pename );
130 
132  void setSelf( const std::string& sename );
133 
135  const std::string& parent( void ) const;
136 
138 
146  virtual void processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv );
147 
149 
157  virtual void preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv );
158 
160  virtual void stream( std::ostream & os ) const;
161 
163  std::vector<DDXMLAttribute>::const_iterator& operator++( int inc );
164 
166  virtual bool isEmpty( void ) const;
167 
169  void throwError( const std::string& keyMessage ) const;
170 
171 protected:
173 
174 private:
176  void appendAttributes( std::vector<std::string> & tv, const std::string& name );
177 
178  std::vector<DDXMLAttribute> attributes_; // std::vector of name-value std::map (i.e. multiple elements of the same type.
179  std::vector<std::string> text_; // accumulates text.. one per element of this type.
180  AttrAccumType attributeAccumulator_; // temporary holder for most recent accessed attributes_... remove later!
182  std::vector<DDXMLAttribute>::const_iterator myIter_;
185 };
186 
187 #endif
virtual bool isEmpty(void) const
Have any elements of this type been encountered but not processed?
std::map< std::string, std::vector< std::string > > AttrAccumType
Definition: DDXMLElement.h:46
virtual ~DDXMLElement(void)=default
Destructor.
std::string parentElement_
Definition: DDXMLElement.h:184
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:172
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.
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:72
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
virtual void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
const std::string & parent(void) const
access to parent element name
void appendAttributes(std::vector< std::string > &tv, const std::string &name)
behind the scenes appending to pAttributes...
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
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:30
void loadText(const std::string &inText)
Used to load both text and XML comments into this object.
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:35
virtual size_t size(void) const
Number of elements accumulated.
std::vector< DDXMLAttribute >::const_iterator myIter_
Definition: DDXMLElement.h:182
std::vector< DDXMLAttribute > attributes_
Definition: DDXMLElement.h:178
friend std::ostream & operator<<(std::ostream &os, const DDXMLElement &element)
std::string myElement_
Definition: DDXMLElement.h:183
virtual bool gotText(void) const
gotText()? kind of like gotMilk? Yes = text has already been encountered.
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:180
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
virtual const std::string & getAttribute(const std::string &name) const
Access to attributes by name.
Definition: DDXMLElement.cc:63
virtual std::vector< DDXMLAttribute >::const_iterator begin(void)
virtual void stream(std::ostream &os) const
Allow for the elements to have their own streaming method, but also provide a default.
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:54
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:79
const std::string getText(size_t tindex=0) const
retrieve the text blob.
std::vector< std::string > text_
Definition: DDXMLElement.h:179