Get a link to yourself when using boost :: python

I am trying to port a Python class to C ++ using boost :: python with the hope of speeding up the execution of a Python application (the class that I am migrating to C ++ is responsible for ~ 30% of the application execution time).

The initialization of the Python source class looks like this:

class PyClass(object):
    def __init__(self, child):
        child.set_parent(self)
        ...

How do I replicate this in a C ++ constructor?

if I have a C ++ class:

class CClass
{
    // to get input args that match the Python class I need
    CClass(boost::python::object &child)
    {
         // but how do I get the boost::python::object self
         // as I only have *this in C++ ?
         CClass& c = boost::python::extract<CClass&>(child);
         c.set_parent(self);
    }

    ...
}

Thanks Mark

+5
source share
1 answer

You can use a pointer thiswith boost::python::ptr(this)as described in this answer .

+3
source

All Articles