[0.3.x] added : __dir__ method for typedVar ( return list of fields name )

git-svn-id: https://pykd.svn.codeplex.com/svn@90852 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2015-10-21 16:05:26 +00:00 committed by Mikhail I. Izmestev
parent 63e824d50a
commit a18dda466f
3 changed files with 28 additions and 0 deletions

View File

@ -773,6 +773,7 @@ BOOST_PYTHON_MODULE( pykd )
.def( "__str__", TypedVarAdapter::print ) .def( "__str__", TypedVarAdapter::print )
.def("__len__", TypedVarAdapter::getElementCount ) .def("__len__", TypedVarAdapter::getElementCount )
.def("__getitem__", TypedVarAdapter::getElementByIndex ) .def("__getitem__", TypedVarAdapter::getElementByIndex )
.def("__dir__", TypedVarAdapter::getElementsDir)
//.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr ) //.def("__getitem__", &kdlib::TypedVar::getElementByIndexPtr )
; ;

View File

@ -97,5 +97,31 @@ python::list TypedVarAdapter::getFields( kdlib::TypedVar& typedVar )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
python::list TypedVarAdapter::getElementsDir(kdlib::TypedVar& typedVar)
{
std::list<std::wstring> lst;
do {
AutoRestorePyState pystate;
for (size_t i = 0; i < typedVar.getElementCount(); ++i)
{
std::wstring name = typedVar.getElementName(i);
lst.push_back(name);
}
} while (false);
python::list pylst;
for (std::list<std::wstring>::const_iterator it = lst.begin(); it != lst.end(); ++it)
pylst.append(*it);
return pylst;
}
///////////////////////////////////////////////////////////////////////////////
} // namesapce pykd } // namesapce pykd

View File

@ -124,6 +124,7 @@ struct TypedVarAdapter {
return typedVar.deref(); return typedVar.deref();
} }
static python::list getElementsDir(kdlib::TypedVar& typedVar);
}; };
} // end namespace pykd } // end namespace pykd