PhoenixGenerator  3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
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 : LGPL-3.0-only
6****************************************/
7
8#include "type_utils.h"
9#include "CppTraitGetter.h"
10
12
19PString getter_createGetterDecl(const PString & varType, const PString & varName, const PString & className, bool isConst, bool isPtr){
20 PString functionDecl("");
21 functionDecl += makeVarType(varType, false, isConst, !isConst, isPtr) + " ";
22 if(className != "") functionDecl += className + "::";
23 functionDecl += "get" + varName.firstToUpper() + "()";
24 return functionDecl;
25}
26
31
34
36
40void CppTraitGetter::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
41 if(!mode.enableGetter || 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" << getter_createGetterDecl(it->getType(), it->getName(), "", true, getIsPointerType(it->getType())) << " const;" << std::endl;
45 fs << "\t\t" << getter_createGetterDecl(it->getType(), it->getName(), "", false, getIsPointerType(it->getType())) << ";" << std::endl;
46 }
47}
48
50
54void CppTraitGetter::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
55 if(!mode.enableGetter || classConfig.getIsEnum()){return;}
56 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
57 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
58 fs << "///Gets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
59 fs << "/**\t@return " << it->getName() << " of the " << classConfig.getName() << std::endl;
60 fs << "*/" << std::endl;
61 fs << mode.templateDeclaration;
62 bool isPtr(getIsPointerType(it->getType()));
63 PString returnExpr("p_" + it->getName());
64 fs << getter_createGetterDecl(it->getType(), it->getName(), classConfig.getName() + mode.defTemplate, true, isPtr) << " const{" << std::endl;
65 fs << "\treturn " << returnExpr << ";" << std::endl;
66 fs << "}" << std::endl << std::endl;
67 fs << "///Gets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
68 fs << "/**\t@return " << it->getName() << " of the " << classConfig.getName() << std::endl;
69 fs << "*/" << std::endl;
70 fs << mode.templateDeclaration;
71 fs << getter_createGetterDecl(it->getType(), it->getName(), classConfig.getName() + mode.defTemplate, false, isPtr) << "{" << std::endl;
72 fs << "\treturn " << returnExpr << ";" << std::endl;
73 fs << "}" << std::endl << std::endl;
74 }
75}
76
77
78
79
80
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.
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.