finished pickling support for valueParam
This commit is contained in:
parent
95d3c19211
commit
27f9ae0894
2 changed files with 48 additions and 4 deletions
|
|
@ -97,6 +97,37 @@ class TestPickling(unittest.TestCase):
|
||||||
b = rng2.rand()
|
b = rng2.rand()
|
||||||
self.failUnlessEqual(a,b)
|
self.failUnlessEqual(a,b)
|
||||||
|
|
||||||
|
def vParam(self,v):
|
||||||
|
|
||||||
|
filename = tempfile.mktemp()
|
||||||
|
file = open(filename,'wb')
|
||||||
|
pickler = cPickle.Pickler(file)
|
||||||
|
|
||||||
|
pickler.dump(v)
|
||||||
|
del pickler
|
||||||
|
file.close()
|
||||||
|
file = open(filename)
|
||||||
|
|
||||||
|
unpickler = cPickle.Unpickler(file)
|
||||||
|
|
||||||
|
v2 = unpickler.load();
|
||||||
|
|
||||||
|
self.failUnlessEqual(v.value, v2.value)
|
||||||
|
|
||||||
|
def testValueParam(self):
|
||||||
|
import Numeric
|
||||||
|
|
||||||
|
self.vParam(eoValueParamInt(42,'int'))
|
||||||
|
self.vParam(eoValueParamFloat(4.2,'float'))
|
||||||
|
|
||||||
|
v = eoValueParamVec()
|
||||||
|
v.value = Numeric.arange(10)
|
||||||
|
self.vParam(v)
|
||||||
|
|
||||||
|
v = eoValueParamPair()
|
||||||
|
v.value = (0.3,0.5)
|
||||||
|
self.vParam(v)
|
||||||
|
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -58,13 +58,27 @@ struct ValueParam_pickle_suite : boost::python::pickle_suite
|
||||||
static
|
static
|
||||||
boost::python::tuple getstate(const eoValueParam<T>& _param)
|
boost::python::tuple getstate(const eoValueParam<T>& _param)
|
||||||
{
|
{
|
||||||
return make_tuple(boost::python::str(_param.getValue()));
|
str v(_param.getValue());
|
||||||
|
str d(_param.description());
|
||||||
|
str def(_param.defValue());
|
||||||
|
str l(_param.longName());
|
||||||
|
object s(_param.shortName());
|
||||||
|
object r(_param.required());
|
||||||
|
return make_tuple(v,d,def,l,s,r);
|
||||||
}
|
}
|
||||||
static
|
static
|
||||||
void setstate(eoValueParam<T>& _param, boost::python::tuple pickled)
|
void setstate(eoValueParam<T>& _param, boost::python::tuple pickled)
|
||||||
{
|
{
|
||||||
std::string s = extract<std::string>(pickled[0]);
|
std::string v = extract<std::string>(pickled[0]);
|
||||||
_param.setValue(s);
|
std::string d = extract<std::string>(pickled[1]);
|
||||||
|
std::string def = extract<std::string>(pickled[2]);
|
||||||
|
std::string l = extract<std::string>(pickled[3]);
|
||||||
|
char s = extract<char>(pickled[4]);
|
||||||
|
bool r = extract<bool>(pickled[5]);
|
||||||
|
|
||||||
|
_param = eoValueParam<T>(T(), l, d, s, r);
|
||||||
|
_param.defValue(d);
|
||||||
|
_param.setValue(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -175,6 +189,5 @@ void valueParam()
|
||||||
.def("setValueAsString", &ValueParam::setValue)
|
.def("setValueAsString", &ValueParam::setValue)
|
||||||
.add_property("object", &ValueParam::getObj, &ValueParam::setObj)
|
.add_property("object", &ValueParam::getObj, &ValueParam::setObj)
|
||||||
;
|
;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue