1 Exporting C++ code to Python {#swig}
2 ============================
4 %IMP uses SWIG to wrap code C++ code and export it to Python. Since SWIG is
5 relatively complicated, we provide a number of helper macros and an example
6 file (see `modules/example/pyext/swig.i-in`). The key bits are
7 - the information goes into a file called `swig.i-in` in the module `pyext` directory
8 - the first part should be one `IMP_SWIG_VALUE(),` `IMP_SWIG_OBJECT()` or
9 `IMP_SWIG_DECORATOR()` line per value type,
object type or decorator
object
10 the module exports to Python. Each of these lines looks like
12 IMP_SWIG_VALUE(IMP::module_namespace, ClassName, ClassNames);
14 - then there should be a number of `%%include` lines, one per header file
15 in the module which exports a
class or function to Python. The header files
16 must be in order such that no class is used before a declaration for it
17 is encountered (SWIG does not do recursive inclusion)
18 - finally, any templates that are to be exported to SWIG must have a
19 `%%
template` call. It should look something like
22 namespace module_namespace {
23 %
template(PythonName) CPPName<Restraint, 3>;