CMS 3D CMS Logo

DDXMLElement.h

Go to the documentation of this file.
00001 #ifndef DD_XMLElement_H
00002 #define DD_XMLElement_H
00003 /***************************************************************************
00004                           DDXMLElement.h  -  description
00005                              -------------------
00006     begin                : Fri Mar 15 2002
00007     email                : case@ucdhep.ucdavis.edu
00008  ***************************************************************************/
00009 
00010 // -------------------------------------------------------------------------
00011 // Includes
00012 // -------------------------------------------------------------------------
00013 
00014 #include <map>
00015 #include <string>
00016 #include <vector>
00017 
00018 #include "DetectorDescription/Core/interface/DDName.h"
00019 #include "DetectorDescription/Base/interface/DDException.h"
00020 
00021 //#include "DetectorDescription/Parser/interface/DDLParser.h"
00022 
00023 // -------------------------------------------------------------------------
00024 // Class declaration
00025 // -------------------------------------------------------------------------
00026 
00028 
00055 typedef std::map <std::string, std::string> DDXMLAttribute;
00056 typedef std::map <std::string, std::vector<std::string> > AttrAccumType;
00057 
00058 class DDXMLElement
00059 {
00060 
00061   friend std::ostream & operator<<(std::ostream & os, const DDXMLElement & element);
00062 
00063  public:
00064 
00066   DDXMLElement();
00067 
00069   DDXMLElement( const bool& clearme);
00070 
00072   virtual ~DDXMLElement();
00073   
00075 
00084   void loadAttributes (const std::string& elemName
00085                        , const std::vector<std::string> & names
00086                        , const std::vector<std::string> & values
00087                        , const std::string& nmspace);
00088 
00090 
00098   void loadText( const std::string& inText);
00099 
00101   void appendText( const std::string& inText );
00102 
00104   const std::string getText(size_t tindex = 0) const;
00105 
00107   virtual bool gotText() const;
00108 
00110   virtual void clear();
00111 
00113   virtual const std::string & getAttribute(const std::string& name) const;
00114 
00116   virtual const DDXMLAttribute& getAttributeSet(size_t aIndex = 0) const;
00117 
00118   const virtual DDName getDDName(const std::string& defaultNS, const std::string& attname = std::string("name"), size_t aIndex = 0);
00119 
00121   const virtual std::string getName(const std::string& attname, size_t aIndex = 0);
00122 
00124   virtual std::string getNameSpace(const std::string& defaultNS, const std::string& attname, size_t aIndex = 0);
00125 
00127   virtual const std::string & get(const std::string& name, size_t aIndex = 0) const;
00128 
00130   virtual std::vector<std::string> getVectorAttribute(const std::string& name);
00131 
00133   virtual size_t size() const;
00134 
00135   virtual std::vector<DDXMLAttribute>::const_iterator begin();
00136 
00137   virtual std::vector<DDXMLAttribute>::const_iterator end();
00138  
00140   const std::string& parent() const;
00141 
00143 
00151   virtual void processElement (const std::string& name, const std::string& nmspace);
00152 
00154 
00162   virtual void preProcessElement (const std::string& name, const std::string& nmspace);
00163 
00165   virtual void stream(std::ostream & os) const;
00166 
00168   std::vector<DDXMLAttribute>::const_iterator& operator++(int inc);
00169 
00171   virtual bool isEmpty() const;
00172 
00174   void throwError ( const std::string& keyMessage ) const;
00175 
00176   // protected:
00178   static std::string itostr(int i);
00179 
00180  private:
00182   void appendAttributes(std::vector<std::string> & tv, const std::string& name);
00183 
00184   std::vector<DDXMLAttribute> attributes_; // std::vector of name-value std::map (i.e. multiple elements of the same type.
00185   std::vector<std::string> text_; // accumulates text.. one per element of this type.
00186   AttrAccumType attributeAccumulator_;  // temporary holder for most recent accessed attributes_... remove later!
00187   bool autoClear_;
00188   std::vector<DDXMLAttribute>::const_iterator myIter_;
00189 
00190 };
00191 
00192 #endif

Generated on Tue Jun 9 17:32:24 2009 for CMSSW by  doxygen 1.5.4