Chaste / cppwg

An automatic Python wrapper generator for C++ code.
BSD 3-Clause "New" or "Revised" License
45 stars 8 forks source link

Use templated wrappers #30

Open kwabenantim opened 6 months ago

kwabenantim commented 6 months ago

Description

Use templating to reduce number of generated wrapper files. Many wrappers only vary in template arguments and the rest of the code is exactly the same.

For example, the aim would be to refactor this

register_AbstractCellPopulation2_2_class(m);
register_AbstractCellPopulation3_3_class(m);

into this:

register_AbstractCellPopulation_class<2, 2>(m);
register_AbstractCellPopulation_class<3, 3>(m);

The first requires separate wrappers to be created for AbstractCellPopulation2_2 and AbstractCellPopulation3_3. Counting hpp and cpp, this generates 4 files.

The second requires a single templated wrapper to be created for AbstractCellPopulation. This would only generate 2 files regardless of the number of different sets of template arguments required. This approach would only need each set of arguments to be explicitly instantiated.

kwabenantim commented 1 week ago

This doesn't seem trivial as CastXML does not support uninstantiated templates https://github.com/CastXML/CastXML/blob/v0.3.4/doc/manual/castxml.1.rst#why-dont-i-see-templates-in-the-output.