00001
00002 #ifndef DETDESC_PARAM_H
00003 #define DETDESC_PARAM_H 1
00004
00005
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009
00010 #include <sstream>
00011
00012 #include "DetDesc/BasicParam.h"
00013 #include "GaudiKernel/GaudiException.h"
00014
00022 template <class T>
00023 class Param: public BasicParam {
00024 public:
00025 typedef T value_type;
00026
00028 Param( ): m_val() {}
00029
00031 Param(const value_type &val): m_val(val) {}
00032
00033 virtual ~Param(){}
00034
00036 template <class T1>
00037 inline void set(const T1 &val) { m_val = val; }
00038
00040 inline value_type &get() { return m_val; }
00041
00043 inline const value_type &get() const { return m_val; }
00044
00046 inline virtual std::string toStr() const;
00047
00049 virtual std::string toXMLStr(const std::string& name,
00050 const std::string& comment = "",
00051 int precision = 16) const;
00052
00054 virtual const std::type_info &type() const { return typeid(T); }
00055
00057 virtual BasicParam * new_copy() const {
00058 return new Param<T>(m_val);
00059 }
00060
00061 private:
00063 virtual void *_get_ptr() { return (void*)&m_val;}
00065 virtual const void *_get_ptr() const { return (void*)&m_val;}
00067 value_type m_val;
00068
00069 };
00070
00071 #include "GaudiKernel/SerializeSTL.h"
00073 template<class T>
00074 inline std::string Param<T>::toStr() const {
00075 using namespace GaudiUtils;
00076 std::ostringstream o;
00077 o << m_val;
00078 return o.str();
00079 }
00080
00081 template<> inline std::string Param<double>::toStr() const {
00082 std::ostringstream o;
00083 o.precision(16);
00084 o << m_val;
00085 return o.str();
00086 }
00087
00090 template<class T>
00091 std::string Param<T>::toXMLStr(const std::string&, const std::string&, int) const {
00092 throw GaudiException(std::string("Cannot convert parameter of type ") + typeid(m_val).name() + " to XML",
00093 "Param<T>::toXMLStr()", StatusCode::FAILURE );
00094 return "";
00095 }
00096
00097
00098
00099 template<> std::string Param<int>::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00100 template<> std::string Param<double>::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00101 template<> std::string Param<std::string>::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00102
00103 template<> std::string Param<std::vector<int> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00104 template<> std::string Param<std::vector<double> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00105 template<> std::string Param<std::vector<std::string> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00106
00107 template<> std::string Param<std::map<std::string,int> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00108 template<> std::string Param<std::map<std::string,double> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00109 template<> std::string Param<std::map<std::string,std::string> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00110
00111 template<> std::string Param<std::map<int,int> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00112 template<> std::string Param<std::map<int,double> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00113 template<> std::string Param<std::map<int,std::string> >::toXMLStr(const std::string& name, const std::string& comment, int precision) const;
00114
00115 #endif // DETDESC_PARAM_H