PhoenixGenerator  2.6.4
Set of tools to generate code
Loading...
Searching...
No Matches
CppTraitTypeStream.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 CppTraitTypeStream::headerExtraInclude(std::ofstream & fs, const GeneratorMode & mode) const{
23 if(!mode.enableTypeStream){return;}
24 fs << "#include \"phoenix_type_stream.h\"" << std::endl;
25}
26
28
32void CppTraitTypeStream::protectedMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
33 if(!mode.enableTypeStream){return;}
34
35}
36
38
42void CppTraitTypeStream::protectedMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
43 if(!mode.enableTypeStream){return;}
44
45}
46
48
52void CppTraitTypeStream::privateMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
53 if(!mode.enableTypeStream){return;}
54
55}
56
58
62void CppTraitTypeStream::privateMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
63 if(!mode.enableTypeStream){return;}
64
65}
66
68
72void CppTraitTypeStream::classExtraFunctionDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
73 if(!mode.enableTypeStream){return;}
74 PString name(classConfig.getName());
75 PString fullName(classConfig.getFullName());
76
77 if(classConfig.getIsEnum()){
78 name = name + "::" + name;
79 }
80
81 const PVecString & listTemplate = classConfig.getListTemplate();
82 if(listTemplate.size() != 0lu){
83 fs << "///Get the name of the class " << name << std::endl;
84 fs << "/**\t@return name of the class " << name << std::endl;
85 fs << "*/" << std::endl;
86 fs << mode.templateDeclaration;
87 fs << "std::string phoenix_getTypeName<"<<fullName << mode.defTemplate <<" >(){" << std::endl;
88 fs << "\treturn \""<<name<<"\"";
89 fs << " + \"<\"";
90 for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
91 fs << " + phoenix_getTypeToStr<"<<it->split(' ').back()<<">()";
92 }
93 fs << " + \">\"";
94 fs << ";" << std::endl;
95 fs << "}" << std::endl << std::endl;
96
97 }else{
98 fs << "template<>" << std::endl;
99 fs << "std::string phoenix_getTypeName<"<<fullName<<">();" << std::endl << std::endl;
100 }
101}
102
104
108void CppTraitTypeStream::classExtraFunctionImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
109 if(!mode.enableTypeStream){return;}
110 PString name(classConfig.getName());
111 fs << "///Get the name of the class " << name << " for PhoenixTypeStream" << std::endl;
112 fs << "/**\t@return name of the class " << name << " for PhoenixTypeStream" << std::endl;
113 fs << "*/" << std::endl;
114 if(classConfig.getIsEnum()){
115 name = name + "::" + name;
116 }
117 const PVecString & listTemplate = classConfig.getListTemplate();
118 if(listTemplate.size() == 0lu){
119 fs << "template<>" << std::endl;
120 }else{
121 fs << mode.templateDeclaration;
122 }
123 fs << "std::string phoenix_getTypeName<"<<name << mode.defTemplate <<" >(){" << std::endl;
124 fs << "\treturn \""<<name<<"\"";
125 if(listTemplate.size() != 0lu){
126 fs << " + \"<\"";
127 for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
128 fs << " + phoenix_getTypeToStr<"<<it->split(' ').back()<<">()";
129 }
130 fs << " + \">\"";
131 }
132 fs << ";" << std::endl;
133 fs << "}" << std::endl << std::endl;
134}
135
137
141void CppTraitTypeStream::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
142 if(!mode.enableTypeStream){return;}
143 PString name(classConfig.getName());
144 fs << "///Check TypeStream of class "+name+"\n";
145 fs << "void check"+name+"TypeStream(){\n";
146 if(classConfig.getIsEnum()){
147 name = name + "::" + name;
148 }
149 fs << "\t"<<mode.assertCall<<"(phoenix_getTypeToStr<"<<name<<">() == \""<<name<<"\");\n";
150 fs << "}\n\n";
151}
152
154
158void CppTraitTypeStream::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
159 if(!mode.enableTypeStream){return;}
160 PString name(classConfig.getName());
161 fs << "\tcheck"+name+"TypeStream();\n";
162}
163
164
165
virtual ~CppTraitTypeStream()
Desctructor of CppTraitTypeStream.
virtual void privateMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of private methods.
virtual void classExtraFunctionImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of extra functions.
virtual void protectedMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of protected methods.
virtual void privateMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of private methods.
virtual void classExtraFunctionDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of extra functions.
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 void protectedMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of protected methods.
virtual void headerExtraInclude(std::ofstream &fs, const GeneratorMode &mode) const
Add extra include on the header.
CppTraitTypeStream()
Consctructor of CppTraitTypeStream.
Class to describe a basic class.
PString getFullName() const
Returns the full name of the class including the namespace.
const PVecString & getListTemplate() const
Returns the list of the template 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.
PString defTemplate
Template definition for the class header.
PString templateDeclaration
Template declaration of the method implementation.
PString assertCall
Assert to be used.
bool enableTypeStream
True to enable type stream interface generator.