schema_salad.cpp_codegen
C++17 code generator for a given Schema Salad definition.
Currently only supports emiting YAML from the C++ objects, not yet parsing YAML into C++ objects.
The generated code requires the libyaml-cpp library & headers
To see an example of usage, look at schema_salad/tests/codegen/cwl.cpp which can be combined with the CWL V1.0 schema as shown below:
schema-salad-tool --codegen cpp schema_salad/tests/test_schema/CommonWorkflowLanguage.yml > cwl_v1_0.h
g++ --std=c++20 -I. -lyaml-cpp schema_salad/tests/codegen/cwl.cpp -o cwl-v1_0-test
./cwl-v1_0-test
# g++ versions older than version 10 may need "--std=c++2a" instead of "--std=c++20"
Classes
Prototype of a class. |
|
Prototype of a single field from a class definition. |
|
Prototype of a map. |
|
Prototype of a union. |
|
Prototype of a enum. |
|
Generation of C++ code for a given Schema Salad definition. |
Functions
|
Put quotes around a string. |
Rename keywords that are reserved in C++. |
|
|
Create a C++ safe name. |
|
Create a C++ safe name for namespaces. |
|
Create a namespaced safename. |
|
Split url name into its components. |
|
Split field into its components. |
Check if v is a primitve type. |
|
|
Check if e has a field f value. |
Check if v is of type record schema. |
|
|
Check if v is of type enum schema. |
|
Check if v is of type array. |
|
Check if v is any of the simple types. |
Check if v is of type array schema. |
|
|
Check if v is of type map schema. |
Check if v is of type union schema. |
Module Contents
- schema_salad.cpp_codegen.replaceKeywords(s)
Rename keywords that are reserved in C++.
- schema_salad.cpp_codegen.safename(name)
Create a C++ safe name.
- schema_salad.cpp_codegen.safenamespacename(name)
Create a C++ safe name for namespaces.
- schema_salad.cpp_codegen.safename2(name)
Create a namespaced safename.
- schema_salad.cpp_codegen.split_name(s)
Split url name into its components.
Splits names like https://xyz.xyz/blub#cwl/class into its class path and non class path
- schema_salad.cpp_codegen.split_field(s)
Split field into its components.
similar to split_name but for field names
- class schema_salad.cpp_codegen.ClassDefinition(name)
Prototype of a class.
- Parameters:
name (str)
- fullName
- allfields: list[FieldDefinition] = []
- fields: list[FieldDefinition] = []
- abstract = False
- namespace
- classname
- writeFwdDeclaration(target, fullInd, ind)
Write forward declaration.
- writeDefinition(target, fullInd, ind, common_namespace)
Write definition of the class.
- class schema_salad.cpp_codegen.FieldDefinition(name, typeStr, optional, mapSubject, mapPredicate, typeDSL)
Prototype of a single field from a class definition.
- Parameters:
- name
- typeStr
- optional
- mapSubject
- mapPredicate
- typeDSL
- class schema_salad.cpp_codegen.MapDefinition(name, values)
Prototype of a map.
- values
- namespace
- classname
- writeFwdDeclaration(target, fullInd, ind)
Write forward declaration.
- writeDefinition(target, ind, common_namespace)
Write map definition to output.
- class schema_salad.cpp_codegen.UnionDefinition(name, types)
Prototype of a union.
- namespace
- classname
- types
- writeFwdDeclaration(target, fullInd, ind)
Write forward declaration.
- writeDefinition(target, ind, common_namespace)
Write union definition to output.
- class schema_salad.cpp_codegen.EnumDefinition(name, values)
Prototype of a enum.
- name
- values
- namespace
- classname
- schema_salad.cpp_codegen.isPrimitiveType(v)
Check if v is a primitve type.
- Parameters:
v (Any)
- Return type:
- schema_salad.cpp_codegen.hasFieldValue(e, f, v)
Check if e has a field f value.
- schema_salad.cpp_codegen.isRecordSchema(v)
Check if v is of type record schema.
- Parameters:
v (Any)
- Return type:
- schema_salad.cpp_codegen.isEnumSchema(v)
Check if v is of type enum schema.
- Parameters:
v (Any)
- Return type:
- schema_salad.cpp_codegen.isArray(v)
Check if v is of type array.
- Parameters:
v (Any)
- Return type:
- schema_salad.cpp_codegen.pred(i)
Check if v is any of the simple types.
- Parameters:
i (Any)
- Return type:
- schema_salad.cpp_codegen.isArraySchema(v)
Check if v is of type array schema.
- Parameters:
v (Any)
- Return type:
- schema_salad.cpp_codegen.isMapSchema(v)
Check if v is of type map schema.
- Parameters:
v (Any)
- Return type:
- schema_salad.cpp_codegen.isUnionSchema(v)
Check if v is of type union schema.
- Parameters:
v (Any)
- Return type:
- class schema_salad.cpp_codegen.CppCodeGen(base, target, examples, package, copyright, spdx_copyright_text, spdx_license_identifier)
Bases:
digraph inheritanceb32d88fe87 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "CodeGenBase" [URL="../codegen_base/index.html#schema_salad.codegen_base.CodeGenBase",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Abstract base class for schema salad code generators."]; "CppCodeGen" [URL="#schema_salad.cpp_codegen.CppCodeGen",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Generation of C++ code for a given Schema Salad definition."]; "CodeGenBase" -> "CppCodeGen" [arrowsize=0.5,style="setlinewidth(0.5)"]; }schema_salad.codegen_base.CodeGenBase
Generation of C++ code for a given Schema Salad definition.
- Parameters:
- base_uri
- target
- examples
- package
- copyright
- spdx_copyright_text
- spdx_license_identifier
- classDefinitions: dict[str, ClassDefinition]
- enumDefinitions: dict[str, EnumDefinition]
- mapDefinitions: dict[str, MapDefinition]
- unionDefinitions: dict[str, UnionDefinition]
- documentRootTypes: list[ClassDefinition] = []
- convertTypeToCpp(type_declaration)
Convert a Schema Salad type to a C++ type.
- epilogue(root_loader)
Trigger to generate the epilouge code.
- Parameters:
root_loader (Optional[schema_salad.codegen_base.TypeDef])
- Return type:
None
- parseRecordField(field)
Parse a record field.
- Parameters:
- Return type:
- parseRecordSchema(stype)
Parse a record schema.