PhoenixGenerator  3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
Loading...
Searching...
No Matches
CppTraitCopy.cpp File Reference
#include "type_utils.h"
#include "CppTraitCopy.h"
Include dependency graph for CppTraitCopy.cpp:

Go to the source code of this file.

Functions

void class_createCheckClassEquality (std::ofstream &fs, const PClassConfig &classConfig, bool isConst)
 Create the class check.
void class_createTestClassCopy (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode)
 Create the class check.
bool copy_hasPointerAttribute (const PClassConfig &classConfig)
 Check if the given class owns at least one pointer attribute.

Function Documentation

◆ class_createCheckClassEquality()

void class_createCheckClassEquality ( std::ofstream & fs,
const PClassConfig & classConfig,
bool isConst )

Create the class check.

Parameters
fs: file to be completed
classConfig: class configuration to be used
isConst: true if the generated check has to use const classes

Definition at line 17 of file CppTraitCopy.cpp.

17 {
18 PString name(classConfig.getName()), strConst("");
19 if(isConst){
20 strConst = "const ";
21 }
22 fs << "///Check the equality between two "+name+" classes\n";
23 fs << "/**\t@param var : variable to be checked\n";
24 fs << " * \t@param reference : reference\n";
25 fs << " * \t@return true on success, false otherwise\n";
26 fs << "*/\n";
27 fs << "bool check"+name+"Equality";
28 if(isConst){
29 fs << "Const";
30 }
31 fs << "(" + strConst + name + " & var, " + strConst + name + " & reference){\n";
32 fs << "\tbool b(true);\n";
33 const PVecClassAttribute & listAttr = classConfig.getListAttribute();
34 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
35 PString attrName(it->getName().firstToUpper());
36 bool isSimpleType = getIsSimpleType(it->getType());
37// std::cout << "createCheckClassEquality : attrName = '"<<attrName<<"', isSimpleType = " << isSimpleType << ", it->getIsPointer() = " << it->getIsPointer() << ", it->getIsReference() = " << it->getIsReference() << std::endl;
38 if(isSimpleType || it->getIsPointer() || it->getType() == "PString"){
39 fs << "\tb &= var.get"+attrName+"() == reference.get"+attrName+"();\n";
40 }
41 }
42 fs << "\treturn b;\n";
43 fs << "}\n\n";
44}
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
const PString & getName() const
Returns the class name.
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.

References class_createCheckClassEquality(), getIsSimpleType(), PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by class_createCheckClassEquality(), and CppTraitCopy::testFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ class_createTestClassCopy()

void class_createTestClassCopy ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode )

Create the class check.

Parameters
fs: file to be completed
classConfig: class configuration to be used
mode: all modes of the generator (data/check/type/config stream)

Definition at line 63 of file CppTraitCopy.cpp.

63 {
64 PString name(classConfig.getName());
65 fs << "///Check copy of class "+name+"\n";
66 fs << "void check"+name+"Copy(){\n";
67 fs << "\t"+name+" reference;\n";
68 fs << "\t//Let's use the setters\n";
69 const PVecClassAttribute & listAttr = classConfig.getListAttribute();
70 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
71 PString defaultValue(getTestDefaultValueTypeInCpp(it->getType())), attrName(it->getName().firstToUpper());;
72 if(defaultValue != ""){
73 fs << "\treference.set"+attrName+"("+defaultValue+");\n";
74 }
75 }
76 fs << "\t"+name+" varCopy(reference);\n";
77 fs << "\t"+name+" varEqual;\n";
78 fs << "\tvarEqual = reference;\n";
79 fs << "\t"<<mode.assertCall<<"(check"+name+"Equality(varCopy, reference));\n";
80 fs << "\t"<<mode.assertCall<<"(check"+name+"EqualityConst(varCopy, reference));\n";
81 fs << "\t"<<mode.assertCall<<"(check"+name+"Equality(varEqual, reference));\n";
82 fs << "\t"<<mode.assertCall<<"(check"+name+"EqualityConst(varEqual, reference));\n";
83 fs << "}\n\n";
84}
PString assertCall
Assert to be used.
PString getTestDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.

References GeneratorMode::assertCall, class_createTestClassCopy(), PClassConfig::getListAttribute(), PClassConfig::getName(), and getTestDefaultValueTypeInCpp().

Referenced by class_createTestClassCopy(), and CppTraitCopy::testFunction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ copy_hasPointerAttribute()

bool copy_hasPointerAttribute ( const PClassConfig & classConfig)

Check if the given class owns at least one pointer attribute.

Parameters
classConfig: PClassConfig to be checked
Returns
true if the class has a pointer attribute, false otherwise

Definition at line 50 of file CppTraitCopy.cpp.

50 {
51 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
52 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
53 if(getIsPointerType(it->getType())){return true;}
54 }
55 return false;
56}
bool getIsPointerType(const PString &varType)
Say if a given type is a pointer type (i.e. it ends with a '*').

References copy_hasPointerAttribute(), getIsPointerType(), and PClassConfig::getListAttribute().

Referenced by copy_hasPointerAttribute(), CppTraitCopy::testCallFunction(), and CppTraitCopy::testFunction().

Here is the call graph for this function:
Here is the caller graph for this function: