[C++-sig] Pyste Modification for operator: is there any python function to know whether a C++ type is a class or basic data type?
roman.yakovenko at gmail.com
Wed Aug 3 14:15:16 CEST 2005
On 8/3/05, Aghera, Parixit <paghera at qualcomm.com> wrote:
> Hi All,
> I have a C++ library which I want to export to python using
> pyste. There are several sequence class in C++ library which overloads
>  operator and that is the only way to access an element in sequence.
> Current pyste implementation (Release version 1_32_0) doesn't handle
> operator , so I modified ClassExporter.py to generate the .defs for
> __getitem__ and __setitem__ in the pyste generated .cpp. Following the
> template function for getitem and pyste modification. It seems that for
> C++ struct/class I have to return the element by reference and for other
> C++ types (basic/enums) I need to return the element by value. I learnt
> this by experiments and from
> boost/python/suite/indexing/vector_indexing_suite.hpp .
> Now the problem I run into here is this. I need to add
> return_internal_reference< 1 > in generated .def in case when getitem
> function return element by reference. Now in python I don't know a way
> to figure out whether IndexOp_PysteWrapper_getitem function will return
> element by reference or by value, since I don't know if the return type
> of operator is a C++ class/structure or basic data type.
> Any solution/hints for solution to this problem would be a great
I think that right now such function does not exist in Pyste. There
are 2 ways to do the job.
Pyste has class hierarchy called Exporters, with base class Exporter.
Instance of this
class keeps referenced to declaration. You should find your function,
operator, in the declarations list and then to examine the return
type. Also I think you will have to give
access to your new function in pyste scripts. See pyste.py
Of course there is an other, simpler way to complete the task - to use
pyplusplus code generator. pyplusplus gives you access to
functionality very similar to boost.type_traits
library. Also it gives you an convenient way to add custom code to
Hope, this was helpful.
More information about the Cplusplus-sig