PhoenixGenerator  3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
Loading...
Searching...
No Matches
CppTraitSetter.cpp
Go to the documentation of this file.
1
2/***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : LGPL-3.0-only
6****************************************/
7
8#include "type_utils.h"
9#include "CppTraitSetter.h"
10
12
18PString setter_createSetterDecl(const PString & varType, const PString & varName, const PString & className, bool isPtr){
19 PString functionDecl("void ");
20 if(className != "") functionDecl += className + "::";
21 functionDecl += "set" + varName.firstToUpper() + "(";
22 functionDecl += makeVarType(varType, true, true, false, isPtr);
23 functionDecl += " " + varName + ")";
24 return functionDecl;
25}
26
27
32
35
37
41void CppTraitSetter::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
42 if(!mode.enableSetter || classConfig.getIsEnum()){return;}
43 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
44 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
45 fs << "\t\t" << setter_createSetterDecl(it->getType(), it->getName(), "", getIsPointerType(it->getType())) << ";" << std::endl;
46 }
47}
48
50
54void CppTraitSetter::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
55 if(!mode.enableSetter || classConfig.getIsEnum()){return;}
56
57 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
58 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
59 fs << "///Sets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
60 fs << "/**\t@param " << it->getName() << " : " << it->getName() << " of the " << classConfig.getName() << std::endl;
61 fs << "*/" << std::endl;
62 fs << mode.templateDeclaration;
63 bool isPtr(getIsPointerType(it->getType()));
64 fs << setter_createSetterDecl(it->getType(), it->getName(), classConfig.getName() + mode.defTemplate, isPtr) << "{" << std::endl;
65 if(isPtr){
66 fs << "\tif(p_" << it->getName() << " != " << it->getName() << "){delete p_" << it->getName() << ";}" << std::endl;
67 fs << "\tp_" << it->getName() << " = " << it->getName() << ";" << std::endl;
68 }else{
69 fs << "\tp_" << it->getName() << " = " << it->getName() << ";" << std::endl;
70 }
71 fs << "}" << std::endl << std::endl;
72 }
73}
74
75
76
77
PString setter_createSetterDecl(const PString &varType, const PString &varName, const PString &className, bool isPtr)
Creates a function decl for setters.
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
virtual ~CppTraitSetter()
Desctructor of CppTraitSetter.
virtual void publicMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of methods.
CppTraitSetter()
Consctructor of CppTraitSetter.
virtual void publicMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of methods.
Class to describe a basic class.
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
const PString & getName() const
Returns the class name.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
All the genertor modes.
PString defTemplate
Template definition for the class header.
PString templateDeclaration
Template declaration of the method implementation.
bool enableSetter
True to enable setters trait generator.
bool getIsPointerType(const PString &varType)
Say if a given type is a pointer type (i.e. it ends with a '*').
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.