Exposing c++ class template to Python (known template instances)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Exposing c++ class template to Python (known template instances)

dbarak
This post has NOT been accepted by the mailing list yet.
Assume I have this Interface:
class FooInterface
{
public:
    ...

};

class FooFilePolicy : public FooInterface
{
 ...
};

class FooIoPolicy : public FooInterface
{
 ...
};

And I have this template using the upper interface policy:

template< typename FooPolicy >
class BarWithPolicy
{
...
    FooPolicy* policy;
...
};

How can I expose BarWithPolicy to python that can be generically instantiate with both  FooIoPolicy and FooFilePolicy ?


I don't want to do this :

BarWithPolicy<FooFilePolicy >& GetBarWithPolicyFile()
{
    return new BarWithPolicy<FooFilePolicy >;
}

BarWithPolicy<FooIoPolicy>& GetBarWithPolicyIo()
{
    return new BarWithPolicy<FooIoPolicy >;
}

BOOST_PYTHON_MODULE(PyBar)
{
    def("GetBarWithPolicyFile",
        &GetBarWithPolicyFile,
        return_value_policy<reference_existing_object>(),
        ""
        );
    def("GetBarWithPolicyIo",
        &GetBarWithPolicyIo,
        return_value_policy<reference_existing_object>(),
        ""
        );
}

I would like to have some thing like this in python:

>>> barPolicy = GetBarWithPolic(Io)
Or
>>> barPolicy = GetBarWithPolic(File)

Thanks
-Dotan

Loading...