Library: CodeGeneration
Package: CodeGeneration
Header: Poco/CodeGeneration/GeneratorEngine.h
A GeneratorEngine iterates over a Struct and calls the correct methods in a CodeGenerator.
Member Functions: emptyCodeGen, generate, getBoolProperty, getStringProperty, getUInt32Property, handleIncludeFile, handleIncludes, parseElementProperties, parseProperties, registerCallback, registerDefaultCallback, registerPostClassCallback, registerPreClassCallback, unregisterCallback, unregisterDefaultCallback, unregisterPostClassCallback, unregisterPreClassCallback
typedef std::map < std::string, MethodGenerator > Callbacks;
typedef void (* MethodGenerator)(const Poco::CppParser::Function *, const Poco::CppParser::Struct *, CodeGenerator &, void * param);
Creates the GeneratorEngine.
~GeneratorEngine();
Destroys the GeneratorEngine.
static void emptyCodeGen(
const Poco::CppParser::Function * param1,
const Poco::CppParser::Struct * param2,
CodeGenerator & param3,
void * param
);
void generate(
const Poco::CppParser::Struct * pStruct,
CodeGenerator & gen,
void * addParam = 0,
bool isFirstClass = true,
bool isLastClass = true
);
Generates code for the given struct using the given CodeGenerator, addParam can be used to provide a pointer to additional information, required for the registered callbacks. If isFirstClass is true, the copyright header and the namespace begin is written, if isLastClass is true the namespace is closed.
static bool getBoolProperty(
const CodeGenerator::Properties & props,
const std::string & propName,
bool & value
);
Returns true if it finds for the given property name the attrValue, writes the found value to parameter value.
static bool getStringProperty(
const CodeGenerator::Properties & props,
const std::string & propName,
std::string & value
);
Returns true if it finds for the given property name the attrValue, writes the found value to parameter value.
static bool getUInt32Property(
const CodeGenerator::Properties & props,
const std::string & propName,
Poco::UInt32 & value
);
Returns true if it finds for the given property name the attrValue, writes the found value to parameter value.
static void handleIncludeFile(
const Poco::CppParser::Struct * pStruct,
const std::string & classDecl,
const std::string & defaultLibrary,
CodeGenerator & gen
);
Checks first the file in pStruct, then regenerates the include based on the classDecl
static void handleIncludes(
const Poco::CppParser::Struct * pStruct,
CodeGenerator & gen
);
Detects and handles all includes.
static void parseElementProperties(
const std::string & elemVal,
CodeGenerator::Properties & props
);
Parses and adds element properties in lower case to props. Element properties are properties defined for single parameters or variables
static void parseProperties(
const Poco::CppParser::Symbol * pSym,
CodeGenerator::Properties & props
);
Parses and adds properties in lower case to props.
void registerCallback(
const std::string & methodName,
MethodGenerator funcGen
);
Registers a callback for a method name if and only if no other callback is registered yet. Throws an exception in the latter case.
void registerDefaultCallback(
MethodGenerator funcGen
);
Registers a default callback, invoked always when no callback is found for a given methodname
void registerPostClassCallback(
MethodGenerator funcGen
);
Allows to register a code generator that will write code to the implementation file after the last method was written. Useful to initialize static members.
void registerPreClassCallback(
MethodGenerator funcGen
);
Allows to register a code generator that will write code to the implementation file before the first constructor is written. Useful to initialize static members. With templates the code will be written right after namespace_begin.
void unregisterCallback(
const std::string & methodName
);
Unregisters a callback.
void unregisterDefaultCallback();
Unregisters the default callback.
void unregisterPostClassCallback();
Unregisters the post class callback.
void unregisterPreClassCallback();
Unregisters the pre class callback.