-
Notifications
You must be signed in to change notification settings - Fork 10
Code injection
The code injection extension allows a user to generate code to inject in different locations of the parsed C++ source code. The code is generated inside macros that are used in the parsed files. It is possible to generate and inject code in 4 different locations:
- At the top of a header file (HeaderFileHeader);
- In a class or struct (ClassFooter);
- At the bottom of a header file (HeaderFileFooter);
- At the top of a source (.cpp) file (SourceFileHeader);
The MacroCodeGenUnit will generate 2 files, which must be included respectively in our header and source files.
To inject the generated code, we would write something like this:
//Example.h
#pragma once
//Add any include here
//At the end, include the generated header file
#include "Generated/Example.h.h" //Code for the HeaderFileHeader location is injected here
class Class() Example
{
Example_GENERATED //Code for the ClassFooter location is injected here
};
File_Example_GENERATED //Code for the HeaderFileFooter location is injected here
//Example.cpp
//Add any include here
#include "Generated/Example.src.h" //Code for the SourceFileHeader location is injected here
//This generated file already includes Example.h so we don't have to write it
Note: To lighten our files, it is possible to omit the generated ClassFooter macro, HeaderFileFooter macro, and the SourceFileHeader file include if we know they don't contain any generated code. However, we will need to add the macros/file includes if code is generated for these locations later on.
This extension contains a few new classes built over the base framework. Those classes introduce a set of new rules that we are going to introduce in this section: