mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[0.3.x] added : __dir__ method for typeInfo ( return list of fields name )
git-svn-id: https://pykd.svn.codeplex.com/svn@90853 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
a18dda466f
commit
7ab33de9f2
@ -737,6 +737,7 @@ BOOST_PYTHON_MODULE( pykd )
|
|||||||
.def( "__getattr__", TypeInfoAdapter::getElementByName )
|
.def( "__getattr__", TypeInfoAdapter::getElementByName )
|
||||||
.def("__len__", TypeInfoAdapter::getElementCount )
|
.def("__len__", TypeInfoAdapter::getElementCount )
|
||||||
.def("__getitem__", TypeInfoAdapter::getElementByIndex )
|
.def("__getitem__", TypeInfoAdapter::getElementByIndex )
|
||||||
|
.def("__dir__", TypeInfoAdapter::getElementDir)
|
||||||
;
|
;
|
||||||
|
|
||||||
python::class_<kdlib::TypedVar, kdlib::TypedVarPtr, python::bases<kdlib::NumBehavior>, boost::noncopyable >("typedVar",
|
python::class_<kdlib::TypedVar, kdlib::TypedVarPtr, python::bases<kdlib::NumBehavior>, boost::noncopyable >("typedVar",
|
||||||
|
@ -104,4 +104,30 @@ python::list TypeInfoAdapter::getFields( kdlib::TypeInfo &typeInfo )
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
python::list TypeInfoAdapter::getElementDir(kdlib::TypeInfo &typeInfo)
|
||||||
|
{
|
||||||
|
std::list<std::wstring> lst;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
AutoRestorePyState pystate;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < typeInfo.getElementCount(); ++i)
|
||||||
|
{
|
||||||
|
std::wstring name = typeInfo.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
} // pykd namespace
|
} // pykd namespace
|
||||||
|
@ -220,6 +220,8 @@ struct TypeInfoAdapter : public kdlib::TypeInfo {
|
|||||||
|
|
||||||
static python::list getFields( kdlib::TypeInfo &typeInfo );
|
static python::list getFields( kdlib::TypeInfo &typeInfo );
|
||||||
|
|
||||||
|
static python::list getElementDir(kdlib::TypeInfo &typeInfo);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BaseTypesEnum {
|
struct BaseTypesEnum {
|
||||||
|
@ -329,3 +329,9 @@ class TypedVarTest( unittest.TestCase ):
|
|||||||
def testFields(self):
|
def testFields(self):
|
||||||
tv = pykd.typedVar( "g_classChild")
|
tv = pykd.typedVar( "g_classChild")
|
||||||
self.assertTrue( len(tv.fields())>0 )
|
self.assertTrue( len(tv.fields())>0 )
|
||||||
|
|
||||||
|
def testDir(self):
|
||||||
|
tv = target.module.typedVar( "structTest", target.module.g_structTest )
|
||||||
|
self.assertEqual(5, len(dir(tv)))
|
||||||
|
self.assertTrue("m_field3" in dir(tv))
|
||||||
|
self.assertFalse("m_field33" in dir(tv))
|
||||||
|
@ -298,3 +298,9 @@ class TypeInfoTest( unittest.TestCase ):
|
|||||||
|
|
||||||
functype = target.module.typedVar( "ArrayOfMethodPtr" ).type()
|
functype = target.module.typedVar( "ArrayOfMethodPtr" ).type()
|
||||||
self.assertEqual(functype.name(), "Void(__thiscall FuncTestClass::*[2])()")
|
self.assertEqual(functype.name(), "Void(__thiscall FuncTestClass::*[2])()")
|
||||||
|
|
||||||
|
def testDir(self):
|
||||||
|
ti = target.module.type("structTest")
|
||||||
|
self.assertEqual(5, len(dir(ti)))
|
||||||
|
self.assertTrue("m_field3" in dir(ti))
|
||||||
|
self.assertFalse("m_field33" in dir(ti))
|
||||||
|
Loading…
Reference in New Issue
Block a user