PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
CppTraitFromString.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
9
14
17
19
22void CppTraitFromString::headerExtraInclude(std::ofstream & fs, const GeneratorMode & mode) const{
23
24}
25
27
31void CppTraitFromString::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
32
33}
34
36
40void CppTraitFromString::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
41
42}
43
45
49void CppTraitFromString::protectedMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
50
51}
52
54
58void CppTraitFromString::protectedMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
59
60}
61
63
67void CppTraitFromString::privateMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
68
69}
70
72
76void CppTraitFromString::privateMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
77
78}
79
81
85void CppTraitFromString::classExtraFunctionDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
86 if(!mode.enableFromString || !classConfig.getIsEnum()){return;}
87 PString name(classConfig.getName());
88 fs << "bool fromString(" << name << "::" << name << " & data, const std::string & value);" << std::endl << std::endl;
89}
90
92
96void CppTraitFromString::classExtraFunctionImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
97 if(!mode.enableFromString || !classConfig.getIsEnum()){return;}
98 PString name(classConfig.getName());
99 fs << "///Set " << name << "::" << name << " enum with a PString" << std::endl;
100 fs << "/**\t@param[out] data : " << name << "::" << name << " to set" << std::endl;
101 fs << " * \t@param value : std::string to initialised it" << std::endl;
102 fs << " * \t@return true on success, false otherwise" << std::endl;
103 fs << "*/" << std::endl;
104 fs << "bool fromString(" << name << "::" << name << " & data, const std::string & value){" << std::endl;
105 fs << "\tswitch(value){" << std::endl;
106 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
107 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
108 fs << "\t\tcase \""<<it->getName()<<"\": data = " << name << "::" << it->getName() << "; break;" << std::endl;
109 }
110 fs << "\t\tdefault: return false;" << std::endl;
111 fs << "\t}" << std::endl;
112 fs << "\treturn true;" << std::endl;
113 fs << "}" << std::endl << std::endl;
114}
115
117
121void CppTraitFromString::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
122 if(!mode.enableFromString || !classConfig.getIsEnum()){return;}
123 PString name(classConfig.getName());
124
125 fs << "///Check the fromString trait of enum " << name << "::" << name << std::endl;
126 fs << "/**\t@param inputValue : input value to initialise a " << name << "::" << name << std::endl;
127 fs << " * \t@param reference : reference value of the expected " << name << "::" << name << std::endl;
128 fs << "*/" << std::endl;
129 fs << "void check" << name << "FromString(const std::string & inputValue, " << name << "::" << name << " reference){" << std::endl;
130 fs << "\t" << name << "::" << name << " value;" << std::endl;
131 fs << "\t"<<mode.assertCall<<"(fromString(value, inputValue));" << std::endl;
132 fs << "\t"<<mode.assertCall<<"(value == reference);" << std::endl;
133 fs << "}" << std::endl << std::endl;
134
135 fs << "///Test the fromString trait of enum " << name << "::" << name << std::endl;
136 fs << "void test" << name << "FromString(){" << std::endl;
137 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
138 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
139 fs << "\tcheck" << name << "FromString(\""<<it->getName()<<"\", " << name << "::" << it->getName() << ");" << std::endl;
140
141 }
142 fs << "\t" << name << "::" << name << " wrongValue;" << std::endl;
143 fs << "\t"<<mode.assertCall<<"(!fromString(wrongValue, \"non sense string of configuration\"));" << std::endl;
144
145 fs << "}" << std::endl << std::endl;
146}
147
149
153void CppTraitFromString::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
154 if(!mode.enableFromString || !classConfig.getIsEnum()){return;}
155 PString name(classConfig.getName());
156 fs << "\ttest" << name << "FromString();" << std::endl;
157}
158
159
160
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
virtual void classExtraFunctionDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of extra functions.
CppTraitFromString()
Consctructor of CppTraitFromString.
virtual void protectedMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of protected methods.
virtual void testCallFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Call of the test function.
virtual void publicMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of public methods.
virtual void headerExtraInclude(std::ofstream &fs, const GeneratorMode &mode) const
Add extra include on the header.
virtual void testFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of test function.
virtual void privateMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of private methods.
virtual ~CppTraitFromString()
Desctructor of CppTraitFromString.
virtual void publicMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of public methods.
virtual void privateMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of private methods.
virtual void protectedMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of protected methods.
virtual void classExtraFunctionImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of extra functions.
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 enableFromString
True to enable fromString trait generator.
PString assertCall
Assert to be used.