The factory generator is a sub-project that helps reduce the time needed to create a new filter.
It is essentially a Python script that, from a configuration file, reads every item headers that the factory produces and then generates the factory header's includes and the factory.
In other words, no need to manually add newly created filters in the factory and factory header, simply run python generate.py located in the src/factory_generator folder of the project to update automatically the factory.
The only requirement for new filters is that they need to include (as a comment) a tag to identify the class name. That tag is configurable, but should be the same for all.
This is needed since class name often don't have the same name as the actual file.
The factory must specify a tag indicating the beginning and end of the instance creation area (aka the long if/else if where objects are created based on a string value).
The factory must specify a tag indicating the beginning and end of the filters list area (aka the list of filters separated with semi-colons).
Both tags are configurable.
This is needed so that the script knows where to insert generated values. Everything inside those area will be overwrited, will the rest will remain as is.
Base configuration for proc_image_processing is included in the repository, following is for reference
In order to reuse this sub-project elsewhere, most features of the Factory Generator are configurable. Configuration is possible by altering the conf.yml file located in the src/factory_generator folder.
Below is a table illustrating the role of every parameter (which are all mandatory):
| Parameter | Description | Type | Constraints | Default value |
|---|---|---|---|---|
project-path |
The project root path where the factory is located. | String. | Should be a valid path. | ../proc_image_processing |
factories |
The factories to generate, multiple factories can be generated at once! | List of objects. | Should contain at least one factory object. | |
tags |
The tags used in project files to define areas. | Object. |
Factory object:
| Parameter | Description | Type | Constraints | Default value |
|---|---|---|---|---|
name |
Name of the factory | String. | FilterFactory |
|
path |
The path (excluding filename) of the factory relative to the project-path. | String. | Should be a valid path. | /server |
items-path |
The path of the items produced by the factory. | String. | Should be a valid path. | /filters |
recurse |
Does the items-path need to be recursively scanned? | Boolean. | true |
|
filename |
The factory's filename. | String. | Should exist. | filter_factory.cc |
header-filename |
The factory's header filename. | String. | Should exist. | filter_factory.h |
equality-variable |
The variable name used to determine which item to create. | String. | name |
|
create-params |
The variables that are passed as parameters upon creation of an item. | List of string. | globalParams |
|
excluded-items |
The items that should be excluded from generation. Specify only filenames. | List of string. | filter.hfilter_inl.hsubtract_plane_adder.h |
Tags:
| Parameter | Description | Type | Constraints | Default value |
|---|---|---|---|---|
factory-header |
The tags related to the factory header. | Object with an attribute named includes-start and includes-end of type string. |
includes-start defines the beginning of the includes area in the factory header file, while includes-end specifies the end of that area. |
includes-start: <FACTORY_GENERATOR_HEADER_INCLUDES>includes-end: <FACTORY_GENERATOR_HEADER_INCLUDES/> |
factory |
The tags related to the factory. | Object with an attribute named list-start, list-end, create-start and create-end |
list-start defines the beginning of the list area in the factory file, while list-end indicates the end of it. create-start defines the beginning of the large if/else if area used to create object instances, while create-end indicates the end of it. |
list-start:<FACTORY_GENERATOR_ITEMS_LIST>list-end:<FACTORY_GENERATOR_ITEMS_LIST/>create-start:<FACTORY_GENERATOR_INSTANCE_CREATION>create-end:<FACTORY_GENERATOR_INSTANCE_CREATION/> |
item-headers |
The tags related to the item headers (aka what is being produced by the factory). | Object with an attribute named class-name and class-name-separator. |
class-name:FACTORY_GENERATOR_CLASS_NAMEclass-name-separator:= |