C++/Python interfacing

Preamble

Software development is an interactive process. During Py++ development I see many interesting problems and even more interesting solutions.

On this page you will find my collection of the solutions to some of the problems.

custom smart pointer class

There are projects, which use custom smart pointer(s). For majority of the projects, it is not an option to switch to boost::shared_ptr. The solution contains source code and comprehensive unit test for the problem.

boost::shared_ptr< const T>

Boost.Python works pretty well with boost::shared_ptr< T > class, but additional work should be done if you want to register a conversion to boost::shared_ptr< const T> class.

automatic conversion

Boost.Python allows to define automatic conversion from\to C++\Python types. While this is very, very useful functionality, the documentation for it does not exist. This example will shed some light on "r-value"\"l-value" converters.

exceptions

Boost.Python has a limitation: it does not allow to create class, which derives from the class defined in Python. In most use cases this should not bother you, except one - exceptions. The example will provide you with one of the possible solutions.


Valid HTML 4.01 Transitional Valid CSS! SourceForge.net Logo