Skip to content

Test fypp to generate templated containers#3

Draft
Manangka wants to merge 1 commit into
developfrom
template_test
Draft

Test fypp to generate templated containers#3
Manangka wants to merge 1 commit into
developfrom
template_test

Conversation

@Manangka

@Manangka Manangka commented May 13, 2026

Copy link
Copy Markdown
Owner

This PR is a prototype for testing fypp to generate classes

It occurred more to once to me that i needed a data container that is avaialble in ource code base but with the different kind of type. The solution has always been to just copy that class and replace the type with the type i needed.
This results in code that has a lot of duplication. To prevent this it would be great to have something like c++ templating.
In C++, if you need a vector of a certain type you can specify that in brackets e.g. vector, vector, vec.

Fortran doesn't support that. There is however a package that performs this as a preprossecing step, fypp.
In this PR I tested that with the existing STLVector class in MODFLOW. I moved its content to a template class and then used it to generate a STLVecInt and STLVecDouble class. I'm pretty sure that it can also generate a vector class of a custom type e.g. STLVecParticleTrackRecordType

The way it is implemented in this PR is that the template generation happens as a custom target in the meson project and as a prebuildstep in the visual studio project. That way whenever the template is altered the new classes are automatically generated.
This however does not work for the existing make files because as far as i know they can't call a preprocessin step generate the templated files.
An alternative therefore would be to have the generation of the classes as a manual step and have the developers check in the generated files

Some of the containers that could be made more generic are listed below

Containers in MODFLOW:

  • List
  • HashTable
  • PtrHashTable
  • KeyValueList
  • STLStackInt
  • STLVecInt
  • Table?

It would also be possible to expend these containers with concepts like iterators and have generic algorithms be applied to them

Checklist of items for pull request

  • Replaced section above with description of pull request
  • Closed issue #xxxx
  • Referenced issue or pull request #xxxx
  • Added new test or modified an existing test
  • Ran ruff on new and modified python scripts in .doc, autotests, doc, distribution, pymake, and utils subdirectories.
  • Formatted new and modified Fortran source files with fprettify
  • Added doxygen comments to new and modified procedures
  • Updated meson files, makefiles, and Visual Studio project files for new source files
  • Updated definition files
  • Updated develop.toml with a plain-language description of the bug fix, change, feature; required for changes that may affect users
  • Updated input and output guide
  • Removed checklist items not relevant to this pull request

For additional information see instructions for contributing and instructions for developing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant