PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
CppTraitCopy.cpp File Reference
#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.
 

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 16 of file CppTraitCopy.cpp.

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

Referenced by 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 50 of file CppTraitCopy.cpp.

50 {
51 PString name(classConfig.getName());
52 fs << "///Check copy of class "+name+"\n";
53 fs << "void check"+name+"Copy(){\n";
54 fs << "\t"+name+" reference;\n";
55 fs << "\t//Let's use the setters\n";
56 const PVecClassAttribute & listAttr = classConfig.getListAttribute();
57 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
58 PString defaultValue(getTestDefaultValueTypeInCpp(it->getType())), attrName(it->getName().firstToUpper());;
59 if(defaultValue != ""){
60 fs << "\treference.set"+attrName+"("+defaultValue+");\n";
61 }
62 }
63 fs << "\t"+name+" varCopy(reference);\n";
64 fs << "\t"+name+" varEqual;\n";
65 fs << "\tvarEqual = reference;\n";
66 fs << "\t"<<mode.assertCall<<"(check"+name+"Equality(varCopy, reference));\n";
67 fs << "\t"<<mode.assertCall<<"(check"+name+"EqualityConst(varCopy, reference));\n";
68 fs << "\t"<<mode.assertCall<<"(check"+name+"Equality(varEqual, reference));\n";
69 fs << "\t"<<mode.assertCall<<"(check"+name+"EqualityConst(varEqual, reference));\n";
70 fs << "}\n\n";
71}
PString assertCall
Assert to be used.
PString getTestDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.

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

Referenced by CppTraitCopy::testFunction().

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