PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
CppTraitFromString Class Reference

Class generator for setter trait. More...

#include <CppTraitFromString.h>

+ Inheritance diagram for CppTraitFromString:
+ Collaboration diagram for CppTraitFromString:

Public Member Functions

virtual void classExtraFunctionDeclaration (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Declaration of extra functions.
 
virtual void classExtraFunctionImplementation (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of extra functions.
 
 CppTraitFromString ()
 Consctructor of CppTraitFromString.
 
virtual void headerExtraInclude (std::ofstream &fs, const GeneratorMode &mode) const
 Add extra include on the header.
 
virtual void privateMethodDeclaration (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Declaration of private methods.
 
virtual void privateMethodImplementation (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of private methods.
 
virtual void protectedMethodDeclaration (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Declaration of protected methods.
 
virtual void protectedMethodImplementation (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of protected methods.
 
virtual void publicMethodDeclaration (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Declaration of public methods.
 
virtual void publicMethodImplementation (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of public methods.
 
virtual void testCallFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Call of the test function.
 
virtual void testFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Implementation of test function.
 
virtual ~CppTraitFromString ()
 Desctructor of CppTraitFromString.
 

Detailed Description

Class generator for setter trait.

Definition at line 16 of file CppTraitFromString.h.

Constructor & Destructor Documentation

◆ CppTraitFromString()

CppTraitFromString::CppTraitFromString ( )

Consctructor of CppTraitFromString.

Definition at line 11 of file CppTraitFromString.cpp.

References PAbstractTraitBackend::PAbstractTraitBackend().

+ Here is the call graph for this function:

◆ ~CppTraitFromString()

CppTraitFromString::~CppTraitFromString ( )
virtual

Desctructor of CppTraitFromString.

Definition at line 16 of file CppTraitFromString.cpp.

16{}

Member Function Documentation

◆ classExtraFunctionDeclaration()

void CppTraitFromString::classExtraFunctionDeclaration ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Declaration of extra functions.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 85 of file CppTraitFromString.cpp.

85 {
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}
const PString & getName() const
Returns the class name.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
bool enableFromString
True to enable fromString trait generator.

References GeneratorMode::enableFromString, PClassConfig::getIsEnum(), and PClassConfig::getName().

+ Here is the call graph for this function:

◆ classExtraFunctionImplementation()

void CppTraitFromString::classExtraFunctionImplementation ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Implementation of extra functions.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 96 of file CppTraitFromString.cpp.

96 {
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}
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.

References GeneratorMode::enableFromString, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), and PClassConfig::getName().

+ Here is the call graph for this function:

◆ headerExtraInclude()

void CppTraitFromString::headerExtraInclude ( std::ofstream & fs,
const GeneratorMode & mode ) const
virtual

Add extra include on the header.

Parameters
[out]fs: file to be completed
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 22 of file CppTraitFromString.cpp.

22 {
23
24}

◆ privateMethodDeclaration()

void CppTraitFromString::privateMethodDeclaration ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Declaration of private methods.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 67 of file CppTraitFromString.cpp.

67 {
68
69}

◆ privateMethodImplementation()

void CppTraitFromString::privateMethodImplementation ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Implementation of private methods.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 76 of file CppTraitFromString.cpp.

76 {
77
78}

◆ protectedMethodDeclaration()

void CppTraitFromString::protectedMethodDeclaration ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Declaration of protected methods.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 49 of file CppTraitFromString.cpp.

49 {
50
51}

◆ protectedMethodImplementation()

void CppTraitFromString::protectedMethodImplementation ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Implementation of protected methods.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 58 of file CppTraitFromString.cpp.

58 {
59
60}

◆ publicMethodDeclaration()

void CppTraitFromString::publicMethodDeclaration ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Declaration of public methods.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 31 of file CppTraitFromString.cpp.

31 {
32
33}

◆ publicMethodImplementation()

void CppTraitFromString::publicMethodImplementation ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Implementation of public methods.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 40 of file CppTraitFromString.cpp.

40 {
41
42}

◆ testCallFunction()

void CppTraitFromString::testCallFunction ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Call of the test function.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 153 of file CppTraitFromString.cpp.

153 {
154 if(!mode.enableFromString || !classConfig.getIsEnum()){return;}
155 PString name(classConfig.getName());
156 fs << "\ttest" << name << "FromString();" << std::endl;
157}

References GeneratorMode::enableFromString, PClassConfig::getIsEnum(), and PClassConfig::getName().

+ Here is the call graph for this function:

◆ testFunction()

void CppTraitFromString::testFunction ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Implementation of test function.

Parameters
[out]fs: file to be completed
classConfig: PClassConfig to be used
mode: mode of the generator

Reimplemented from PAbstractTraitBackend.

Definition at line 121 of file CppTraitFromString.cpp.

121 {
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}
PString assertCall
Assert to be used.

References GeneratorMode::assertCall, GeneratorMode::enableFromString, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), and PClassConfig::getName().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: