Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/xml/element is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_xml_element
0005 #define tools_xml_element
0006 
0007 // This is only needed to satisfy a use in source/analysis/hntools/src/G4PlotManager.cc
0008 #include "../srep"
0009 
0010 #include "../sto"
0011 #include "../scast"
0012 
0013 namespace tools {
0014 namespace xml {
0015 
0016 class ielem {
0017 public:
0018   virtual ~ielem(){}
0019 public:
0020   virtual void* cast(cid) const = 0;
0021 };
0022 
0023 class element : public virtual ielem {
0024 public:
0025   static cid id_class() {return 0;}
0026   virtual void* cast(cid a_class) const {
0027     if(void* p = cmp_cast<element>(this,a_class)) {return p;}
0028     else return 0;
0029   }
0030 public:
0031   typedef std::pair<std::string,std::string> atb;
0032 public:
0033   element(const std::string& a_name,
0034           const std::vector<atb>& a_atbs,
0035           const std::string& a_value){
0036     m_name = a_name;
0037     m_atbs = a_atbs;
0038     m_value = a_value;
0039   }
0040   virtual ~element(){
0041   }
0042 public:
0043   element(const element& a_from)
0044   :ielem(a_from) {
0045     m_name = a_from.m_name;
0046     m_atbs = a_from.m_atbs;
0047     m_value = a_from.m_value;
0048   }
0049   element& operator=(const element& a_from) {
0050     m_name = a_from.m_name;
0051     m_atbs = a_from.m_atbs;
0052     m_value = a_from.m_value;
0053     return *this;
0054   }
0055 public:
0056   const std::string& name() const {return m_name;}
0057   const std::vector<atb>& attributes() const {return m_atbs;}
0058   const std::string& value() const {return m_value;}
0059 
0060   bool attribute_value(const std::string& a_atb,std::string& a_value) const {
0061     tools_vforcit(atb,m_atbs,it) {
0062       if((*it).first==a_atb) {
0063         a_value = (*it).second;
0064         return true;
0065       }
0066     }
0067     a_value.clear();
0068     return false;
0069   }
0070 
0071   template <class T>
0072   bool attribute_value(const std::string& a_atb,T& a_value) const {
0073     std::string sv;
0074     if(!attribute_value(a_atb,sv)) {a_value=T();return false;}
0075     return to<T>(sv,a_value);
0076   }
0077 
0078 protected:
0079   std::string m_name;
0080   std::vector<atb> m_atbs;
0081   std::string m_value;
0082 };
0083 
0084 }}
0085 
0086 #endif