schema_salad.cpp_codegen
========================

.. py:module:: schema_salad.cpp_codegen

.. autoapi-nested-parse::

   C++17 code generator for a given Schema Salad definition.

   Currently only supports emitting 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
-------

.. autoapisummary::

   schema_salad.cpp_codegen.ClassDefinition
   schema_salad.cpp_codegen.FieldDefinition
   schema_salad.cpp_codegen.MapDefinition
   schema_salad.cpp_codegen.UnionDefinition
   schema_salad.cpp_codegen.EnumDefinition
   schema_salad.cpp_codegen.CppCodeGen


Functions
---------

.. autoapisummary::

   schema_salad.cpp_codegen.q
   schema_salad.cpp_codegen.replaceKeywords
   schema_salad.cpp_codegen.safename
   schema_salad.cpp_codegen.safenamespacename
   schema_salad.cpp_codegen.safename2
   schema_salad.cpp_codegen.split_name
   schema_salad.cpp_codegen.split_field
   schema_salad.cpp_codegen.isPrimitiveType
   schema_salad.cpp_codegen.hasFieldValue
   schema_salad.cpp_codegen.isRecordSchema
   schema_salad.cpp_codegen.isEnumSchema
   schema_salad.cpp_codegen.isArray
   schema_salad.cpp_codegen.pred
   schema_salad.cpp_codegen.isArraySchema
   schema_salad.cpp_codegen.isMapSchema
   schema_salad.cpp_codegen.isUnionSchema


Module Contents
---------------

.. py:function:: q(s)

   Put quotes around a string.


.. py:function:: replaceKeywords(s)

   Rename keywords that are reserved in C++.


.. py:function:: safename(name)

   Create a C++ safe name.


.. py:function:: safenamespacename(name)

   Create a C++ safe name for namespaces.


.. py:function:: safename2(name)

   Create a namespaced safename.


.. py:function:: 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


.. py:function:: split_field(s)

   Split field into its components.

   similar to split_name but for field names


.. py:class:: ClassDefinition(name)

   Prototype of a class.


   .. py:attribute:: fullName


   .. py:attribute:: extends
      :type:  list[dict[str, str]]
      :value: []



   .. py:attribute:: specializationTypes
      :type:  list[str]
      :value: []



   .. py:attribute:: allfields
      :type:  list[FieldDefinition]
      :value: []



   .. py:attribute:: fields
      :type:  list[FieldDefinition]
      :value: []



   .. py:attribute:: abstract
      :value: False



   .. py:attribute:: namespace


   .. py:attribute:: classname


   .. py:method:: writeFwdDeclaration(target, fullInd, ind)

      Write forward declaration.



   .. py:method:: writeDefinition(target, fullInd, ind, common_namespace)

      Write definition of the class.



   .. py:method:: writeImplDefinition(target, fullInd, ind, common_namespace)

      Write definition with implementation.



.. py:class:: FieldDefinition(name, typeStr, optional, mapSubject, mapPredicate, typeDSL)

   Prototype of a single field from a class definition.


   .. py:attribute:: name


   .. py:attribute:: typeStr


   .. py:attribute:: optional


   .. py:attribute:: mapSubject


   .. py:attribute:: mapPredicate


   .. py:attribute:: typeDSL


   .. py:method:: writeDefinition(target, fullInd, ind, namespace)

      Write a C++ definition for the class field.



.. py:class:: MapDefinition(name, values)

   Prototype of a map.


   .. py:attribute:: values


   .. py:attribute:: namespace


   .. py:attribute:: classname


   .. py:method:: writeFwdDeclaration(target, fullInd, ind)

      Write forward declaration.



   .. py:method:: writeDefinition(target, ind, common_namespace)

      Write map definition to output.



   .. py:method:: writeImplDefinition(target, fullInd, ind, common_namespace)

      Write definition with implementation.



.. py:class:: UnionDefinition(name, types)

   Prototype of a union.


   .. py:attribute:: namespace


   .. py:attribute:: classname


   .. py:attribute:: types


   .. py:method:: writeFwdDeclaration(target, fullInd, ind)

      Write forward declaration.



   .. py:method:: writeDefinition(target, ind, common_namespace)

      Write union definition to output.



   .. py:method:: writeImplDefinition(target, fullInd, ind, common_namespace)

      Write definition with implementation.



.. py:class:: EnumDefinition(name, values)

   Prototype of a enum.


   .. py:attribute:: name


   .. py:attribute:: values


   .. py:attribute:: namespace


   .. py:attribute:: classname


   .. py:method:: writeDefinition(target, ind, common_namespace)

      Write enum definition to output.



.. py:function:: isPrimitiveType(v)

   Check if v is a primitive type.


.. py:function:: hasFieldValue(e, f, v)

   Check if e has a field f value.


.. py:function:: isRecordSchema(v)

   Check if v is of type record schema.


.. py:function:: isEnumSchema(v)

   Check if v is of type enum schema.


.. py:function:: isArray(v)

   Check if v is of type array.


.. py:function:: pred(i)

   Check if v is any of the simple types.


.. py:function:: isArraySchema(v)

   Check if v is of type array schema.


.. py:function:: isMapSchema(v)

   Check if v is of type map schema.


.. py:function:: isUnionSchema(v)

   Check if v is of type union schema.


.. py:class:: CppCodeGen(base, target, examples, package, copyright, spdx_copyright_text, spdx_license_identifier)

   Bases: :py:obj:`schema_salad.codegen_base.CodeGenBase`

   .. autoapi-inheritance-diagram:: schema_salad.cpp_codegen.CppCodeGen
      :parts: 1


   Generation of C++ code for a given Schema Salad definition.


   .. py:attribute:: base_uri


   .. py:attribute:: target


   .. py:attribute:: examples


   .. py:attribute:: package


   .. py:attribute:: copyright


   .. py:attribute:: spdx_copyright_text


   .. py:attribute:: spdx_license_identifier


   .. py:attribute:: classDefinitions
      :type:  dict[str, ClassDefinition]


   .. py:attribute:: enumDefinitions
      :type:  dict[str, EnumDefinition]


   .. py:attribute:: mapDefinitions
      :type:  dict[str, MapDefinition]


   .. py:attribute:: unionDefinitions
      :type:  dict[str, UnionDefinition]


   .. py:attribute:: documentRootTypes
      :type:  list[ClassDefinition]
      :value: []



   .. py:method:: convertTypeToCpp(type_declaration)

      Convert a Schema Salad type to a C++ type.



   .. py:method:: epilogue(root_loader)

      Trigger to generate the epilouge code.



   .. py:method:: parseRecordField(field)

      Parse a record field.



   .. py:method:: parseRecordSchema(stype)

      Parse a record schema.



   .. py:method:: parseMapSchema(stype)

      Parse a map schema.



   .. py:method:: parseUnionSchema(stype)

      Parse a union schema.



   .. py:method:: parseEnum(stype)

      Parse a schema salad enum.



   .. py:method:: parse(items)

      Parse sechema salad items.

      This function is being called from the outside and drives
      the whole code generation.



