[C++-sig] Re: operator ->, cast operator

Leonard "paniq" Ritter paniq at paniq.org
Sun Mar 13 01:17:54 CET 2005


followup (heh):

to get the syntax i wished for i wrote a function that went like

    template<typename T>
    Ptr<T> New(const String& objectClassName)
    {
        return Ptr<T>(objectClassName);
    }

and exposed it via def("View",New<View>), and  that works due to 
boost.pythons magical ptr conversion wizardry ;) the class itself is now 
exposed as "ViewInterface" which is not _perfect_, but its sufficient 
since type names dont play a big role in python anyway.

thank you dave for the help, boost.python rocks again :)

Leonard "paniq" Ritter wrote:

>
> appending i should say that the code compiled, but i still had no 
> access on View's methods. i modified the code so that the export of 
> Ptr<> was removed (i assume it was not needed anymore), and so i'm 
> left with an abstract class export with a custom smart pointer that 
> doesnt give me any benefit because i dont have access to the smart 
> pointers constructor (which a shortcut to looking up the library from 
> the class id, loading it, resolving the factory function and obtaining 
> a new object) - that means using Ptr<> as HeldType does not seem to 
> let me use the interface instantiations in the fashion i wanted to 
> from python.
>
> given that Ptr<> itself exports a few nice methods i want to use from 
> python (such as factory constructors and interface querying methods), 
> is there any chance of exposing these?
>
>> You also need
>> namespace Mu
>> {
>>   template <class T>
>>   T* get_pointer(Ptr<T> const& p)
>>   {       return p.get();  // or something
>>   }
>> }
>>
>>
>>  
>>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>




More information about the Cplusplus-sig mailing list