[C++-sig] examples for add_override_precall_code?
Roman Yakovenko
roman.yakovenko at gmail.com
Thu Mar 25 22:34:54 CET 2010
On Thu, Mar 25, 2010 at 10:33 PM, Nathan Stewart <swarfrat at gmail.com> wrote:
> I have pyplusplus churning out code, now I'm trying to get it to resemble
> what I need. I need to use add_override_precall_code, to add some thread
> locking to my overrides, but I can't seem to figure out how to use it from
> the docs.
Can you ask more concrete question? Basically
"add_override_precall_code" method has single argument - the code you
want to add before calling "override" function.
> Also, I have a set of overloaded virtual functions, and previously
> I've had a wrapper class where the python exports rename the overloads, like
> so:
>
> class Connection
> {
> virtual void Callback(const Type_A&);
> virtual void Callback(const Type_B&);
> }
>
> the wrapper looked like:
>
> ConnectionWrap : Connection, wrapper<Connection>
> {
> void Callback(const Type_A& arg)
> {
> ScopedGILLock lock(m_state); // the reason I'm trying to figure out
> add_override_porecall_code
> if (override o = this->get_override("Callback_Type_A"))
> { o(arg); }
> }
> };
>
>
> I'm getting the rest of the override as above, but setting
> use_overload_macro doesn't rename the overloads as I need. Any clues (since
> pointers are references are both 'overloaded' in this context')
use_overload_macro generates code that uses
"BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS" macro ( see Boost.Python
reference for explanation ).
I guess what you want to use/change is the function alias:
mb = module_builder_t ( .... )
connection = mb.class_( 'Connection' )
for callback in connection.mem_funs( 'Callback' ):
callback.alias = < create new alias name based in argument types
and original function name>
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list