using boost::python v1
hello all.. i've got some questions about using bpl, and i've searched the docs & the examples, and i can find no answer this example illustrates the issues i'm having <cpp> class B ; class C ; class A { public: A() ; virtual bool func1 ( ) ; virtual bool func2 ( ) = 0 ; virtual ~A() ; virtual int func3 ( std::list<C> ) ; protected : B m_Bobj ; std::string m_Aname ; } ; </cpp> now , i know how to expose the virtual and pure virtual functions to pyhon, i just write a derived class A_callback, and write some static default functions that forward the impl to the virtual function in A . my problem is in the func3() and the protected members do i need to write my own wrapper functions to python for mapping a list<C> ? or does bpl do this itself in some way? and how do i expose the protected members to python? if i do something like this : <cpp> boost::python::class_builder a_class ( this_module , "A" ) ; a_class.def ( &A::m_Bobj , "m_Bobj" ) ; </cpp> that line of code gets me this error (in msvc 6 : sp 5 ) : error C2248: 'm_Bobj': cannot access protected member declared in class 'Logging::Endpoint' <file-name> : see declaration of 'm_Bobj' how can i get this to work?
hello all.. i've got some questions about using bpl, and i've searched the docs & the examples, and i can find no answer
this example illustrates the issues i'm having
<cpp> class B ; class C ;
class A { public: A() ; virtual bool func1 ( ) ; virtual bool func2 ( ) = 0 ; virtual ~A() ; virtual int func3 ( std::list<C> ) ; protected : B m_Bobj ; std::string m_Aname ; } ; </cpp>
now , i know how to expose the virtual and pure virtual functions to
From: "Srivatsan Raghavan"
i just write a derived class A_callback, and write some static default functions that forward the impl to the virtual function in A . my problem is in the func3() and the protected members do i need to write my own wrapper functions to python for mapping a list<C> ?
You can just use class_builder
or does bpl do this itself in some way?
Unfortunately not. In BPL v2 I hope to incorporate some facilities from Ralf Grosse-Kunstleve which make it much easier to translate between Python sequences (lists, tuples, etc) and C++ containers.
and how do i expose the protected members to python? if i do something like this : <cpp> boost::python::class_builder a_class ( this_module , "A" ) ; a_class.def ( &A::m_Bobj , "m_Bobj" ) ; </cpp> that line of code gets me this error (in msvc 6 : sp 5 ) : error C2248: 'm_Bobj': cannot access protected member declared in class 'Logging::Endpoint' <file-name> : see declaration of 'm_Bobj'
Hence the name "protected"
how can i get this to work?
Well, members are probably protected for a reason... However, if you really want to break encapsulation, since you're writing a callback class anyway you could add static get/set member functions to your callback class, then expose them as __getattr__<NAME>__ and __setattr__<NAME>__. HTH, Dave --------------------------------- David Abrahams * Boost Consulting dave@boost-consulting.com * http://www.boost-consulting.com
participants (2)
-
David Abrahams
-
Srivatsan Raghavan