PhoenixGenerator
3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
Toggle main menu visibility
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
19
PString
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
28
CppTraitGetter::CppTraitGetter
()
29
:
PAbstractTraitBackend
()
30
{}
31
33
CppTraitGetter::~CppTraitGetter
(){}
34
36
40
void
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
54
void
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
getter_createGetterDecl
PString getter_createGetterDecl(const PString &varType, const PString &varName, const PString &className, bool isConst, bool isPtr)
Creates a function decl for setters.
Definition
CppTraitGetter.cpp:19
CppTraitGetter.h
PVecClassAttribute
std::vector< PClassAttribute > PVecClassAttribute
Definition
PDataConfig.h:13
CppTraitGetter::CppTraitGetter
CppTraitGetter()
Consctructor of CppTraitGetter.
Definition
CppTraitGetter.cpp:28
CppTraitGetter::~CppTraitGetter
virtual ~CppTraitGetter()
Desctructor of CppTraitGetter.
Definition
CppTraitGetter.cpp:33
CppTraitGetter::publicMethodImplementation
virtual void publicMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of methods.
Definition
CppTraitGetter.cpp:54
CppTraitGetter::publicMethodDeclaration
virtual void publicMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of methods.
Definition
CppTraitGetter.cpp:40
PAbstractTraitBackend::PAbstractTraitBackend
PAbstractTraitBackend()
Definition
PAbstractTraitBackend.h:22
PClassConfig
Class to describe a basic class.
Definition
PClassConfig.h:14
PClassConfig::getListAttribute
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
Definition
PClassConfig.cpp:167
PClassConfig::getName
const PString & getName() const
Returns the class name.
Definition
PClassConfig.cpp:129
PClassConfig::getIsEnum
bool getIsEnum() const
Say if the current PClassConfig is an enum.
Definition
PClassConfig.cpp:197
GeneratorMode
All the genertor modes.
Definition
GeneratorMode.h:28
GeneratorMode::enableGetter
bool enableGetter
True to enable getters trait generator.
Definition
GeneratorMode.h:43
GeneratorMode::defTemplate
PString defTemplate
Template definition for the class header.
Definition
GeneratorMode.h:49
GeneratorMode::templateDeclaration
PString templateDeclaration
Template declaration of the method implementation.
Definition
GeneratorMode.h:51
getIsPointerType
bool getIsPointerType(const PString &varType)
Say if a given type is a pointer type (i.e. it ends with a '*').
Definition
type_utils.cpp:41
makeVarType
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.
Definition
type_utils.cpp:162
type_utils.h
src
TraitBackEnd
CPP
CppTraitGetter
CppTraitGetter.cpp
Generated by
1.18.0