#ifndef IHASPARAMS_H #define IHASPARAMS_H #include #include #include enum class ParamType { INT, FLOAT, STRING, FILE, POINT2, POINT3, }; class ParamValue { private: union { int _int; float _float; float _arr[3]; }; std::string _str; public: template ParamValue(const T val) { setValue(val); } void setValue(const std::string& val) {_str = val;} void setValue(float val) {_float = val;} void setValue(int val) {_int = val;} void setValue(Point2 p) {_arr[0] = p.x; _arr[1] = p.y;} void setValue(Point3 p) {_arr[0] = p.x; _arr[1] = p.y; _arr[2] = p.z;} Point2 toPoint2() const {return Point2(_arr[0], _arr[1]);} Point3 toPoint3() const {return Point3(_arr[0], _arr[1], _arr[2]);} std::string toString() const {return _str;} float toFloat() const {return _float;} int toInt() const {return _int;} }; //union ParamValue { // int _int; // float _float; // std::string _string; // template ParamValue(const T val) { // setValue(val); // } // int toInt() const {return _int;} // float toFloat() const {return _float;} // const std::string& toString() const {return _string;} // void setValue(const float val) {_float = val;} // void setValue(const int val) {_int = val;} // void setValue(const std::string& val) {_string = val;} //}; struct Param { std::string name; ParamType type; Param(const std::string& name, const ParamType type) : name(name), type(type) {;} }; /** free parameters */ class IHasParams { public: /** get the number of parameters */ virtual int getNumParams() const = 0; /** get the description of the idx-th parameter */ virtual Param getParamDesc(const int idx) const = 0; /** get the idx-th param's value */ virtual ParamValue getParamValue(const int idx) const = 0; /** set the idx-th param's value */ virtual void setParamValue(const int idx, const ParamValue& val) const = 0; }; #endif // IHASPARAMS_H