00001
00002 #ifndef DETDESC_PARAMVALIDDATAOBJECT_H
00003 #define DETDESC_PARAMVALIDDATAOBJECT_H 1
00004
00005
00006 #include "DetDesc/ValidDataObject.h"
00007
00008 #include "DetDesc/ParamList.h"
00009 #include "DetDesc/ParamException.h"
00010
00021 class ParamValidDataObject : public ValidDataObject {
00022
00023 public:
00024
00026 ParamValidDataObject();
00027
00029 ParamValidDataObject (const ParamValidDataObject& obj);
00030
00032 virtual ~ParamValidDataObject();
00033
00034 public:
00035
00037 void reset();
00038
00039 public:
00040
00041
00043 virtual void update ( ValidDataObject& obj );
00044
00046 virtual std::ostream& fillStream( std::ostream& s ) const;
00047
00048 public:
00049
00051 bool exists(const std::string &name) const;
00052
00054 virtual const std::type_info &type(const std::string &name) const;
00055
00057 template <class T>
00058 inline bool is(const std::string &name) const {
00059 return type(name) == typeid(T);
00060 }
00061
00063 bool isVector(const std::string &name) const;
00064
00066 virtual std::string comment (const std::string &name) const;
00067
00069 virtual void setComment (const std::string &name, const char *comm);
00070
00072 template <class T>
00073 inline const T ¶m(const std::string &name) const {
00074 ParamList::const_iterator i = m_paramList.find(name);
00075 if ( i == m_paramList.end() ) throw ParamException(name);
00076 try {
00077 return i->second-> template get<T>();
00078 } catch (std::bad_cast) {
00079 throw ParamException(name,typeid(T),i->second->type());
00080 }
00081 }
00082
00084 template <class T>
00085 inline T ¶m(const std::string &name) {
00086 ParamList::iterator i = m_paramList.find(name);
00087 if ( i == m_paramList.end() ) throw ParamException(name);
00088 try {
00089 return i->second-> template get<T>();
00090 } catch (std::bad_cast) {
00091 throw ParamException(name,typeid(T),i->second->type());
00092 }
00093 }
00094
00096 template <class T>
00097 inline const std::vector<T> ¶mVect(const std::string &name) const {
00098 return param<std::vector<T> >(name);
00099 }
00100
00102 template <class T>
00103 inline std::vector<T> ¶mVect(const std::string &name) {
00104 return param<std::vector<T> >(name);
00105 }
00106
00108 virtual const std::string ¶mAsString (const std::string &name) const;
00109
00111 virtual std::string ¶mAsString (const std::string &name);
00112
00114 virtual int paramAsInt (const std::string &name) const;
00115
00117 virtual double paramAsDouble (const std::string &name) const;
00118
00120 virtual const std::vector<std::string> ¶mAsStringVect (const std::string &name) const;
00121
00123 virtual std::vector<std::string> ¶mAsStringVect (const std::string &name);
00124
00126 virtual const std::vector<int> ¶mAsIntVect (const std::string &name) const;
00127
00129 virtual std::vector<int> ¶mAsIntVect (const std::string &name);
00130
00132 virtual const std::vector<double> ¶mAsDoubleVect (const std::string &name) const;
00133
00135 virtual std::vector<double> ¶mAsDoubleVect (const std::string &name);
00136
00138 virtual std::vector<std::string> paramNames() const;
00139
00141 virtual std::string printParams() const ;
00142
00144 virtual std::string paramToString(const std::string &name, int precision) const ;
00145
00146 public:
00147
00148 template <class T>
00149 inline void addParam(const std::string &name, const T &value, const std::string &comment=std::string()){
00150 m_paramList.add(name,value);
00151 if (!comment.empty()) {
00152 m_comments[name] = comment;
00153 }
00154 }
00155
00156 inline void addBasicParam(const std::string &name, const BasicParam *p, const std::string &comment=std::string()){
00157 m_paramList.addBasicParam(name,p);
00158 if (!comment.empty()) {
00159 m_comments[name] = comment;
00160 }
00161 }
00162
00163 private:
00164
00165 typedef std::map<std::string,std::string> CommentMap;
00166
00167 ParamList m_paramList;
00168 CommentMap m_comments;
00169
00170 };
00171
00172 #endif // DETDESC_PARAMVALIDDATAOBJECT_H