Skip to content

CodeGenManager settings

Julien SOYSOUVANH edited this page Oct 29, 2021 · 6 revisions

Introduction

This section is here to provide a brief description of each of the available settings for the CodeGenManager class. Those settings are hinting the CodeGenManager about what files should be processed during the code generation. You can manipulate CodeGenManager settings through the CodeGenManagerSettings class, publicly accessible through a CodeGenManager instance as follows:

#include <Kodgen/CodeGen/CodeGenManager.h>

//...

kodgen::CodeGenManager codeGenMgr;
kodgen::CodeGenManagerSettings& settings = codeGenMgr.settings;

//Do stuff with settings here

CodeGenManagerSettings

CodeGenManagerSettings::_toProcessFiles

Collection of (absolute or relative to the working directory) paths to files that must be processed by the CodeGenManager. All files contained there will be processed no matter what other settings are.
Use the addToProcessFile, removeToProcessFile, clearToProcessFiles and getToProcessFiles methods to set the collection.

settings.addToProcessFile("path/to/someFile.h"); //Add a file for code generation
settings.removeToProcessFile("path/to/someFile.h"); //Remove the file we've just added... interesting
settings.clearToProcessFiles(); //Remove all files from the collection

//In case you want to inspect processed files
settings.getToProcessFiles();

Note that only valid files can be added through the addToProcessFile method, so you won't be able to add non-existing or invalid files. You might check the returned boolean value to make sure the file was successfully added.

CodeGenManagerSettings::_toProcessDirectories

Collection of (absolute or relative to the working directory) paths to directories that must be processed by the CodeGenManager. Directories are recursively processed, which means that all directories and files contained in processed directories are also considered for processing. Subdirectories contained in the _ignoredDirectories collection will not be processed. Ultimately, only files that are not part of _ignoredFiles and have a valid extension (see _supportedExtensions) are forwarded to the code generation process.
Use the addToProcessDirectory, removeToProcessDirectory, clearToProcessDirectories and getToProcessDirectories methods to set the collection.

settings.addToProcessDirectory("path/to/some/directory"); //Add a directory to process
settings.removeToProcessDirectory("path/to/some/directory"); //Remove the directory we've just added... interesting
settings.clearToProcessDirectories(); //Remove all directories from the collection

//In case you want to inspect processed directories
settings.getToProcessDirectories();

Note that only valid directories can be added through the addToProcessDirectory method, so you won't be able to add non-existing or invalid directories. You might check the returned boolean value to make sure the directory was successfully added.

CodeGenManagerSettings::_ignoredFiles

Collection of (absolute or relative to the working directory) paths to files that must be ignored (skipped) by the CodeGenManager. All files contained there will be ignored, except if they are also contained in the _toProcessFiles collection (which makes no sense).
Use the addIgnoredFile, removeIgnoredFile, clearIgnoredFiles and getIgnoredFiles methods to set the collection.

settings.addIgnoredFile("path/to/someFile.h"); //Add a file to ignore
settings.removeIgnoredFile("path/to/someFile.h"); //Remove the file we've just added... interesting
settings.clearIgnoredFiles(); //Remove all files from the collection

//In case you want to inspect ignored files
settings.getIgnoredFiles();

Note that only valid files can be added through the addIgnoredFile method, so you won't be able to add non-existing or invalid files. You might check the returned boolean value to make sure the file was successfully added.

CodeGenManagerSettings::_ignoredDirectories

Collection of (absolute or relative to the working directory) paths to directories that must be ignored (skipped) by the CodeGenManager. This setting comes in handy when you want to skip _toProcessDirectories subdirectories.
Use the addIgnoredDirectory, removeIgnoredDirectory, clearIgnoredDirectories and getIgnoredDirectories methods to set the collection.

settings.addIgnoredDirectory("path/to/some/directory"); //Add a directory to ignore
settings.removeIgnoredDirectory("path/to/some/directory"); //Remove the directory we've just added... interesting
settings.clearIgnoredDirectories(); //Remove all directories from the collection

//In case you want to inspect ignored directories
settings.getIgnoredDirectories();

Note that only valid directories can be added through the addIgnoredDirectory method, so you won't be able to add non-existing or invalid directories. You might check the returned boolean value to make sure the directory was successfully added.

CodeGenManagerSettings::_supportedExtensions

Collection of all valid file extensions. Only files contained in _toProcessDirectories and having one of these extensions will be processed. Provided extensions must start with a '.'.
Use the addSupportedExtension, removeSupportedExtension, clearSupportedExtensions and getSupportedExtensions methods to set the collection.

settings.addSupportedExtension(".hpp"); //Add a valid file extension
settings.removeSupportedExtension(".hpp"); //Remove the extension we've just added... interesting
settings.clearSupportedExtensions(); //Remove all extensions from the collection

//In case you want to inspect valid extensions
settings.getSupportedExtensions();

Example

Let's consider a typical project hierarchy:

ProjectRoot/
└── include/
|    |  Header1.h
|    |  Header2.hpp
|    |
|    └── generated/
|    |    |  GeneratedFile.h
|    └── tests/
|    |    |  Header3.h
|    |    |  IgnoreThisHeader.h
|
└── source/
|    |  Header1.cpp

Let's consider that ProjectRoot/ is the working directory. With that assumption, all paths can be given relative to ProjectRoot/.
We setup our settings like this:

settings.addSupportedExtension(".h");
settings.addToProcessDirectory("include");
settings.addIgnoredDirectory("include/generated");
settings.addIgnoredFile("include/tests/IgnoreThisHeader.h");

With that configuration, the CodeGenManager will behave as follows:

  1. Enter include directory
  2. Header1.h has a supported extension and is not ignored --> process
  3. Header2.hpp doesn't have a supported extension --> ignore
  4. include/generated is an ignored directory --> ignore
  5. Enter include/tests
  6. Header3.h has a supported extension and is not ignored --> process
  7. IgnoreThisHeader.h has a supported extension but is ignored --> ignore

Load settings from a TOML file

All settings can be loaded from a TOML file with a call to the "loadFromFile" method:

settings.loadFromFile("path/to/your/settingsfile.toml"); //absolute or working directory relative path

A copy of the TOML file is available in the project and the pre-compiled binaries. You can of course remove the settings you don't use. Settings that are not present will conserve their current value.
For the example, let's see how previously presented settings would look like in a TOML file:

[CodeGenManagerSettings]
supportedFileExtensions = [".h"]

toProcessDirectories = [
'''include'''
]

ignoredDirectories = [
'''include/generated'''
]

toProcessFiles = []

ignoredFiles = [
'''include/tests/IgnoreThisHeader.h'''
]

Note: Paths must be enclosed between '''.