[0.3.x] added : __bool__ operator for typedVar class

git-svn-id: https://pykd.svn.codeplex.com/svn@90968 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2016-03-22 08:49:40 +00:00 committed by Mikhail I. Izmestev
parent c971656625
commit 4ea9cf304e
2 changed files with 16 additions and 0 deletions

View File

@ -832,6 +832,11 @@ BOOST_PYTHON_MODULE( pykd )
.def("__getitem__", TypedVarAdapter::getElementByIndex )
.def("__dir__", TypedVarAdapter::getElementsDir)
//.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr )
#if PY_VERSION_HEX >= 0x03000000
.def("__bool__", TypedVarAdapter::isNotZero)
#else
.def("__iszero__", TypedVarAdapter::isZero)
#endif
;
python::class_<BaseTypesEnum>("baseTypes", "base types enumeration", boost::python::no_init)

View File

@ -162,6 +162,17 @@ struct TypedVarAdapter {
}
static python::list getElementsDir(kdlib::TypedVar& typedVar);
static bool isZero(kdlib::TypedVar& typedVar)
{
AutoRestorePyState pystate;
return typedVar.getValue() == 0;
}
static bool isNotZero(kdlib::TypedVar& typedVar)
{
return !isZero(typedVar);
}
};
} // end namespace pykd