Added monitors and statistics, also made a module with some

specific python stuff in __init__.py
This commit is contained in:
maartenkeijzer 2003-01-10 15:41:17 +00:00
commit ea2e369542
19 changed files with 503 additions and 47 deletions

View file

@ -19,7 +19,12 @@
*/
#include <utils/eoParam.h>
#include <boost/python.hpp>
#include <stdexcept>
// Here's 'len'. Why? dunno
#include "valueParam.h"
#include <boost/python/detail/api_placeholder.hpp>
using namespace boost::python;
@ -38,31 +43,92 @@ public:
std::string getValue() const
{
return call_method<std::string>(self, "getValue");
return call_method<std::string>(self, "getValueAsString");
}
void setValue(std::string s)
{
call_method<void>(self, "setValue", s);
call_method<void>(self, "setValueAsString", s);
}
};
template <class T> T getv(const eoValueParam<T>& v) { return v.value(); }
template <class T> void setv(eoValueParam<T>& v, T val) { v.value() = val; }
template <class T>
template <class T, class U>
U getv(const eoValueParam<T>& v) { return v.value(); }
template <class T, class U>
void setv(eoValueParam<T>& v, U val) { v.value() = val; }
template <>
numeric::array getv< std::vector<double>, numeric::array >
(const eoValueParam< std::vector<double> >& param)
{
const std::vector<double>& v = param.value();
list result;
for (unsigned i =0; i < v.size(); ++i)
result.append(v[i]);
return numeric::array(result);
}
template <>
void setv< std::vector<double>, numeric::array >
(eoValueParam< std::vector<double> >& param, numeric::array val)
{
std::vector<double>& v = param.value();
v.resize( boost::python::len(val) );
for (unsigned i = 0; i < v.size(); ++i)
{
extract<double> x(val[i]);
if (!x.check())
throw std::runtime_error("double expected");
v[i] = x();
}
}
template <>
tuple getv<std::pair<double, double>, tuple >
(const eoValueParam< std::pair<double,double> >& p)
{
return make_tuple(p.value().first, p.value().second);
}
template <>
void setv< std::pair<double, double>, tuple >
(eoValueParam< std::pair<double,double> >& p, tuple val)
{
extract<double> first(val[0]);
extract<double> second(val[1]);
if (!first.check())
throw std::runtime_error("doubles expected");
if (!second.check())
throw std::runtime_error("doubles expected");
p.value().first = first();
p.value().second = second();
}
template <class T, class U>
void define_valueParam(std::string prefix)
{
class_<eoValueParam<T>, bases<eoParam> >( (prefix + "ValueParam").c_str(), init<>())
std::string name = "eoValueParam";
name += prefix;
class_<eoValueParam<T>, bases<eoParam> >(name.c_str(), init<>())
.def(init<T, std::string, std::string, char, bool>())
.def(init<T, std::string, std::string, char>())
.def(init<T, std::string, std::string>())
.def(init<T, std::string>())
.def("getValue", &eoValueParam<T>::getValue)
.def("getValueAsString", &eoValueParam<T>::getValue)
.def("__str__", &eoValueParam<T>::getValue)
.def("setValue", &eoValueParam<T>::setValue)
//.add_property("value", getv<T>, setv<T>)
.def("setValueAsString", &eoValueParam<T>::setValue)
.def("getValue", getv<T, U>)
.def("setValue", setv<T, U>)
//.add_property("value", getv<T, U>, setv<T, U>)
;
}
@ -70,8 +136,8 @@ void valueParam()
{
class_<eoParam, ParamWrapper, boost::noncopyable>("eoParam", init<>())
.def(init< std::string, std::string, std::string, char, bool>())
.def("getValue", &ParamWrapper::getValue)
.def("setValue", &ParamWrapper::setValue)
.def("getValueAsString", &ParamWrapper::getValue)
.def("setValueAsString", &ParamWrapper::setValue)
.def("longName", &eoParam::longName, return_value_policy<copy_const_reference>())
//.def("defValue", &eoParam::defValue, return_value_policy<copy_const_reference>())
.def("description", &eoParam::description, return_value_policy<copy_const_reference>())
@ -79,7 +145,21 @@ void valueParam()
.def("required", &eoParam::required)
;
define_valueParam<int>("int");
define_valueParam<std::vector<double> >("vec");
define_valueParam<int, int>("Int");
define_valueParam<double, double>("Float");
define_valueParam<std::vector<double>, numeric::array >("Vec");
define_valueParam< std::pair<double, double>, tuple >("Pair");
class_<ValueParam, bases<eoParam> >("eoValueParamPy", init<>())
//.def(init<object, std::string, std::string, char, bool>())
//.def(init<object, std::string, std::string, char>())
//.def(init<object, std::string, std::string>())
//.def(init<object, std::string>())
.def("getValueAsString", &ValueParam::getValue)
.def("__str__", &ValueParam::getValue)
.def("setValueAsString", &ValueParam::setValue)
.add_property("object", &ValueParam::getObj, &ValueParam::setObj)
;
}