PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
CppTraitCheckStream.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 CppTraitCheckStream::headerExtraInclude(std::ofstream & fs, const GeneratorMode & mode) const{
23 if(!mode.enableCheckStream){return;}
24 fs << "#include \"phoenix_check_stream.h\"" << std::endl;
25}
26
28
32void CppTraitCheckStream::publicMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
33 if(!mode.enableCheckStream){return;}
34
35}
36
38
42void CppTraitCheckStream::publicMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
43 if(!mode.enableCheckStream){return;}
44
45}
46
48
52void CppTraitCheckStream::protectedMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
53
54}
55
57
61void CppTraitCheckStream::protectedMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
62
63}
64
66
70void CppTraitCheckStream::privateMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
71
72}
73
75
79void CppTraitCheckStream::privateMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
80
81}
82
84
88void CppTraitCheckStream::classExtraFunctionDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
89 if(!mode.enableCheckStream){return;}
90 PString name(classConfig.getName());
91 const PVecString & listTemplate = classConfig.getListTemplate();
92 if(classConfig.getIsEnum()){
93 fs << "PHOENIX_CHECK_STREAM_ENUM("<<name<<"::"<<name<<")" << std::endl << std::endl;
94 return;
95 }
96 if(listTemplate.size() != 0lu){
97 fs << "///@brief Generic "<<name<<" check function" << std::endl;
98 fs << mode.templateDeclaration;
99 fs << "struct CheckStream<"<<name << mode.defTemplate<<">{" << std::endl;
100 fs << "\tstatic bool check_stream(const std::string & fieldDescription, const "<<name << mode.defTemplate<<" & data, const "<<name << mode.defTemplate<<" & reference, std::ostream & out);" << std::endl;
101 fs << "\t\tbool b(true);" << std::endl;
102 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
103 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
104 fs << "\t\tb &= CheckStream<"<<it->getType()<<">::check_stream(fieldDescription + \"\\n- "<<name<<"::"<<it->getName()<<"\", data.get"<<it->getName().firstToUpper()<<"(), reference.get"<<it->getName().firstToUpper()<<"(), out);" << std::endl;
105 }
106 fs << "\t\treturn b;" << std::endl;
107 fs << "\t}" << std::endl;
108 fs << "};" << std::endl;
109 }else{
110 fs << "///@brief Generic "<<name<<" Check function" << std::endl;
111 fs << "template<>" << std::endl;
112 fs << "struct CheckStream<"<<name<<">{" << std::endl;
113 fs << "\tstatic bool check_stream(const std::string & fieldDescription, const "<<name<<" & data, const "<<name<<" & reference, std::ostream & out);" << std::endl;
114 fs << "};" << std::endl;
115 }
116 fs << std::endl << std::endl;
117}
118
120
124void CppTraitCheckStream::classExtraFunctionImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
125 if(!mode.enableCheckStream || classConfig.getIsEnum()){return;}
126
127 PString name(classConfig.getName());
128 const PVecString & listTemplate = classConfig.getListTemplate();
129 if(listTemplate.size() == 0lu){
130 fs << "///Check Stream for a "<<name<<"" << std::endl;
131 fs << "/**\t@param fieldDescription : description of the field to be checked" << std::endl;
132 fs << " * \t@param data : data to be checked" << std::endl;
133 fs << " * \t@param reference : reference of the check" << std::endl;
134 fs << " * \t@param out : ostream used to collect feed back in case of error (std::cerr or a logger)" << std::endl;
135 fs << " * \t@return true on success, false otherwise" << std::endl;
136 fs << "*/" << std::endl;
137 fs << "bool CheckStream<"<<name<<">::check_stream(const std::string & fieldDescription, const "<<name<<" & data, const "<<name<<" & reference, std::ostream & out){" << std::endl;
138 fs << "\tbool b(true);" << std::endl;
139 const PVecClassAttribute & vecAttr(classConfig.getListAttribute());
140 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
141 fs << "\tb &= CheckStream<"<<it->getType()<<">::check_stream(fieldDescription + \"\\n- "<<name<<"::"<<it->getName()<<"\", data.get"<<it->getName().firstToUpper()<<"(), reference.get"<<it->getName().firstToUpper()<<"(), out);" << std::endl;
142 }
143 fs << "\treturn b;" << std::endl;
144 fs << "}" << std::endl;
145 }
146 fs << std::endl << std::endl;
147}
148
149
150
151
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
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 publicMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of public methods.
virtual void publicMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of public methods.
virtual void classExtraFunctionDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of extra functions.
CppTraitCheckStream()
Consctructor of CppTraitCheckStream.
virtual ~CppTraitCheckStream()
Desctructor of CppTraitCheckStream.
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.
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 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.
bool enableCheckStream
True to enable check stream interface generator.