From 4ea9cf304e6c2d1b37cdf2ff13910b6138c2bbef Mon Sep 17 00:00:00 2001 From: "SND\\kernelnet_cp" Date: Tue, 22 Mar 2016 08:49:40 +0000 Subject: [PATCH] [0.3.x] added : __bool__ operator for typedVar class git-svn-id: https://pykd.svn.codeplex.com/svn@90968 9b283d60-5439-405e-af05-b73fd8c4d996 --- pykd/pymod.cpp | 5 +++++ pykd/pytypedvar.h | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/pykd/pymod.cpp b/pykd/pymod.cpp index 6191413..f18f422 100644 --- a/pykd/pymod.cpp +++ b/pykd/pymod.cpp @@ -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_("baseTypes", "base types enumeration", boost::python::no_init) diff --git a/pykd/pytypedvar.h b/pykd/pytypedvar.h index 4f7caf0..00d190f 100644 --- a/pykd/pytypedvar.h +++ b/pykd/pytypedvar.h @@ -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