![]() |
|
PhoenixGenerator
3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
|
#include <sstream>#include "phoenix_color.h"#include "openFileStream.h"#include "header_generator.h"#include "cmakelist_generator.h"#include "type_utils.h"#include "generator_class_cpp.h"Go to the source code of this file.
Functions | |
| void | class_checkClassConfig (bool &hasSource, bool &hasTemplate, const std::vector< PClassConfig > &vecClassConfig) |
| Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated. | |
| PString | class_getAttributeDefaultInit (const PClassAttribute &attr) |
| Get the in-class default member initialiser of an attribute (eg "{0}"), or an empty PString if the attribute doesn't need one. | |
| PString | class_getClassDeclTempalteDef (const PVecString &listTemplate) |
| Get the template definition in the class declaration. | |
| PString | class_getClassDefTemplate (const PVecString &listTemplate) |
| Get the template call in the class declaration. | |
| bool | class_hasPointerAttribute (const PClassConfig &classConfig) |
| Check if the given class owns at least one pointer attribute. | |
| void | class_savePointerOwnershipSpecialMembersImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration) |
| Saves the destructor, copy constructor/assignment and move constructor/assignment of a class owning at least one raw pointer attribute. | |
| bool | generator_checkDefaultValueExist (const std::vector< PClassAttribute > &vecAttr) |
| Check if the vector of PClassAttribute has default value. | |
| bool | generator_class_cpp (const PTraitBackendManager &manager, const std::vector< PClassConfig > &vecClassConfig, const PPath &outputSourceDir, const PPath &baseFileName, const GeneratorMode &mode, const PVecPath &vecInclude) |
| Creates header and source files. | |
| void | generator_class_cpp_header (const PTraitBackendManager &manager, std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) |
| Create the declaration of the given class. | |
| bool | generator_class_cpp_headerFile (const PTraitBackendManager &manager, const PPath &headerFile, const std::vector< PClassConfig > &vecClassConfig, const GeneratorMode &mode, const PVecPath &vecInclude, const PString &includeTemplate) |
| Create the declaration of the given class. | |
| void | generator_class_cpp_source (const PTraitBackendManager &manager, std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) |
| Create the implementation of the given class. | |
| bool | generator_class_cpp_sourceFile (const PTraitBackendManager &manager, const PPath &sourceFile, const PPath &headerFile, const std::vector< PClassConfig > &vecClassConfig, const GeneratorMode &mode, bool isTemplateImpl) |
| Create the implementation of the given file. | |
| bool | generator_class_cpp_test (const PTraitBackendManager &manager, const PPath &outputTestDir, const std::vector< PClassConfig > &vecClassConfig, const PString &projectName, const PPath &baseFileName, const GeneratorMode &mode) |
| Save the unit test of the generated PClassConfig. | |
| bool | generator_class_full (const PTraitBackendManager &manager, const ProjectParam &projectParam) |
| Generate the full sources and related unit tests from configuration. | |
| bool | generator_class_test (const PTraitBackendManager &manager, const PPath &outputTestDir, const PClassConfig &classConfig, const PString &projectName, const PPath &baseFileName, const GeneratorMode &mode) |
| Save the unit test of the generated PClassConfig. | |
| bool | generator_class_testCMakeLists (const PPath &outputCurrentTestDir, const PClassConfig &classConfig, const PString &projectName, const GeneratorMode &mode) |
| Save the CMakeLists to be used to compile the unit test. | |
| bool | generator_class_testMain (const PTraitBackendManager &manager, const PPath &outputCurrentTestDir, const PClassConfig &classConfig, const PPath &baseFileName, const GeneratorMode &mode) |
| Save the CMakeLists to be used to compile the unit test. | |
| void | generator_enum_cpp_header (const PTraitBackendManager &manager, std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) |
| Create the declaration of the given class. | |
| void class_checkClassConfig | ( | bool & | hasSource, |
| bool & | hasTemplate, | ||
| const std::vector< PClassConfig > & | vecClassConfig ) |
Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated.
| [out] | hasSource | : true if the configuration needs .cpp file |
| [out] | hasTemplate | : true if the configuration needs _impl.h file |
| vecClassConfig | : class config we want to save |
Definition at line 449 of file generator_class_cpp.cpp.
References class_checkClassConfig().
Referenced by class_checkClassConfig(), and generator_class_cpp().
| PString class_getAttributeDefaultInit | ( | const PClassAttribute & | attr | ) |
Get the in-class default member initialiser of an attribute (eg "{0}"), or an empty PString if the attribute doesn't need one.
| attr | : attribute to be checked |
Definition at line 66 of file generator_class_cpp.cpp.
References class_getAttributeDefaultInit(), PClassAttribute::getDefaultValue(), getDefaultValueTypeInCpp(), getIsPointerType(), and PClassAttribute::getType().
Referenced by class_getAttributeDefaultInit(), and generator_class_cpp_header().
| PString class_getClassDeclTempalteDef | ( | const PVecString & | listTemplate | ) |
Get the template definition in the class declaration.
| listTemplate | : list of template def |
Definition at line 49 of file generator_class_cpp.cpp.
References class_getClassDeclTempalteDef().
Referenced by class_getClassDeclTempalteDef(), generator_class_cpp_header(), and generator_class_cpp_source().
| PString class_getClassDefTemplate | ( | const PVecString & | listTemplate | ) |
Get the template call in the class declaration.
| listTemplate | : list of template def |
Definition at line 31 of file generator_class_cpp.cpp.
References class_getClassDefTemplate().
Referenced by class_getClassDefTemplate(), generator_class_cpp_header(), and generator_class_cpp_source().
| bool class_hasPointerAttribute | ( | const PClassConfig & | classConfig | ) |
Check if the given class owns at least one pointer attribute.
| classConfig | : PClassConfig to be checked |
Definition at line 19 of file generator_class_cpp.cpp.
References class_hasPointerAttribute(), getIsPointerType(), and PClassConfig::getListAttribute().
Referenced by class_hasPointerAttribute(), class_savePointerOwnershipSpecialMembersImpl(), generator_class_cpp_header(), and generator_class_cpp_sourceFile().
| void class_savePointerOwnershipSpecialMembersImpl | ( | std::ofstream & | fs, |
| const PClassConfig & | classConfig, | ||
| const PString & | defTemplate, | ||
| const PString & | templateDeclaration ) |
Saves the destructor, copy constructor/assignment and move constructor/assignment of a class owning at least one raw pointer attribute.
A class with a raw pointer attribute cannot rely on the compiler-generated (=default) special members : the default copy/move would only copy the pointer value (shallow copy), leading to double-delete once the hand-written destructor frees it. Per the rule of five, all five special members (destructor, copy ctor/assign, move ctor/assign) are generated by hand for these classes.
| [out] | fs | : header file name |
| classConfig | : PClassConfig we vant to save | |
| defTemplate | : extra template definition for the class name space | |
| templateDeclaration | : basic template declaration before each method (template< ... >) |
Destructor
Copy constructor
Copy assignment operator
Copy helper, reused by the copy constructor and the copy assignment operator
Move constructor
Move assignment operator
Move helper, reused by the move constructor and the move assignment operator
Definition at line 96 of file generator_class_cpp.cpp.
References class_hasPointerAttribute(), class_savePointerOwnershipSpecialMembersImpl(), getIsPointerType(), PClassConfig::getListAttribute(), and PClassConfig::getName().
Referenced by class_savePointerOwnershipSpecialMembersImpl(), and generator_class_cpp_source().
| bool generator_checkDefaultValueExist | ( | const std::vector< PClassAttribute > & | vecAttr | ) |
Check if the vector of PClassAttribute has default value.
| vecAttr | : vector of attribute to be checked |
Definition at line 79 of file generator_class_cpp.cpp.
References generator_checkDefaultValueExist().
Referenced by generator_checkDefaultValueExist(), and generator_enum_cpp_header().
| bool generator_class_cpp | ( | const PTraitBackendManager & | manager, |
| const std::vector< PClassConfig > & | vecClassConfig, | ||
| const PPath & | outputSourceDir, | ||
| const PPath & | baseFileName, | ||
| const GeneratorMode & | mode, | ||
| const PVecPath & | vecInclude ) |
Creates header and source files.
| manager | : PTraitBackendManager which handles all trait backend |
| vecClassConfig | : vector of class config we want to save |
| baseFileName | : base file name for header or source file |
| outputSourceDir | : output directory where to save sources |
| mode | : all modes of the generator (data/check/type/config stream) |
Definition at line 467 of file generator_class_cpp.cpp.
References class_checkClassConfig(), generator_class_cpp(), generator_class_cpp_headerFile(), and generator_class_cpp_sourceFile().
Referenced by generator_class_cpp(), and generator_class_full().
| void generator_class_cpp_header | ( | const PTraitBackendManager & | manager, |
| std::ofstream & | fs, | ||
| const PClassConfig & | classConfig, | ||
| const GeneratorMode & | mode ) |
Create the declaration of the given class.
| manager | : PTraitBackendManager which handles all trait backend | |
| [out] | fs | : file to be completed |
| classConfig | : configuration of the class to be used | |
| mode | : mode of the generator |
Definition at line 245 of file generator_class_cpp.cpp.
References class_getAttributeDefaultInit(), class_getClassDeclTempalteDef(), class_getClassDefTemplate(), class_hasPointerAttribute(), PTraitBackendManager::classExtraFunctionDeclaration(), GeneratorMode::defTemplate, generator_class_cpp_header(), PClassConfig::getClassDocumentation(), PClassConfig::getListAttribute(), PClassConfig::getListParentClass(), PClassConfig::getListTemplate(), PClassConfig::getName(), PClassConfig::getNamespace(), PTraitBackendManager::privateMethodDeclaration(), PTraitBackendManager::protectedMethodDeclaration(), PTraitBackendManager::publicMethodDeclaration(), and GeneratorMode::templateDeclaration.
Referenced by generator_class_cpp_header(), and generator_class_cpp_headerFile().
| bool generator_class_cpp_headerFile | ( | const PTraitBackendManager & | manager, |
| const PPath & | headerFile, | ||
| const std::vector< PClassConfig > & | vecClassConfig, | ||
| const GeneratorMode & | mode, | ||
| const PVecPath & | vecInclude, | ||
| const PString & | includeTemplate ) |
Create the declaration of the given class.
| manager | : PTraitBackendManager which handles all trait backend |
| headerFile | : file to be saved |
| vecClassConfig | : configuration of the class to be used |
| mode | : mode of the generator |
| vecInclude | : vector of include files to be added into the header |
| includeTemplate | : extra include for the template implementation |
Definition at line 335 of file generator_class_cpp.cpp.
References generator_class_cpp_header(), generator_class_cpp_headerFile(), generator_enum_cpp_header(), PTraitBackendManager::headerExtraInclude(), licenceSave(), and makeMultiIncludeDefineMacro().
Referenced by generator_class_cpp(), and generator_class_cpp_headerFile().
| void generator_class_cpp_source | ( | const PTraitBackendManager & | manager, |
| std::ofstream & | fs, | ||
| const PClassConfig & | classConfig, | ||
| const GeneratorMode & | mode ) |
Create the implementation of the given class.
| manager | : PTraitBackendManager which handles all trait backend | |
| [out] | fs | : file to be completed |
| classConfig | : configuration of the class to be used | |
| mode | : mode of the generator |
Definition at line 378 of file generator_class_cpp.cpp.
References class_getClassDeclTempalteDef(), class_getClassDefTemplate(), class_savePointerOwnershipSpecialMembersImpl(), PTraitBackendManager::classExtraFunctionImplementation(), GeneratorMode::defTemplate, generator_class_cpp_source(), PClassConfig::getIsEnum(), PClassConfig::getListTemplate(), PTraitBackendManager::privateMethodImplementation(), PTraitBackendManager::protectedMethodImplementation(), PTraitBackendManager::publicMethodImplementation(), and GeneratorMode::templateDeclaration.
Referenced by generator_class_cpp_source(), and generator_class_cpp_sourceFile().
| bool generator_class_cpp_sourceFile | ( | const PTraitBackendManager & | manager, |
| const PPath & | sourceFile, | ||
| const PPath & | headerFile, | ||
| const std::vector< PClassConfig > & | vecClassConfig, | ||
| const GeneratorMode & | mode, | ||
| bool | isTemplateImpl ) |
Create the implementation of the given file.
| manager | : PTraitBackendManager which handles all trait backend |
| sourceFile | : source file to be saved |
| headerFile | : header to be used with this source file |
| vecClassConfig | : vector of configuration of the classes to be used |
| mode | : mode of the generator |
| isTemplateImpl | : true to activate |
Definition at line 403 of file generator_class_cpp.cpp.
References class_hasPointerAttribute(), generator_class_cpp_source(), generator_class_cpp_sourceFile(), licenceSave(), and makeMultiIncludeDefineMacro().
Referenced by generator_class_cpp(), and generator_class_cpp_sourceFile().
| bool generator_class_cpp_test | ( | const PTraitBackendManager & | manager, |
| const PPath & | outputTestDir, | ||
| const std::vector< PClassConfig > & | vecClassConfig, | ||
| const PString & | projectName, | ||
| const PPath & | baseFileName, | ||
| const GeneratorMode & | mode ) |
Save the unit test of the generated PClassConfig.
| manager | : PTraitBackendManager which handles all trait backend |
| outputTestDir | : output directory where to put the generated test (typically ../TESTS if the program is called from ./src) |
| vecClassConfig | : vector of class configuration to be used |
| projectName | : configuration of the project |
| baseFileName | : base of output file name of the generated sources |
| mode | : all modes of the generator (data/check/type/config stream) |
Definition at line 578 of file generator_class_cpp.cpp.
References generator_class_cpp_test(), generator_class_test(), and getCMakeListsHeader().
Referenced by generator_class_cpp_test(), and generator_class_full().
| bool generator_class_full | ( | const PTraitBackendManager & | manager, |
| const ProjectParam & | projectParam ) |
Generate the full sources and related unit tests from configuration.
| manager | : PTraitBackendManager which handles all trait backend |
| projectParam | : description of classes and how and where to generate sources and test |
Definition at line 598 of file generator_class_cpp.cpp.
References generator_class_cpp(), generator_class_cpp_test(), generator_class_full(), getCMakeListsHeader(), ProjectParam::mode, ProjectParam::name, ProjectParam::outputSourceDir, ProjectParam::outputTestDir, and ProjectParam::vecDataConfig.
Referenced by generateCppClassesFull(), and generator_class_full().
| bool generator_class_test | ( | const PTraitBackendManager & | manager, |
| const PPath & | outputTestDir, | ||
| const PClassConfig & | classConfig, | ||
| const PString & | projectName, | ||
| const PPath & | baseFileName, | ||
| const GeneratorMode & | mode ) |
Save the unit test of the generated PClassConfig.
| manager | : PTraitBackendManager which handles all trait backend |
| outputTestDir | : output directory where to put the genreated test (typically ../TESTS if the program is called from ./src) |
| classConfig | : class configuration to be used |
| projectName | : configuration of the project |
| baseFileName | : base of output file name of the generated sources |
| mode | : all modes of the generator (data/check/type/config stream) |
Definition at line 558 of file generator_class_cpp.cpp.
References generator_class_test(), generator_class_testCMakeLists(), generator_class_testMain(), and PClassConfig::getName().
Referenced by generator_class_cpp_test(), and generator_class_test().
| bool generator_class_testCMakeLists | ( | const PPath & | outputCurrentTestDir, |
| const PClassConfig & | classConfig, | ||
| const PString & | projectName, | ||
| const GeneratorMode & | mode ) |
Save the CMakeLists to be used to compile the unit test.
| outputCurrentTestDir | : current test directory in which to create the CMakeLists.txt |
| classConfig | : class configuration to be used |
| projectName | : configuration of the project |
| mode | : all modes of the generator (data/check/type/config stream) |
Definition at line 536 of file generator_class_cpp.cpp.
References generator_class_testCMakeLists(), getCMakeListsHeader(), and PClassConfig::getName().
Referenced by generator_class_test(), and generator_class_testCMakeLists().
| bool generator_class_testMain | ( | const PTraitBackendManager & | manager, |
| const PPath & | outputCurrentTestDir, | ||
| const PClassConfig & | classConfig, | ||
| const PPath & | baseFileName, | ||
| const GeneratorMode & | mode ) |
Save the CMakeLists to be used to compile the unit test.
| manager | : PTraitBackendManager which handles all trait backend |
| outputCurrentTestDir | : current test directoru in which to create the CMakeLists.txt |
| classConfig | : class configuration to be used |
| baseFileName | : base of output file name of the generated sources |
| mode | : all modes of the generator (data/check/type/config stream) |
Definition at line 509 of file generator_class_cpp.cpp.
References GeneratorMode::assertInclude, generator_class_testMain(), PClassConfig::getNamespace(), licenceSave(), PTraitBackendManager::testCallFunction(), and PTraitBackendManager::testFunction().
Referenced by generator_class_test(), and generator_class_testMain().
| void generator_enum_cpp_header | ( | const PTraitBackendManager & | manager, |
| std::ofstream & | fs, | ||
| const PClassConfig & | classConfig, | ||
| const GeneratorMode & | mode ) |
Create the declaration of the given class.
| manager | : PTraitBackendManager which handles all trait backend | |
| [out] | fs | : file to be completed |
| classConfig | : configuration of the class to be used | |
| mode | : mode of the generator |
Definition at line 211 of file generator_class_cpp.cpp.
References PTraitBackendManager::classExtraFunctionDeclaration(), generator_checkDefaultValueExist(), generator_enum_cpp_header(), PClassConfig::getClassDocumentation(), PClassConfig::getListAttribute(), and PClassConfig::getName().
Referenced by generator_class_cpp_headerFile(), and generator_enum_cpp_header().