Skip to content

poly_scribe_code_gen.cpp_gen

cpp_gen

This module generates C++ code from parsed IDL data.

It uses Jinja2 templates to render the C++ code based on the parsed IDL data and additional data provided. It supports generating enumerations, typedefs, structs, and polymorphic structs as tagged unions.

Functions:

  • generate_cpp

    Generate C++ code from the parsed IDL data.

generate_cpp

generate_cpp(
    parsed_idl: ParsedIDL,
    additional_data: AdditionalData,
    out_file: Path,
) -> None

Generate C++ code from the parsed IDL data.

Based on the parsed IDL data and additional data, this function generates reflect-cpp data structures. The generated code is written to the specified output file.

Enumerations are generated as enum class types, and typedefs are implemented via using statements. Structs are generated as C++ structs, and the inheritance is flattened as this is not supported by reflect-cpp. Polymorphic structs are generated as tagged unions.

All code is contained in a namespace, the name of which is specified via the package key in the additional data.

The generated header file contains will also include the poly-scribe.hpp header file. In this header file, two convenience functions are defined: load and save, which can be used to load and save the generated structs. These functions will, depending on the type of file store the data in different formats. The following formats are supported:

  • JSON
  • YAML
  • CBOR
  • UBJSON

Any types from the IDL that are not supported in C++ are converted to cpp types.