CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDXMLElement.h
Go to the documentation of this file.
1 #ifndef DD_XMLElement_H
2 #define DD_XMLElement_H
3 /***************************************************************************
4  DDXMLElement.h - description
5  -------------------
6  begin : Fri Mar 15 2002
7  email : case@ucdhep.ucdavis.edu
8  ***************************************************************************/
9 
10 // -------------------------------------------------------------------------
11 // Includes
12 // -------------------------------------------------------------------------
13 
14 #include <map>
15 #include <string>
16 #include <vector>
17 
20 
22 
23 // -------------------------------------------------------------------------
24 // Class declaration
25 // -------------------------------------------------------------------------
26 
28 
55 typedef std::map <std::string, std::string> DDXMLAttribute;
56 typedef std::map <std::string, std::vector<std::string> > AttrAccumType;
57 
59 {
60  friend std::ostream & operator<<(std::ostream & os, const DDXMLElement & element);
61 
62 public:
63 
66 
68  DDXMLElement( DDLElementRegistry* myreg, const bool& clearme );
69 
71  virtual ~DDXMLElement( void );
72 
74 
83  void loadAttributes(const std::string& elemName,
84  const std::vector<std::string> & names,
85  const std::vector<std::string> & values,
86  const std::string& nmspace, DDCompactView& cpv );
87 
89 
97  void loadText( const std::string& inText );
98 
100  void appendText( const std::string& inText );
101 
103  const std::string getText( size_t tindex = 0 ) const;
104 
106  virtual bool gotText( void ) const;
107 
109  virtual void clear( void );
110 
112  virtual const std::string & getAttribute( const std::string& name ) const;
113 
115  virtual const DDXMLAttribute& getAttributeSet( size_t aIndex = 0 ) const;
116 
117  const virtual DDName getDDName( const std::string& defaultNS, const std::string& attname = std::string( "name" ), size_t aIndex = 0 );
118 
119  /* /// Gets the value of the name part of an attribute of the form ns:name. */
120  /* const virtual std::string getName(const std::string& attname, size_t aIndex = 0); */
121 
122  /* /// Gets the namespace of an attribute of the form ns:name. */
123  /* virtual std::string getNameSpace(const std::string& defaultNS, const std::string& attname, size_t aIndex = 0); */
124 
126  virtual const std::string & get( const std::string& name, size_t aIndex = 0 ) const;
127 
129  virtual std::vector<std::string> getVectorAttribute( const std::string& name );
130 
132  virtual size_t size( void ) const;
133 
134  virtual std::vector<DDXMLAttribute>::const_iterator begin( void );
135 
136  virtual std::vector<DDXMLAttribute>::const_iterator end( void );
137 
139  void setParent( const std::string& pename );
140 
142  void setSelf( const std::string& sename );
143 
145  const std::string& parent( void ) const;
146 
148 
156  virtual void processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv );
157 
159 
167  virtual void preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv );
168 
170  virtual void stream( std::ostream & os ) const;
171 
173  std::vector<DDXMLAttribute>::const_iterator& operator++( int inc );
174 
176  virtual bool isEmpty( void ) const;
177 
179  void throwError( const std::string& keyMessage ) const;
180 
181  // protected:
183  static std::string itostr( int i );
184 
185 protected:
187 
188 private:
190  void appendAttributes( std::vector<std::string> & tv, const std::string& name );
191 
192  std::vector<DDXMLAttribute> attributes_; // std::vector of name-value std::map (i.e. multiple elements of the same type.
193  std::vector<std::string> text_; // accumulates text.. one per element of this type.
194  AttrAccumType attributeAccumulator_; // temporary holder for most recent accessed attributes_... remove later!
196  std::vector<DDXMLAttribute>::const_iterator myIter_;
199 };
200 
201 #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:56
int i
Definition: DBlmapReader.cc:9
std::string parentElement_
Definition: DDXMLElement.h:198
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:186
static const HistoName names[]
static std::string itostr(int i)
WARNING: abused by other classes in this system: yet another conversion from int to std::string...
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 &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:79
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:18
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...
type of data representation of DDCompactView
Definition: DDCompactView.h:76
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:55
virtual void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Called by loadAttributes AFTER attributes are loaded.
Definition: DDXMLElement.cc:34
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:41
virtual size_t size(void) const
Number of elements accumulated.
std::vector< DDXMLAttribute >::const_iterator myIter_
Definition: DDXMLElement.h:196
std::vector< DDXMLAttribute > attributes_
Definition: DDXMLElement.h:192
friend std::ostream & operator<<(std::ostream &os, const DDXMLElement &element)
std::string myElement_
Definition: DDXMLElement.h:197
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:194
virtual ~DDXMLElement(void)
Destructor.
Definition: DDXMLElement.cc:29
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
virtual const std::string & getAttribute(const std::string &name) const
Access to attributes by name.
Definition: DDXMLElement.cc:70
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:61
DDXMLElement(DDLElementRegistry *myreg)
Constructor.
Definition: DDXMLElement.cc:15
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:86
const std::string getText(size_t tindex=0) const
retrieve the text blob.
std::vector< std::string > text_
Definition: DDXMLElement.h:193