Automatic generation of C++ code for process models – 2 of 3
In this part two of the series of three posts we will leverage the techniques discussed in part one (command-line C++ code generation from the JSON representation of process models with the jinja2 template engine) to make the code generation interactive.
JSON, JSON schema and Jinja2 templates are de-facto standards and there are quite a few tools that understand these formats.
To get the best out of json-editor, we’ll need to expand the basic JSON schema presented in part one, adding a few additional, optional fields (title, format, propertyOrder, template, watch, enumSource). The expanded schema is quite verbose so if you really want to see it here is the link.
Here is a screenshot of the LIBPF™ model wizard with the MicroTurbine model from the cogeneration demo:
The wizard behind the scenes uses the very same JSON representation we have shown in part one, and you can see it for the currently loaded model by clicking on the JSON button at the top of the Model tab. For example here is the link to the JSON representation for the MicroTurbine model.
From the JSON representation, the LIBPF™ model wizard can generate the Process Flow Diagram preview, which gives you a rough idea of how the connectivity you have defined in the
streams section of the JSON translates:
Finally thanks to the Nunjucks library the LIBPF™ model wizard can perform the C++ code generation directly in the browser, without the need to invoke the command-line commands described in part one (but if you prefer them, you can still use them !).
Here is the generated interface for the MicroTurbine model (.h file):
and here is the generated implementation (.cc file):
The LIBPF™ model wizard can be used online at this address: </sdk/model_wizard/>.
This tutorial video will guide you in your first steps:
Finally, we choose to release the source code for the LIBPF™ model wizard with an open source license so you can also run it locally: to do so, clone the gitlab repo and have a look at the README.
Watch out for part three in this series, where we’ll present the complete model development workflow using the automatic code generation tool presented here !