[C++-sig] embedded Python: Access an object defined previously in C++

Markus Heller markus at relix.de
Wed Dec 28 08:08:21 CET 2005


Hi Stefan,

> Ok, I was misled by your phrasing then, sorry. It seems you really want
> to reflect your C++ type(s) into python, using boost.python's class_
> mechanism.
> That is described rather well in the above docs, I think. May be you
> could ask more specific questions once you run into difficulties, sending
> code snippets, error messages, and the like ?
> Or, a *concrete* example of what you want to do, i.e. how the C++ type
> looks like, and how you want it to look like in python, etc.

well, I experimented a little with the boost libs, but I see that you can only 
expose entire classes with the class_ method. What I want, though, is just to 
expose a data object to the python program I would like to call through the 
Py/C-API. 

The definition of the data is as follows:
>>>>>
typedef std::vector<std::string> multiline;

struct XTuple {
    multiline XMLPath;
    std::string Content;
};

struct IDoc { 
    std::string DocURL;
    std::vector<XTuple> TupleSet;
};
<<<<<

I would like to expose an IDoc to Python, have all the processing of the 
TupleSet done out there and collect the results. Off course, the IDoc 
contents will be changing during runtime, so I cannot generate a shared 
object and be happy... I need to do this from within a so-called pipeline 
class. 

How can I expose the IDoc?

Thanks in advance,

Markus




More information about the Cplusplus-sig mailing list