[0.1.x] added : long converter for intBase class

git-svn-id: https://pykd.svn.codeplex.com/svn@71858 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
SND\kernelnet_cp 2011-11-28 16:42:55 +00:00 committed by Mikhail I. Izmestev
parent d778486d62
commit 43639b5476
4 changed files with 31 additions and 2 deletions

View File

@ -128,7 +128,9 @@ BOOST_PYTHON_MODULE( pykd )
.def( "__invert__", &intBase::invert )
.def( "__nonzero__", &intBase::nonzero )
.def( "__str__", &intBase::str )
.def( "__hex__", &intBase::hex );
.def( "__hex__", &intBase::hex )
.def( "__long__", &intBase::long_ )
.def( "__int__", &intBase::int_ );
python::class_<pykd::DebugClient, pykd::DebugClientPtr>("dbgClient", "Class representing a debugging session", python::no_init )
.def( "addr64", &DebugClient::addr64,

View File

@ -37,6 +37,15 @@ public:
}
};
class VariantToPylong : public boost::static_visitor<python::object>
{
public:
template<typename T>
python::object operator()(T i ) const {
return python::long_( i );
}
};
class intBase {
@ -60,6 +69,16 @@ public:
return boost::apply_visitor( VariantToHex(), getValue() );
}
python::object
long_() {
return boost::apply_visitor( VariantToPylong(), getValue() );
}
python::object
int_() {
return boost::apply_visitor( VariantToPylong(), getValue() );
}
python::object eq( python::object& obj ) {
return boost::apply_visitor( VariantToPyobj(), getValue() ) == obj;
}

View File

@ -142,5 +142,12 @@ class IntBaseTest( unittest.TestCase ):
self.assertEqual( -0xFFFFFFFF, -intBase(0xFFFFFFFF) )
self.assertEqual( 0xFFFFFFFF, +intBase(0xFFFFFFFF) )
self.assertEqual( 0, ~intBase(0xFFFFFFFF) )
def testLongConvert( self ):
self.assertEqual( "100", "%d" % intBase(100) )
self.assertEqual( "FFFF", "%X" % intBase(0xFFFF) )
self.assertEqual( "-70000000000", "%d" % intBase(-70000000000) )
self.assertEqual( "FFFFFFFFFFFFFF", "%X" % intBase(0xFFFFFFFFFFFFFF) )
self.assertEqual( "0", "%d" % intBase(False) )

View File

@ -54,8 +54,9 @@ if __name__ == "__main__":
target.module.reload();
suite = getTestSuite()
#suite = getTestSuite( "intbase.IntBaseTest.testLongConvert" )
#suite = getTestSuite( "typedvar.TypedVarTest.testStruct" )
unittest.TextTestRunner(stream=sys.stdout, verbosity=2).run( suite )
a = raw_input("\npress return\n")
#a = raw_input("\npress return\n")