00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023 #ifndef VOLUMILL_PARAMS_H
00024 #define VOLUMILL_PARAMS_H
00025
00026 #include <map>
00027 #include <boost/mpl/vector.hpp>
00028 #include <boost/variant.hpp>
00029 #include <Util/ParamIds.h>
00030
00031 namespace util
00032 {
00033 namespace detail
00034 {
00035 typedef boost::mpl::vector<int, double, std::string> ParamTypes;
00036 }
00037
00038 typedef boost::make_variant_over<detail::ParamTypes>::type ParamType;
00039
00040 class Parameterized
00041 {
00042 friend class boost::serialization::access;
00043 template<class Archive>
00044 void serialize(Archive & ar, const unsigned int )
00045 {
00046 ar & boost::serialization::make_nvp ("params", m_params);
00047 }
00048 public:
00049 virtual ~Parameterized() {}
00050 virtual void setParam (ParamId paramId, const ParamType& param)
00051 {
00052 m_params[paramId] = param;
00053 }
00055 template<class T>
00056 const T& getParam (ParamId paramId) const
00057 {
00058 ParamTable::const_iterator it = m_params.find (paramId);
00059 VALIDATE (it != m_params.end());
00060 return boost::get<T> (it->second);
00061 }
00063 template<class T>
00064 bool getParam (ParamId paramId, T* pT) const
00065 {
00066 ParamTable::const_iterator it = m_params.find (paramId);
00067 if (it != m_params.end())
00068 {
00069 *pT = boost::get<T> (it->second);
00070 return true;
00071 }
00072 return false;
00073 }
00074 virtual void deleteParam (ParamId paramId)
00075 {
00076 ParamTable::iterator it = m_params.find (paramId);
00077 if (it != m_params.end())
00078 m_params.erase (it);
00079 }
00080 void copyParamTable (const Parameterized& other)
00081 {
00082 for (std::map<ParamId, ParamType>::const_iterator it = other.m_params.begin();
00083 it != other.m_params.end(); ++it)
00084 m_params[it->first] = it->second;
00085 }
00086 size_t getNumParams () const
00087 {
00088 return m_params.size();
00089 }
00090 protected:
00091 typedef std::map<ParamId, ParamType> ParamTable;
00092 ParamTable m_params;
00093 };
00094 }
00095
00096 #endif