Code Generator
The Python generator lives in src/generator/ and is the entry point for turning model files into
C++ headers and Python bindings.
Requirements
Python ≥ 3.9 and the following packages (also in src/generator/requirements.txt):
jinja2
jsonschema
pyyaml
Install with:
pip install -r src/generator/requirements.txt
Invocation
python src/generator/generator.py \
--model_dir src/model \
--out_dir build/ \
--template_dir src/template \
--schema_dir src/generator \
--module_name my_module # optional pybind11 module name
Arguments:
Argument |
Description |
|---|---|
|
Directory containing the JSON / YAML model files ( |
|
Root output directory. Generated files go into |
|
Directory with the Jinja2 |
|
Directory containing |
|
Name of the generated pybind11 Python module (default: |
|
Convert JSON model files to YAML (Python ≥ 3.9: |
Output Files
All files are written under <out_dir>/generated/:
File |
Content |
|---|---|
|
Main generated header — group infos, custom types, enums, structs, and all |
|
|
|
pybind11 module source (only when |
|
PlantUML class diagram sources for the generated data model. |
|
CSV listing all datapoints: ID, name, type, access, group, version. |
CMake Integration
The generator is wired into CMake via a custom target. When building the project directly:
# In src/CMakeLists.txt (already set up)
add_custom_command(OUTPUT "${_GEN_STAMP}" ...)
add_custom_target(GenerateDataLayer DEPENDS "${_GEN_STAMP}")
add_dependencies(DatalayerGeneratorExample GenerateDataLayer)
When consuming the library as a Conan package the generate_datalayer() CMake function from
DataLayerGeneratorHelpers.cmake provides the same capability:
find_package(DataLayerGenerator REQUIRED)
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE DataLayerGenerator::DataLayerGenerator)
generate_datalayer(my_app
MODEL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/model
OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
)
See Packaging & Integration for the full consumer workflow.
Validation
The generator validates model files in two passes:
JSON Schema validation —
schema.jsonchecks structural correctness (required fields, allowed values for"access","persistence", etc.).Semantic validation — Python validators in
validators.pycheck cross-references:Every datapoint
"group"must refer to a group defined inGroups.Every datapoint
"type"must be a base type, a defined struct, enum, or alias type.Duplicate names and duplicate IDs within a group are rejected.
Alias types with both
"min"and"max"must satisfymin < max.
Templates
Three Jinja2 templates drive code generation:
Template |
Output |
|---|---|
|
|
|
|
|
|
</content> </invoke>