PhoenixGenerator  2.0.4
Set of tools to generate code
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 : CeCILL-C
6****************************************/
7
8#include "CppTraitSetter.h"
9
11
17PString setter_createSetterDecl(const PString & varType, const PString & varName, const PString & className, bool isPtr){
18 PString functionDecl("void ");
19 if(className != "") functionDecl += className + "::";
20 functionDecl += "set" + varName.firstToUpper() + "(";
21 functionDecl += makeVarType(varType, true, true, false, isPtr);
22 functionDecl += " " + varName + ")";
23 return functionDecl;
24}
25
26
31
34
36
40void CppTraitSetter::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
41 if(!mode.enableSetter || classConfig.getIsEnum()){return;}
42 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
43 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
44 fs << "\t\t" << setter_createSetterDecl(it->getType(), it->getName(), "", it->getIsPointer()) << ";" << std::endl;
45 }
46}
47
49
53void CppTraitSetter::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
54 if(!mode.enableSetter || classConfig.getIsEnum()){return;}
55
56 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
57 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
58 fs << "///Sets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
59 fs << "/**\t@param " << it->getName() << " : " << it->getName() << " of the " << classConfig.getName() << std::endl;
60 fs << "*/" << std::endl;
61 fs << mode.templateDeclaration;
62 fs << setter_createSetterDecl(it->getType(), it->getName(), classConfig.getName() + mode.defTemplate, it->getIsPointer()) << "{" << std::endl;
63 fs << "\tp_" << it->getName() << " = " << it->getName() << ";" << std::endl;
64 fs << "}" << std::endl << std::endl;
65 }
66}
67
68
69
70
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.
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.