00001
00002 #ifndef DETDESC_BASICPARAM_H
00003 #define DETDESC_BASICPARAM_H 1
00004
00005
00006 #include <typeinfo>
00007
00015 class BasicParam {
00016 public:
00017
00019 virtual ~BasicParam() {};
00020
00023 template <class T>
00024 inline T &get() {
00025 if (type() != typeid(T)) { throw std::bad_cast(); }
00026 return *(T*)_get_ptr();
00027 }
00029 template <class T>
00030 inline const T &get() const {
00031 if (type() != typeid(T)) { throw std::bad_cast(); }
00032 return *(T*)_get_ptr();
00033 }
00034
00036 template <class T>
00037 inline void set(const T &val) {
00038 if (type() != typeid(T)) { throw std::bad_cast(); }
00039 *(T*)_get_ptr() = val;
00040 }
00041
00043 virtual std::string toStr() const = 0;
00044
00046 virtual std::string toXMLStr(const std::string &name,
00047 const std::string& comment = "",
00048 int precision = 16) const = 0;
00049
00051 virtual const std::type_info &type() const = 0;
00052
00055 virtual BasicParam * new_copy() const = 0;
00056
00057 protected:
00058
00059 private:
00061 virtual void *_get_ptr() = 0;
00063 virtual const void *_get_ptr() const = 0;
00064
00065 };
00066 #endif // DETDESC_BASICPARAM_H