-
Notifications
You must be signed in to change notification settings - Fork 10
MacroPropertyCodeGen
The MacroPropertyCodeGen
inherits from the PropertyCodeGen class.
To create a new MacroPropertyCodeGen
, you must inherit from MacroPropertyCodeGen
instead of PropertyCodeGen
:
#include <Kodgen/CodeGen/Macro/MacroPropertyCodeGen.h>
class ExamplePCG : public kodgen::MacroPropertyCodeGen
{
};
Same as PropertyCodeGen::getGenerationOrder.
Same as PropertyCodeGen::shouldGenerateCode.
The initialGenerateCode
method is sealed in the MacroPropertyCodeGen
implementation. Instead, 3 methods are called once to initially generate code in each location:
initialGenerateHeaderFileHeaderCode
initialGenerateHeaderFileFooterCode
initialGenerateSourceFileHeaderCode
bool initialGenerateHeaderFileHeaderCode(kodgen::MacroCodeGenEnv& env, std::string& inout_result) noexcept override
{
//Generate code at the beginning of the generated header file header
//...
return true;
}
The finalGenerateCode
method is sealed in the MacroPropertyCodeGen
implementation. Instead, 3 methods are called once to generate code in each location:
finalGenerateHeaderFileHeaderCode
finalGenerateHeaderFileFooterCode
finalGenerateSourceFileHeaderCode
bool finalGenerateHeaderFileHeaderCode(kodgen::MacroCodeGenEnv& env, std::string& inout_result) noexcept override
{
//Generate code at the end of the generated header file header
//...
return true;
}
Called once before generating code for an eligible entity/property pair. Returns false to abort the code generation for the running CodeGenUnit
.
bool preGenerateCodeForEntity(kodgen::EntityInfo const& entity, kodgen::Property const& property, kodgen::uint8 propertyIndex, kodgen::MacroCodeGenEnv& env) noexcept override
{
//Do some stuff
return true; //return false if you want to abort the code generation for the running unit
}
Called once after generating code for an entity/property pair. Returns false to abort the code generation for the running CodeGenUnit.
bool preGenerateCodeForEntity(kodgen::EntityInfo const& entity, kodgen::Property const& property, kodgen::uint8 propertyIndex, kodgen::MacroCodeGenEnv& env) noexcept override
{
//Do some stuff
return true; //return false if you want to abort the code generation for the running unit
}
This method generates code for the attached entity in the HeaderFileHeader location (see this section for more info about code generation locations). Returns false to abort the code generation for the running CodeGenUnit.
bool generateHeaderFileHeaderCodeForEntity(kodgen::EntityInfo const& entity, kodgen::Property const& property, kodgen::uint8 propertyIndex, kodgen::MacroCodeGenEnv& env, std::string& inout_result) noexcept override
{
//TODO: Append generated code to inout_result here
return true; //or return false if failure + abort
}
This method generates code for the attached entity in the ClassFooter location (see this section for more info about code generation locations). Note that this method is called only for properties attached to structs, classes, or struct/class nested entities. Returns false to abort the code generation for the running CodeGenUnit.
bool generateClassFooterCodeForEntity(kodgen::EntityInfo const& entity, kodgen::Property const& property, kodgen::uint8 propertyIndex, kodgen::MacroCodeGenEnv& env, std::string& inout_result) noexcept override
{
//TODO: Append generated code to inout_result here
return true; //or return false if failure + abort
}
This method generates code for the attached entity in the HeaderFileFooter location (see this section for more info about code generation locations). Returns false to abort the code generation for the running CodeGenUnit.
bool generateHeaderFileFooterCodeForEntity(kodgen::EntityInfo const& entity, kodgen::Property const& property, kodgen::uint8 propertyIndex, kodgen::MacroCodeGenEnv& env, std::string& inout_result) noexcept override
{
//TODO: Append generated code to inout_result here
return true; //or return false if failure + abort
}
This method generates code for the attached entity in the SourceFileHeader location (see this section for more info about code generation locations). Returns false to abort the code generation for the running CodeGenUnit.
bool generateSourceFileHeaderCodeForEntity(kodgen::EntityInfo const& entity, kodgen::Property const& property, kodgen::uint8 propertyIndex, kodgen::MacroCodeGenEnv& env, std::string& inout_result) noexcept override
{
//TODO: Append generated code to inout_result here
return true; //or return false if failure + abort
}
You can use the MacroCodeGenEnv::getSeparator() method to insert spaces and generate human-readable (and more easily debuggable) code.
See this section for more details.