PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
CppTraitGetter.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 "CppTraitGetter.h"
9
11
18PString getter_createGetterDecl(const PString & varType, const PString & varName, const PString & className, bool isConst, bool isPtr){
19 PString functionDecl("");
20 functionDecl += makeVarType(varType, false, isConst, !isConst, isPtr) + " ";
21 if(className != "") functionDecl += className + "::";
22 functionDecl += "get" + varName.firstToUpper() + "()";
23 return functionDecl;
24}
25
30
33
35
39void CppTraitGetter::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
40 if(!mode.enableGetter || classConfig.getIsEnum()){return;}
41 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
42 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
43 fs << "\t\t" << getter_createGetterDecl(it->getType(), it->getName(), "", true, it->getIsPointer()) << " const;" << std::endl;
44 fs << "\t\t" << getter_createGetterDecl(it->getType(), it->getName(), "", false, it->getIsPointer()) << ";" << std::endl;
45 }
46}
47
49
53void CppTraitGetter::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
54 if(!mode.enableGetter || classConfig.getIsEnum()){return;}
55 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
56 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
57 fs << "///Gets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
58 fs << "/**\t@return " << it->getName() << " of the " << classConfig.getName() << std::endl;
59 fs << "*/" << std::endl;
60 fs << mode.templateDeclaration;
61 fs << getter_createGetterDecl(it->getType(), it->getName(), classConfig.getName() + mode.defTemplate, true, it->getIsPointer()) << " const{" << std::endl;
62 fs << "\treturn p_" << it->getName() << ";" << std::endl;
63 fs << "}" << std::endl << std::endl;
64 fs << "///Gets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
65 fs << "/**\t@return " << it->getName() << " of the " << classConfig.getName() << std::endl;
66 fs << "*/" << std::endl;
67 fs << mode.templateDeclaration;
68 fs << getter_createGetterDecl(it->getType(), it->getName(), classConfig.getName() + mode.defTemplate, false, it->getIsPointer()) << "{" << std::endl;
69 fs << "\treturn p_" << it->getName() << ";" << std::endl;
70 fs << "}" << std::endl << std::endl;
71 }
72}
73
74
75
76
77
PString getter_createGetterDecl(const PString &varType, const PString &varName, const PString &className, bool isConst, bool isPtr)
Creates a function decl for setters.
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
CppTraitGetter()
Consctructor of CppTraitGetter.
virtual ~CppTraitGetter()
Desctructor of CppTraitGetter.
virtual void publicMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of methods.
virtual void publicMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration 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.
bool enableGetter
True to enable getters trait generator.
PString defTemplate
Template definition for the class header.
PString templateDeclaration
Template declaration of the method implementation.
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.