From: Barry S. <ba...@ba...> - 2010-04-04 17:21:02
|
On 1 Apr 2010, at 07:52, B A wrote: > Hi, guys, > PyCXX is great. :) > After reading the code, I am not clear about the relationship between PythonExtension and ExtensionObject. > Some usage in the sample code was > > Py::ExtensionObject<range> rheap( new range(1, 10, 2) ); > > and > > range is based on PythonExtension. > > > How to use ExtensionObject? ExtensionObject<type> is an object that will only accept a Py::Object that is of <type>. Use this to make sure you have been passed one of your objects. If I wanted to make sure a Py::Object was a String I could write: Py::String s( args[2] ); If args[2] is not a string then an exception is thrown. Now if I want to make sure I get a MyType then I'd code: ExtensionObject<MyType> s( args[2] ); If args[2] is not a MyType then an exception is thrown. Barry |