Skip to content

Code injection

Julien SOYSOUVANH edited this page Aug 7, 2021 · 6 revisions

Introduction

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;
  • In a class or struct;
  • At the bottom of a header file;
  • At the top of a source (.cpp) file;

To inject the generated code in our source files, 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 "top of a header file" location is injected here

class Class() Example
{
    Example_GENERATED //Code for the "class or struct" location is injected here
};

File_Example_GENERATED //Code for the "bottom of a header file" location is injected here
//Example.cpp
//Add any include here

#include "Generated/Example.src.h" //Code for the "top of a source file" location is injected here
//This generated file already includes Example.h so we don't have to write it

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: