hi there, I'v got a class that holds a reference to an external object, which is accessible through a simple method: class Origin {}; class Event { public: Event(const Origin *o) : my_origin(o) {} const Origin *GetOrigin() { return my_origin;} private: const Origin *my_origin; }; I can expose the 'Event' and 'Origin' classes, as well as &Event::GetOrigin, to python. However, I'd rather like to make the origin accessible as a (read-only) property. The problem is that the 'add_property' method doesn't take a return value policy, so I have no way of telling python how to wrap the pointer. What is the suggested way to do that ? Regards, Stefan
Stefan Seefeld <stefan.seefeld@orthosoft.ca> writes:
hi there,
I'v got a class that holds a reference to an external object, which is accessible through a simple method:
class Origin {};
class Event { public: Event(const Origin *o) : my_origin(o) {} const Origin *GetOrigin() { return my_origin;} private: const Origin *my_origin; };
I can expose the 'Event' and 'Origin' classes, as well as &Event::GetOrigin, to python. However, I'd rather like to make the origin accessible as a (read-only) property. The problem is that the 'add_property' method doesn't take a return value policy, so I have no way of telling python how to wrap the pointer.
What is the suggested way to do that ?
See make_getter/make_setter. You can pass their results to add_property. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
Stefan Seefeld <stefan.seefeld@orthosoft.ca> writes:
hi there,
I'v got a class that holds a reference to an external object, which is accessible through a simple method:
class Origin {};
class Event { public: Event(const Origin *o) : my_origin(o) {} const Origin *GetOrigin() { return my_origin;} private: const Origin *my_origin; };
I can expose the 'Event' and 'Origin' classes, as well as &Event::GetOrigin, to python. However, I'd rather like to make the origin accessible as a (read-only) property. The problem is that the 'add_property' method doesn't take a return value policy, so I have no way of telling python how to wrap the pointer.
What is the suggested way to do that ?
See make_getter/make_setter. You can pass their results to add_property.
make_getter seems to expect a pointer-to-member, while I want a pointer-to-member-function. Am I missing something ? Stefan
I'm trying to compile boost.python on Linux using Intel compiler and STLport. Can someone please point me to some references or bjam documentation on how to do it? Any help will be appreciated!!! Marcelo A. Camelo, M. Eng. - Project Leader ESSS - Engineering Simulation and Scientific Software E-mail: camelo@esss.com.br Phone: +55-48-334-8922
Hummm... a bit more of information. I can compile boost without problems using the intel-linux toolset. The problem is that I need to compile it using STL (intel's compaining standard library is not 100% conformant and does not implement some features we need in another part of our code base). All I need is a clean way to pass to icc the path to the icl header files. I could not figure it out by my self. I've tried to learn from "intel-win32-stlport-tools.jam" but it didn't help much. I've also tried to add the include directory to STDHDRS var in intel-linux-tools.jam and through bjam command line. No success there also. I know this must be a basic feature of bjam, but I could not learn how to do it. Marcelo A. Camelo, M. Eng. - Project Leader ESSS - Engineering Simulation and Scientific Software E-mail: camelo@esss.com.br Phone: +55-48-334-8922 -----Original Message----- From: c++-sig-admin@python.org [mailto:c++-sig-admin@python.org] On Behalf Of Marcelo A. Camelo Sent: quarta-feira, 16 de julho de 2003 17:04 To: c++-sig@python.org Subject: [C++-sig] Compiling boost.python using intel and stlport on linux I'm trying to compile boost.python on Linux using Intel compiler and STLport. Can someone please point me to some references or bjam documentation on how to do it? Any help will be appreciated!!! Marcelo A. Camelo, M. Eng. - Project Leader ESSS - Engineering Simulation and Scientific Software E-mail: camelo@esss.com.br Phone: +55-48-334-8922 _______________________________________________ C++-sig mailing list C++-sig@python.org http://mail.python.org/mailman/listinfo/c++-sig
"Marcelo A. Camelo" <camelo@esss.com.br> writes:
Hummm... a bit more of information.
I can compile boost without problems using the intel-linux toolset. The problem is that I need to compile it using STL (intel's compaining standard library is not 100% conformant and does not implement some features we need in another part of our code base).
All I need is a clean way to pass to icc the path to the icl header files. I could not figure it out by my self.
I've tried to learn from "intel-win32-stlport-tools.jam" but it didn't help much. I've also tried to add the include directory to STDHDRS var in intel-linux-tools.jam and through bjam command line. No success there also.
I know this must be a basic feature of bjam, but I could not learn how to do it.
Try making a toolset like this one: # # intel-linux-stlport-tools.jam # extends-toolset intel-linux ; STDHDRS = path/to/stlport/headers $(STDHDRS) ; # I think you need this too LIBPATH += path/to/stlport/lib ; FINDLIBS += stlport-<your version> ; That should get you most of the way there. -- Dave Abrahams Boost Consulting www.boost-consulting.com
Hi, Can someone give me example of a ResultConvertorGenerator (or whatever is required) so that addref/decref calls get called on an object? Currently, I am using boost::intrusive_ptr, which does almost what I want. All my class bindings are defined like so: class_<A, intrusive_ptr<A>
("A"); class_<B, intrusive_ptr<B>, bases<A> >("B"); etc...
The problem is that functions which accept an intrusive_ptr<A>, when called with an intrusive_ptr<B>, cause boost.python errors (no valid type found). So, I would like to replace most of the uses of intrusive_ptr<A> with A* (in method signatures), and just have my C++ implementations use intrusive_ptr internally. This way, the polymorphic thing will work out ok, with boost wrapping B* and calling foo(A*) rather than wrapping intrusive_ptr<B> and failing to call foo(intrusive_ptr<A>).
"Dusty Leary" <dleary@ttlc.net> writes:
Hi,
Can someone give me example of a ResultConvertorGenerator (or whatever is required) so that addref/decref calls get called on an object?
Currently, I am using boost::intrusive_ptr, which does almost what I want.
All my class bindings are defined like so: class_<A, intrusive_ptr<A>
("A"); class_<B, intrusive_ptr<B>, bases<A> >("B"); etc...
The problem is that functions which accept an intrusive_ptr<A>, when called with an intrusive_ptr<B>, cause boost.python errors (no valid type found).
Try implicitly_convertible<intrusive_ptr<B>, intrusive_ptr<A> >(); Of course, if you just use shared_ptr instead, none of that is needed ;-)
So, I would like to replace most of the uses of intrusive_ptr<A> with A* (in method signatures), and just have my C++ implementations use intrusive_ptr internally. This way, the polymorphic thing will work out ok, with boost wrapping B* and calling foo(A*) rather than wrapping intrusive_ptr<B> and failing to call foo(intrusive_ptr<A>).
If you really want to do that, the only way is to write thin wrapper functions for each [member] function you're wrapping. -- Dave Abrahams Boost Consulting www.boost-consulting.com
"Dusty Leary" <dleary@ttlc.net> writes:
Try
implicitly_convertible<intrusive_ptr<B>, intrusive_ptr<A> >();
Of course, if you just use shared_ptr instead, none of that is needed ;-)
why does it work automatically with shared_ptr and not with intrusive_ptr?
Because shared_ptr is special, and can do so safely. The shared pointer always manages the owning Python object, while intrusive_ptr can't do that, and there's no guarantee that a derived-to-base conversion on intrusive_ptr is safe (there might be no virtual destructor in the base class). -- Dave Abrahams Boost Consulting www.boost-consulting.com
Stefan Seefeld <seefeld@sympatico.ca> writes:
David Abrahams wrote:
Stefan Seefeld <stefan.seefeld@orthosoft.ca> writes:
hi there,
I'v got a class that holds a reference to an external object, which is accessible through a simple method:
class Origin {};
class Event { public: Event(const Origin *o) : my_origin(o) {} const Origin *GetOrigin() { return my_origin;} private: const Origin *my_origin; };
I can expose the 'Event' and 'Origin' classes, as well as &Event::GetOrigin, to python. However, I'd rather like to make the origin accessible as a (read-only) property. The problem is that the 'add_property' method doesn't take a return value policy, so I have no way of telling python how to wrap the pointer.
What is the suggested way to do that ? See make_getter/make_setter. You can pass their results to add_property.
make_getter seems to expect a pointer-to-member, while I want a pointer-to-member-function. Am I missing something ?
http://www.boost.org/libs/python/doc/v2/make_function.html? -- Dave Abrahams Boost Consulting www.boost-consulting.com
--- Stefan Seefeld <stefan.seefeld@orthosoft.ca> wrote:
However, I'd rather like to make the origin accessible as a (read-only) property. The problem is that the 'add_property' method doesn't take a return value policy, so I have no way of telling python how to wrap the pointer.
make_getter supports return-value policies: .add_property("origin", make_getter(&Event::origin, return_value_policy<whatever>())) Ralf __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
participants (6)
-
David Abrahams -
Dusty Leary -
Marcelo A. Camelo -
Ralf W. Grosse-Kunstleve -
Stefan Seefeld -
Stefan Seefeld