CMG documentation
C++ model generation API documentation.
A schema used to define the structure of the data in a model.
- class cmg.schema.Field(name: str, description: str, type: str, example: Any | None = None, default: Any | None = None, parent: str | None = None, is_child: bool = False, is_list: bool = False, is_optional: bool = False)
A field used to define the structure of the data in a model.
- Attributes:
name (str): The name of the field.
description (str): The description of the field.
type (str): The type of the field.
example (Any): The example value of the field.
default (Optional[Any]): The default value of the field.
parent (Optional[str]): The parent of the field.
is_child (bool): Whether the field is a child.
is_list (bool): Whether the field is a list.
is_optional (bool): Whether the field is optional.
- get_cpp_type(nolist=False, cast=False) str
Get the C++ type for the field.
- Args:
nolist (bool): Whether to exclude list types. cast (bool): Whether to cast the type.
- Returns:
str: The C++ type.
- get_example() Any
Get the example value for the field.
- Returns:
Any: The example value.
- has_default() bool
Check if the field has a default value.
- Returns:
bool: True if the field has a default value, False otherwise.
- has_parent() bool
Check if the field has a parent.
- Returns:
bool: True if the field has a parent, False otherwise.
- is_reference() bool
Check if the field is a reference.
- Returns:
bool: True if the field is a reference, False otherwise.
- Raises:
ValueError: If the class or schema is not linked.
- to_camel_case(upper_first=False) str | None
Convert the field name to camelCase.
- Args:
upper_first (bool): Whether to capitalize the first letter.
- Returns:
str: The field name in camelCase.
- class cmg.schema.Klass(name: str, description: str, fields: ~typing.List[~cmg.schema.Field] = <factory>)
A class used to define the structure of the data in a model.
- Attributes:
name (str): The name of the class.
description (str): The description of the class.
fields (List[Field]): The fields in the class.
- get_create_arguments() str
Get the create arguments for the class.
- Returns:
str: The create arguments.
- get_create_ptr_type() str
Get the create pointer type for the class.
- Returns:
str: The create pointer type.
- get_example_arguments() str
Get the example arguments for the class.
- Returns:
str: The example arguments.
- get_example_update_arguments() str
Get the example update arguments for the class.
- Returns:
str: The example update arguments.
- get_forward_declarations() List[str]
Get the forward declarations for the class.
- Returns:
List[str]: The forward declarations.
- get_forward_includes() List[str]
Get the forward includes for the class.
- Returns:
List[str]: The forward includes.
- get_include_define() str
Get the include define for the class.
- Returns:
str: The include define.
- get_ordered_fields()
Get the ordered fields for the class.
- Returns:
List[Field]: The ordered fields.
- get_parent_field() Field
Get the parent field for the class.
- Returns:
Field: The parent field.
- Raises:
ValueError: If no parent field is found.
- get_parent_fields() List[Field]
Get the parent fields for the class.
- Returns:
List[Field]: The parent fields.
- get_updatable_fields()
Get the updatable fields for the class.
- Returns:
List[Field]: The updatable fields.
- get_var_name() str
Get the variable name for the class.
- Returns:
str: The variable name.
- has_parent() bool
Check if the class has a parent.
- Returns:
bool: True if the class has a parent, False otherwise.
- init_fields(parents=True) List[Field]
Initialize the fields for the class.
- Args:
parents (bool): Whether to include parent fields.
- Returns:
List[Field]: The initialized fields.
- is_root() bool
Check if the class is the root klass.
- Returns:
bool: True if the class is the root klass, False otherwise.
- link() None
Link the class to its fields and schema.
- to_snake_case() str
Convert the class name to snake_case.
- Returns:
str: The class name in snake_case.
- class cmg.schema.Schema(name: str, description: str, namespace: str, version: str, classes: ~typing.List[~cmg.schema.Klass] = <factory>)
A schema used to define the structure of the data in a model.
- Attributes:
name (str): The name of the schema.
description (str): The description of the schema.
namespace (str): The namespace of the schema.
classes (List[Klass]): The classes in the schema.
- get_cmakelists_src() str
Get the source files for the CMakeLists.txt file.
- Returns:
str: The source files.
- get_field(klass_name: str, field_name: str) Field
Get a field by klass and field name.
- Args:
klass_name (str): The name of the klass. field_name (str): The name of the field.
- Returns:
Field: The field.
- Raises:
ValueError: If the field is not found.
- get_klass(name: str) Klass
Get a klass by name.
- Args:
name (str): The name of the klass.
- Returns:
Klass: The klass.
- Raises:
ValueError: If the klass is not found.
- get_lcov_src() str
Get the source files for the lcov command.
- Returns:
str: The source files.
- get_root_klass() Klass
Get the root klass for the schema.
- Returns:
Klass: The root klass.
- Raises:
ValueError: If no root klass is found.
- get_supplementary_klasses()
Get the supplementary sources for the schema.
- Returns:
List[str]: The supplementary sources.
- get_test_includes() List[str]
Get the include statements for the test file.
- Returns:
List[str]: A list of include statements for each class in the test file.
- link() None
Link the schema to its classes and fields.
- set_output_dir(output_dir: str) None
Set the output directory for the schema.
- Args:
output_dir (str): The output directory.
- cmg.schema.to_camel_case(name: str | None, upper_first=False) str | None
Convert a snake_case string to camelCase.
- Args:
name (str): The name to convert. upper_first (bool): Whether to capitalize the first letter.
- Returns:
str: The name in camelCase.
- cmg.schema.to_snake_case(name: str) str
Convert a camelCase or PascalCase string to snake_case.
- Args:
name (str): The name to convert.
- Returns:
str: The name in snake_case.