[0.1.x] added : "subscription" for UDT typedVar

git-svn-id: https://pykd.svn.codeplex.com/svn@76519 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2012-05-22 11:21:02 +00:00 committed by Mikhail I. Izmestev
parent f05e0e2658
commit b3e8165aa1
4 changed files with 48 additions and 2 deletions

View File

@ -252,6 +252,31 @@ UdtTypedVar::getField( const std::string &fieldName )
///////////////////////////////////////////////////////////////////////////////////
TypedVarPtr
UdtTypedVar::getElementByIndex( ULONG index )
{
TypeInfoPtr fieldType = m_typeInfo->getFieldByIndex(index);
if ( fieldType->isStaticMember() )
{
if ( fieldType->getStaticOffset() == 0 )
throw ImplementException( __FILE__, __LINE__, "Fix ME");
return TypedVar::getTypedVar( m_client, fieldType, VarDataMemory::factory(m_dataSpaces, fieldType->getStaticOffset() ) );
}
ULONG fieldOffset = fieldType->getOffset();
if ( fieldType->isVirtualMember() )
{
fieldOffset += getVirtualBaseDisplacement( fieldType );
}
return TypedVar::getTypedVar( m_client, fieldType, m_varData->fork(fieldOffset) );
}
///////////////////////////////////////////////////////////////////////////////////
LONG UdtTypedVar::getVirtualBaseDisplacement( TypeInfoPtr& typeInfo )
{
ULONG virtualBasePtr, virtualDispIndex, virtualDispSize;

View File

@ -68,7 +68,7 @@ public:
throw PyException( PyExc_TypeError, "object is unsubscriptable");
}
virtual TypedVarPtr getElementByIndexPtr( const TypedVarPtr& tv ) {
TypedVarPtr getElementByIndexPtr( const TypedVarPtr& tv ) {
return getElementByIndex( boost::apply_visitor( VariantToULong(), tv->getValue() ) );
}
@ -172,12 +172,20 @@ public:
{
}
protected:
virtual std::string print();
virtual std::string printValue();
virtual TypedVarPtr getField( const std::string &fieldName );
virtual ULONG getElementCount() {
return m_typeInfo->getFieldCount();
}
virtual TypedVarPtr getElementByIndex( ULONG index );
LONG getVirtualBaseDisplacement( TypeInfoPtr& typeInfo );
};

View File

@ -529,6 +529,9 @@ TypeInfoPtr UdtTypeInfo::getFieldByIndex( ULONG index )
getVirtualFields();
}
if ( index >= m_fields.size() )
throw PyException( PyExc_IndexError, "Index out of range");
return m_fields[ index ].second;
}
@ -542,6 +545,9 @@ std::string UdtTypeInfo::getFieldNameByIndex( ULONG index )
getVirtualFields();
}
if ( index >= m_fields.size() )
throw PyException( PyExc_IndexError, "Index out of range");
return m_fields[ index ].first;
}

View File

@ -254,3 +254,10 @@ class TypedVarTest( unittest.TestCase ):
g_map = target.module.typedVar( "g_map" )
self.assertEqual( 1, g_map._Mysize )
def testUdtSubscribe(self):
tv = pykd.typedVar( "g_virtChild" )
self.assertEqual( 5, len(tv) )
self.assertEqual( tv[4], tv.m_baseField )
for field in tv:
str( field )