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
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
18
PString
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
29
CppTraitSetter::CppTraitSetter
()
30
:
PAbstractTraitBackend
()
31
{}
32
34
CppTraitSetter::~CppTraitSetter
(){}
35
37
41
void
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
54
void
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
setter_createSetterDecl
PString setter_createSetterDecl(const PString &varType, const PString &varName, const PString &className, bool isPtr)
Creates a function decl for setters.
Definition
CppTraitSetter.cpp:18
CppTraitSetter.h
PVecClassAttribute
std::vector< PClassAttribute > PVecClassAttribute
Definition
PDataConfig.h:13
CppTraitSetter::~CppTraitSetter
virtual ~CppTraitSetter()
Desctructor of CppTraitSetter.
Definition
CppTraitSetter.cpp:34
CppTraitSetter::publicMethodDeclaration
virtual void publicMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of methods.
Definition
CppTraitSetter.cpp:41
CppTraitSetter::CppTraitSetter
CppTraitSetter()
Consctructor of CppTraitSetter.
Definition
CppTraitSetter.cpp:29
CppTraitSetter::publicMethodImplementation
virtual void publicMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of methods.
Definition
CppTraitSetter.cpp:54
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::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
GeneratorMode::enableSetter
bool enableSetter
True to enable setters trait generator.
Definition
GeneratorMode.h:41
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
CppTraitSetter
CppTraitSetter.cpp
Generated by
1.18.0