PhoenixGenerator  2.0.0
Set of tools to generate code
saveClassConfig.cpp File Reference
#include "header_generator.h"
#include "saveClassConfig.h"
+ Include dependency graph for saveClassConfig.cpp:

Go to the source code of this file.

Functions

void checkClassConfig (bool &hasSource, bool &hasTemplate, const std::vector< PClassConfig > &classConfig)
 Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated. More...
 
PString createGetterDecl (const PString &varType, const PString &varName, const PString &className, bool isConst, bool isPtr)
 Creates a function decl for setters. More...
 
PString createSetterDecl (const PString &varType, const PString &varName, const PString &className, bool isPtr)
 Creates a function decl for setters. More...
 
PString getClassDeclTempalteDef (const PVecString &listTemplate)
 Get the template definition in the class declaration. More...
 
PString getClassDefTemplate (const PVecString &listTemplate)
 Get the template call in the class declaration. More...
 
PString getDefaultValueTypeInCpp (const PString &type)
 Get the default value of a type in C++. More...
 
bool getIsPointer (const PString &varType)
 Check if the given type is a pointer or not. More...
 
bool getIsSimpleType (const PString &varType)
 Check if the given type is a simple type. More...
 
PString makeVarType (const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
 Makes the var type by taking account of the type. More...
 
void saveClassConstructorImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves constructor of the class. More...
 
void saveClassCopyConstructorImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves copy constructor of the class. More...
 
void saveClassCopyFunctionImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves the copy function of a class. More...
 
void saveClassDataStreamGenericFunction (std::ofstream &fs, const PClassConfig &classConfig)
 Creates the method which enable to save/load generated class with any kind of stream/message/file. More...
 
void saveClassDataStreamMethod (std::ofstream &fs, const PClassConfig &classConfig)
 Creates the method which enable to save/load generated class with any kind of stream/message/file. More...
 
bool saveClassDecl (const std::vector< PClassConfig > &classConfig, const PPath &headerFile, const PVecPath &listInclude, bool enableDataStream, bool enableTypeStream, const PString &includeTemplate)
 Creates header file. More...
 
void saveClassDecl (std::ofstream &fs, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
 Creates header file. More...
 
void saveClassDestructorImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves destructor of the class. More...
 
void saveClassEqualOperatorImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves = operator of the class. More...
 
void saveClassGettersImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves the class getters implementation. More...
 
void saveClassGetTypeNameImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration, bool enableTypeStream)
 Saves constructor of the class. More...
 
bool saveClassImpl (const std::vector< PClassConfig > &classConfig, const PPath &sourceFile, const PPath &headerFile, bool enableTypeStream)
 Creates source file. More...
 
void saveClassImpl (std::ofstream &fs, const PClassConfig &classConfig, bool enableTypeStream)
 Creates source file. More...
 
bool saveClassImplDecl (const std::vector< PClassConfig > &classConfig, const PPath &baseFileName, const PVecPath &listInclude, bool enableDataStream, bool enableTypeStream)
 Creates header file. More...
 
void saveClassInitialisationFunctionImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves the copy function of a class. More...
 
void saveClassSettersImpl (std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
 Saves the class setters implementation. More...
 
bool saveClassTemplate (const std::vector< PClassConfig > &classConfig, const PPath &sourceFile, const PPath &headerFile)
 Creates template implementation file. More...
 
void saveClassTemplate (std::ofstream &fs, const PClassConfig &classConfig)
 Creates template implementation file. More...
 
void saveDeclGetters (std::ofstream &fs, const PClassConfig &classConfig)
 Creates getters header file. More...
 
void saveDeclSetters (std::ofstream &fs, const PClassConfig &classConfig)
 Creates setters header file. More...
 
void saveEnumDecl (std::ofstream &fs, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
 Creates header file. More...
 

Function Documentation

◆ checkClassConfig()

void checkClassConfig ( bool &  hasSource,
bool &  hasTemplate,
const std::vector< PClassConfig > &  classConfig 
)

Check if the configuration has source or template to determine if the .cpp or _impl.h files have to be generated.

Parameters
[out]hasSource: true if the configuration needs .cpp file
[out]hasTemplate: true if the configuration needs _impl.h file
classConfig: class config we want to save

Definition at line 710 of file saveClassConfig.cpp.

710  {
711  hasSource = false;
712  hasTemplate = false;
713  for(std::vector<PClassConfig>::const_iterator it(classConfig.begin()); it != classConfig.end(); ++it){
714  bool isTemplate = it->getListTemplate().size() != 0lu;
715  hasSource |= !isTemplate;
716  hasTemplate |= isTemplate;
717  }
718 }

Referenced by saveClassImplDecl().

+ Here is the caller graph for this function:

◆ createGetterDecl()

PString createGetterDecl ( const PString varType,
const PString varName,
const PString className,
bool  isConst,
bool  isPtr 
)

Creates a function decl for setters.

Parameters
varType: type of the var to set
varName: name of the var to set
className: name of the class
isConst: true if the function must be const
isPtr: true if te variable is a pointer
Returns
setters function decl

Definition at line 102 of file saveClassConfig.cpp.

102  {
103  PString functionDecl("");
104  functionDecl += makeVarType(varType, false, isConst, !isConst, isPtr) + " ";
105  if(className != "") functionDecl += className + "::";
106  functionDecl += "get" + varName.firstToUpper() + "()";
107  return functionDecl;
108 }
Extends the std::string.
Definition: PString.h:16
PString firstToUpper() const
Convert first letter of the PString in upper case.
Definition: PString.cpp:673
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.

References PString::firstToUpper(), and makeVarType().

Referenced by saveClassGettersImpl(), and saveDeclGetters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createSetterDecl()

PString createSetterDecl ( const PString varType,
const PString varName,
const PString className,
bool  isPtr 
)

Creates a function decl for setters.

Parameters
varType: type of the var to set
varName: name of the var to set
className: name of the class
isPtr: true if te variable is a pointer
Returns
setters function decl

Definition at line 85 of file saveClassConfig.cpp.

85  {
86  PString functionDecl("void ");
87  if(className != "") functionDecl += className + "::";
88  functionDecl += "set" + varName.firstToUpper() + "(";
89  functionDecl += makeVarType(varType, true, true, false, isPtr);
90  functionDecl += " " + varName + ")";
91  return functionDecl;
92 }

References PString::firstToUpper(), and makeVarType().

Referenced by saveClassSettersImpl(), and saveDeclSetters().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getClassDeclTempalteDef()

PString getClassDeclTempalteDef ( const PVecString listTemplate)

Get the template definition in the class declaration.

Parameters
listTemplate: list of template def
Returns
template definition in the class declaration (template< .... >)

Definition at line 180 of file saveClassConfig.cpp.

180  {
181  if(listTemplate.size() == 0lu){return "";}
182  PString templateDef("template<");
183  PString comma("");
184  for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
185  templateDef += comma;
186  templateDef += *it;
187  comma = ", ";
188  }
189  templateDef += ">\n";
190  return templateDef;
191 }

Referenced by saveClassDecl(), and saveClassTemplate().

+ Here is the caller graph for this function:

◆ getClassDefTemplate()

PString getClassDefTemplate ( const PVecString listTemplate)

Get the template call in the class declaration.

Parameters
listTemplate: list of template def
Returns
template definition in the class declaration (< T, U, .... >)

Definition at line 197 of file saveClassConfig.cpp.

197  {
198  PString defTemplate("<"), comma("");
199  for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
200  defTemplate += comma + it->split(' ').back();
201  comma = ", ";
202  }
203  defTemplate += ">";
204  return defTemplate;
205 }

References PString::split().

Referenced by saveClassDecl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultValueTypeInCpp()

PString getDefaultValueTypeInCpp ( const PString type)

Get the default value of a type in C++.

Parameters
type: type to be converted
Returns
default value of the type in C++

Definition at line 33 of file saveClassConfig.cpp.

33  {
34  if(type == "PString"){
35  return "\"\"";
36  }else if(type == "char"){
37  return "0";
38  }else if(type == "unsigned char"){
39  return "0";
40  }else if(type == "int" || type == "short" || type == "unsigned short"){
41  return "0";
42  }else if(type == "unsigned int"){
43  return "0u";
44  }else if(type == "long int" || type == "long" || type == "ssize_t"){
45  return "0l";
46  }else if(type == "size_t" || type == "long unsigned int"){
47  return "0lu";
48  }else if(type == "bool"){
49  return "false";
50  }else{
51  return "";
52  }
53 }

Referenced by saveClassInitialisationFunctionImpl().

+ Here is the caller graph for this function:

◆ getIsPointer()

bool getIsPointer ( const PString varType)

Check if the given type is a pointer or not.

Parameters
varType: type to be checked
Returns
true if the given type is a pointer, false otherwise

Definition at line 24 of file saveClassConfig.cpp.

24  {
25  if(varType.size() == 0lu){return false;}
26  return varType.find('*') && varType.back() == '*';
27 }
bool find(char ch) const
Find a char in a string.
Definition: PString.cpp:371

References PString::find().

Referenced by saveClassInitialisationFunctionImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIsSimpleType()

bool getIsSimpleType ( const PString varType)

Check if the given type is a simple type.

Parameters
varType: type to be checked
Returns
true if the given type is a simple type, false otherwise

Definition at line 15 of file saveClassConfig.cpp.

15  {
16  PString restVarName(varType.replace("unsigned", "").eraseChar(" \n\t*&"));
17  return (restVarName == "char" || restVarName == "short" || restVarName == "int" || restVarName == "float" || restVarName == "double" || restVarName == "bool" || restVarName == "long" || restVarName == "longint" || restVarName == "size_t" || restVarName == "ssize_t" || restVarName == "void");
18 }
PString replace(const PString &pattern, const PString &replaceStr) const
Replace a PString into an other PString.
Definition: PString.cpp:204
PString eraseChar(char ch) const
Erase char ch of current string.
Definition: PString.cpp:478

References PString::eraseChar(), and PString::replace().

Referenced by createCheckClassEquality(), makeVarType(), project_wrapper_attributeDef(), project_wrapper_classAttributeFromMessage(), project_wrapper_classAttributeGetSize(), project_wrapper_classAttributeToMessage(), project_wrapper_classGetterSetterDef(), project_wrapper_classImpl(), project_wrapper_classImplCheck(), project_wrapper_classImplDealloc(), project_wrapper_classImplGetterSetter(), project_wrapper_classImplNewc(), and saveClassInitialisationFunctionImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeVarType()

PString makeVarType ( const PString varType,
bool  isSetter,
bool  isConst,
bool  isRef,
bool  isPtr 
)

Makes the var type by taking account of the type.

Parameters
varType: variable type name
isSetter: true if the type is made for a setter
isConst: true if the type must be const
isRef: true if the variable is a reference
isPtr: true if te variable is a pointer
Returns
var type by taking account of the type

Definition at line 63 of file saveClassConfig.cpp.

63  {
64  PString varTypeName("");
65 // std::cout << "makeVarType : varType = '" << varType << "'" << std::endl;
66  bool isSimpleType = getIsSimpleType(varType);
67  if(isSimpleType || isPtr){
68  if(isConst && !isSetter && (!isSimpleType || isPtr)) varTypeName += "const ";
69  varTypeName += varType;
70  if(isRef && !isPtr) varTypeName += " &";
71  }else{
72  if(isConst && !isPtr) varTypeName += "const ";
73  varTypeName += varType + " &";
74  }
75  return varTypeName;
76 }
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.

References getIsSimpleType().

Referenced by createGetterDecl(), and createSetterDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassConstructorImpl()

void saveClassConstructorImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves constructor of the class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 388 of file saveClassConfig.cpp.

388  {
389  PString name(classConfig.getName());
390  fs << "///Constructor of class " << name << std::endl;
391  fs << templateDeclaration;
392  fs << name << defTemplate << "::" << name << "()";
393  if(classConfig.getListParentClass().size() != 0lu){
394  PVecString::const_iterator it(classConfig.getListParentClass().begin());
395  fs << std::endl << "\t: " << *it << "()";
396  if(classConfig.getListParentClass().size() > 1lu){
397  while(it != classConfig.getListParentClass().end()){
398  fs << ", " << *it << "()";
399  ++it;
400  }
401  }
402  fs << std::endl;
403  }
404  fs << "{" << std::endl;
405  fs << "\tinitialisation" << name << "();" << std::endl;
406  fs << "}" << std::endl << std::endl;
407 }
const PString & getName() const
Returns the class name.
const PVecString & getListParentClass() const
Returns the list of the parents of the class.

References PClassConfig::getListParentClass(), and PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassCopyConstructorImpl()

void saveClassCopyConstructorImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves copy constructor of the class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 415 of file saveClassConfig.cpp.

415  {
416  PString name(classConfig.getName());
417  fs << "///Copy Constructor of class " << name << std::endl;
418  fs << "/**\t@param other : " << name << " we want ot copy" << std::endl;
419  fs << "*/" << std::endl;
420  fs << templateDeclaration;
421  fs << name << defTemplate << "::" << name << "(const " << name << defTemplate << " & other){" << std::endl;
422  fs << "\tcopy" << name << "(other);" << std::endl;
423  fs << "}" << std::endl << std::endl;
424 }

References PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassCopyFunctionImpl()

void saveClassCopyFunctionImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves the copy function of a class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 511 of file saveClassConfig.cpp.

511  {
512  PString name(classConfig.getName());
513  fs << "///Copy Function of class " << name << std::endl;
514  fs << "/**\t@param other : " << name << " we want ot copy" << std::endl;
515  fs << "*/" << std::endl;
516  fs << templateDeclaration;
517  fs << "void " << name << defTemplate << "::copy" << name << "(const " << name << defTemplate << " & other){" << std::endl;
518  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
519  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
520  fs << "\tp_" << it->getName() << " = other.p_" << it->getName() << ";" << std::endl;
521  }
522  fs << "}" << std::endl << std::endl;
523 }
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.

References PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassDataStreamGenericFunction()

void saveClassDataStreamGenericFunction ( std::ofstream &  fs,
const PClassConfig classConfig 
)

Creates the method which enable to save/load generated class with any kind of stream/message/file.

Parameters
[out]fs: header file name
classConfig: class config we want to save

Definition at line 161 of file saveClassConfig.cpp.

161  {
162  PString name(classConfig.getName());
163  fs << "///@brief Generic "<<name<<" serialisation/deserialisation, load/save and size function" << std::endl;
164  fs << "template<typename Stream, DataStreamMode::DataStreamMode Mode>" << std::endl;
165  fs << "struct DataStream<Stream, Mode, "<<name<<">{" << std::endl;
166  fs << "\t///Generic function to load/save/serialise/deserialise "<<name << std::endl;
167  fs << "\t/**\t@param data : "<<name<<" to be used" << std::endl;
168  fs << "\t * \t@return true on success, false otherwise" << std::endl;
169  fs << "\t*/" << std::endl;
170  fs << "\tstatic bool data_stream(Stream & ds, "<<name<<" & data){" << std::endl;
171  fs << "\t\treturn data.readWriteStream<Stream, Mode>(ds);" << std::endl;
172  fs << "\t}" << std::endl;
173  fs << "};" << std::endl << std::endl;
174 }

References PClassConfig::getName().

Referenced by saveClassDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassDataStreamMethod()

void saveClassDataStreamMethod ( std::ofstream &  fs,
const PClassConfig classConfig 
)

Creates the method which enable to save/load generated class with any kind of stream/message/file.

Parameters
[out]fs: header file name
classConfig: class config we want to save

Definition at line 137 of file saveClassConfig.cpp.

137  {
138  PString name(classConfig.getName());
139  fs << std::endl;
140  fs << "\t\t///Load the current "<<name<<" with a stream" << std::endl;
141  fs << "\t\t/** @param[out] ds : stream to be used" << std::endl;
142  fs << "\t\t * @return true on success, false otherwise" << std::endl;
143  fs << "\t\t*/" << std::endl;
144  fs << "\t\ttemplate<typename Stream, DataStreamMode::DataStreamMode Mode>" << std::endl;
145  fs << "\t\tbool readWriteStream(Stream & ds){" << std::endl;
146  fs << "\t\t\tbool b(true);" << std::endl;
147 
148  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
149  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
150  fs << "\t\t\tb &= DataStream<Stream, Mode, "<<it->getType()<<" >::data_stream(ds, p_" << it->getName() << ");" << std::endl;
151  }
152 
153  fs << "\t\t\treturn b;" << std::endl;
154  fs << "\t\t}" << std::endl << std::endl;
155 }

References PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by saveClassDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassDecl() [1/2]

bool saveClassDecl ( const std::vector< PClassConfig > &  classConfig,
const PPath headerFile,
const PVecPath listInclude,
bool  enableDataStream,
bool  enableTypeStream,
const PString includeTemplate 
)

Creates header file.

Parameters
classConfig: class config we want to save
headerFile: header file name
listInclude: list of the include files
enableDataStream: true to enable the serialization/deserialization with DataStream, false otherwise
enableTypeStream: true to enable the phoenix_getTypeName function creation
includeTemplate: include to the template implementation file
Returns
true on success, false otherwise

Definition at line 587 of file saveClassConfig.cpp.

589 {
590  if(headerFile == "") return false;
591  std::ofstream fs;
592  fs.open(headerFile.c_str());
593  if(!fs.is_open()){
594  std::cerr << "saveClassDecl : can't open file '" << headerFile << "'" << std::endl;
595  return false;
596  }
597  licenceSave(fs);
598  PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName()));
599  fs << "#ifndef " << macroDef << std::endl;
600  fs << "#define " << macroDef << std::endl << std::endl;
601  if(listInclude.size() != 0lu){
602  for(PVecPath::const_iterator it(listInclude.begin()); it != listInclude.end(); ++it){
603  fs << "#include " << *it << std::endl;
604  }
605  fs << std::endl;
606  }
607  if(enableDataStream){
608  fs << "#include \"data_all.h\"" << std::endl << std::endl;
609  }
610  if(enableTypeStream){
611  fs << "#include \"phoenix_type_stream.h\"" << std::endl << std::endl;
612  }
613 
614  for(std::vector<PClassConfig>::const_iterator it(classConfig.begin()); it != classConfig.end(); ++it){
615  if(it->getIsEnum()){
616  saveEnumDecl(fs, *it, enableDataStream, enableTypeStream);
617  }else{
618  saveClassDecl(fs, *it, enableDataStream, enableTypeStream);
619  }
620  }
621 
622  if(includeTemplate != ""){
623  fs << "#include \""<<includeTemplate<<"\"" << std::endl << std::endl;
624  }
625 
626  fs << std::endl << std::endl << "#endif" << std::endl << std::endl;
627  fs.close();
628  return true;
629 }
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
PString makeMultiIncludeDefineMacro(const PString &fileName)
Create the macro of multi inclusion file name.
void licenceSave(std::ofstream &fs)
Saves the policy.
void saveClassDecl(std::ofstream &fs, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
Creates header file.
void saveEnumDecl(std::ofstream &fs, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
Creates header file.

References PPath::getFileName(), licenceSave(), makeMultiIncludeDefineMacro(), saveClassDecl(), and saveEnumDecl().

+ Here is the call graph for this function:

◆ saveClassDecl() [2/2]

void saveClassDecl ( std::ofstream &  fs,
const PClassConfig classConfig,
bool  enableDataStream,
bool  enableTypeStream 
)

Creates header file.

Parameters
[out]fs: header file name
classConfig: class config we want to save
enableDataStream: true to enable the serialization/deserialization with DataStream, false otherwise
enableTypeStream: true to enable the phoenix_getTypeName function creation

Definition at line 279 of file saveClassConfig.cpp.

279  {
280  if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl;
281  PString name(classConfig.getName());
282  const PVecString & listTemplate = classConfig.getListTemplate();
283  if(listTemplate.size() != 0lu){
284  fs << getClassDeclTempalteDef(listTemplate);
285  }
286  fs << "class " << name;
287  if(classConfig.getListParentClass().size() != 0lu){
288  PVecString::const_iterator it(classConfig.getListParentClass().begin());
289  fs << " : public " << *it;
290  if(classConfig.getListParentClass().size() > 1lu){
291  while(it != classConfig.getListParentClass().end()){
292  fs << ", " << *it;
293  ++it;
294  }
295  }
296  }
297  fs << "{" << std::endl;
298  fs << "\tpublic:" << std::endl;
299  fs << "\t\t" << name << "();" << std::endl;
300  fs << "\t\t" << name << "(const " << name << " & other);" << std::endl;
301  fs << "\t\tvirtual ~" << name << "();" << std::endl;
302  fs << "\t\t" << name << " & operator = (const " << name << " & other);" << std::endl;
303  saveDeclSetters(fs, classConfig);
304  saveDeclGetters(fs, classConfig);
305 
306  if(enableDataStream){
307  saveClassDataStreamMethod(fs, classConfig);
308  }
309 
310  fs << "\tprotected:" << std::endl;
311  fs << "\t\tvoid copy" << name << "(const " << name << " & other);" << std::endl;
312 
313  fs << "\tprivate:" << std::endl;
314  fs << "\t\tvoid initialisation" << name << "();" << std::endl;
315  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
316  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
317  if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl;
318 
319  fs << "\t\t" << it->getType() << " p_" << it->getName() << ";" << std::endl;
320  }
321  fs << "};" << std::endl << std::endl;
322 
323  if(enableDataStream){
324  saveClassDataStreamGenericFunction(fs, classConfig);
325  fs << std::endl << std::endl;
326  }
327  if(enableTypeStream){
328  if(listTemplate.size() != 0lu){
329  fs << "///Get the name of the class " << name << std::endl;
330  fs << "/**\t@return name of the class " << name << std::endl;
331  fs << "*/" << std::endl;
332  fs << getClassDeclTempalteDef(listTemplate);
333  fs << "std::string phoenix_getTypeName<"<<name << getClassDefTemplate(listTemplate) <<" >(){" << std::endl;
334  fs << "\treturn \""<<name<<"\"";
335  fs << " + \"<\"";
336  for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
337  fs << " + phoenix_getTypeToStr<"<<it->split(' ').back()<<">()";
338  }
339  fs << " + \">\"";
340  fs << ";" << std::endl;
341  fs << "}" << std::endl << std::endl;
342 
343  }else{
344  fs << "template<>" << std::endl;
345  fs << "std::string phoenix_getTypeName<"<<name<<">();" << std::endl << std::endl;
346  }
347  }
348 }
std::vector< PString > PVecString
Definition: PString.h:96
const PString & getClassDocumentation() const
Returns the class documentation.
const PVecString & getListTemplate() const
Returns the list of the template of the class.
std::vector< PString > split(char separator) const
Cut a PString on the given separator char.
Definition: PString.cpp:420
PString getClassDefTemplate(const PVecString &listTemplate)
Get the template call in the class declaration.
void saveClassDataStreamGenericFunction(std::ofstream &fs, const PClassConfig &classConfig)
Creates the method which enable to save/load generated class with any kind of stream/message/file.
void saveDeclGetters(std::ofstream &fs, const PClassConfig &classConfig)
Creates getters header file.
void saveClassDataStreamMethod(std::ofstream &fs, const PClassConfig &classConfig)
Creates the method which enable to save/load generated class with any kind of stream/message/file.
PString getClassDeclTempalteDef(const PVecString &listTemplate)
Get the template definition in the class declaration.
void saveDeclSetters(std::ofstream &fs, const PClassConfig &classConfig)
Creates setters header file.

References getClassDeclTempalteDef(), getClassDefTemplate(), PClassConfig::getClassDocumentation(), PClassConfig::getListAttribute(), PClassConfig::getListParentClass(), PClassConfig::getListTemplate(), PClassConfig::getName(), saveClassDataStreamGenericFunction(), saveClassDataStreamMethod(), saveDeclGetters(), saveDeclSetters(), and PString::split().

Referenced by saveClassDecl(), and saveClassImplDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassDestructorImpl()

void saveClassDestructorImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves destructor of the class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 432 of file saveClassConfig.cpp.

432  {
433  PString name(classConfig.getName());
434  fs << "///Destructor of class " << name << std::endl;
435  fs << templateDeclaration;
436  fs << name << defTemplate << "::~" << name << "(){" << std::endl;
437  fs << "\t" << std::endl;
438  fs << "}" << std::endl << std::endl;
439 }

References PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassEqualOperatorImpl()

void saveClassEqualOperatorImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves = operator of the class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 447 of file saveClassConfig.cpp.

447  {
448  PString name(classConfig.getName());
449  fs << "///Operator = of class " << name << std::endl;
450  fs << "/**\t@param other : " << name << " we want ot copy" << std::endl;
451  fs << " * \t@return copied class " << name << std::endl;
452  fs << "*/" << std::endl;
453  fs << templateDeclaration;
454  fs << name << defTemplate << " & " << name << defTemplate << "::operator =" << " (const " << name << defTemplate << " & other){" << std::endl;
455  fs << "\tcopy" << name << "(other);" << std::endl;
456  fs << "\treturn *this;" << std::endl;
457  fs << "}" << std::endl << std::endl;
458 }

References PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassGettersImpl()

void saveClassGettersImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves the class getters implementation.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 485 of file saveClassConfig.cpp.

485  {
486  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
487  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
488  fs << "///Gets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
489  fs << "/**\t@return " << it->getName() << " of the " << classConfig.getName() << std::endl;
490  fs << "*/" << std::endl;
491  fs << templateDeclaration;
492  fs << createGetterDecl(it->getType(), it->getName(), classConfig.getName() + defTemplate, true, it->getIsPointer()) << " const{" << std::endl;
493  fs << "\treturn p_" << it->getName() << ";" << std::endl;
494  fs << "}" << std::endl << std::endl;
495  fs << "///Gets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
496  fs << "/**\t@return " << it->getName() << " of the " << classConfig.getName() << std::endl;
497  fs << "*/" << std::endl;
498  fs << templateDeclaration;
499  fs << createGetterDecl(it->getType(), it->getName(), classConfig.getName() + defTemplate, false, it->getIsPointer()) << "{" << std::endl;
500  fs << "\treturn p_" << it->getName() << ";" << std::endl;
501  fs << "}" << std::endl << std::endl;
502  }
503 }
PString createGetterDecl(const PString &varType, const PString &varName, const PString &className, bool isConst, bool isPtr)
Creates a function decl for setters.

References createGetterDecl(), PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassGetTypeNameImpl()

void saveClassGetTypeNameImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration,
bool  enableTypeStream 
)

Saves constructor of the class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)
enableTypeStream: true to enable the phoenix_getTypeName function creation

Definition at line 357 of file saveClassConfig.cpp.

357  {
358  if(!enableTypeStream){return;}
359  PString name(classConfig.getName());
360  fs << "///Get the name of the class " << name << std::endl;
361  fs << "/**\t@return name of the class " << name << std::endl;
362  fs << "*/" << std::endl;
363  const PVecString & listTemplate = classConfig.getListTemplate();
364  if(listTemplate.size() == 0lu){
365  fs << "template<>" << std::endl;
366  }else{
367  fs << templateDeclaration;
368  }
369  fs << "std::string phoenix_getTypeName<"<<name << defTemplate <<" >(){" << std::endl;
370  fs << "\treturn \""<<name<<"\"";
371  if(listTemplate.size() != 0lu){
372  fs << " + \"<\"";
373  for(PVecString::const_iterator it(listTemplate.begin()); it != listTemplate.end(); ++it){
374  fs << " + phoenix_getTypeToStr<"<<it->split(' ').back()<<">()";
375  }
376  fs << " + \">\"";
377  }
378  fs << ";" << std::endl;
379  fs << "}" << std::endl << std::endl;
380 }

References PClassConfig::getListTemplate(), PClassConfig::getName(), and PString::split().

Referenced by saveClassImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassImpl() [1/2]

bool saveClassImpl ( const std::vector< PClassConfig > &  classConfig,
const PPath sourceFile,
const PPath headerFile,
bool  enableTypeStream 
)

Creates source file.

Parameters
classConfig: class config we want to save
sourceFile: source file name
headerFile: header file name
enableTypeStream: true to enable the phoenix_getTypeName function creation
Returns
true on success, false otherwise

Definition at line 638 of file saveClassConfig.cpp.

638  {
639  if(sourceFile == "" || headerFile == "") return false;
640  std::ofstream fs;
641  fs.open(sourceFile.c_str());
642  if(!fs.is_open()){
643  std::cerr << "saveClassImpl : can't open file '" << sourceFile << "'" << std::endl;
644  return true;
645  }
646  licenceSave(fs);
647  fs << std::endl << "#include \"" << headerFile.getFileName() << "\"" << std::endl << std::endl;
648  for(std::vector<PClassConfig>::const_iterator it(classConfig.begin()); it != classConfig.end(); ++it){
649  if(it->getIsEnum()){continue;}
650  saveClassImpl(fs, *it, enableTypeStream);
651  }
652  fs.close();
653  return true;
654 }
void saveClassImpl(std::ofstream &fs, const PClassConfig &classConfig, bool enableTypeStream)
Creates source file.

References PPath::getFileName(), licenceSave(), and saveClassImpl().

+ Here is the call graph for this function:

◆ saveClassImpl() [2/2]

void saveClassImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
bool  enableTypeStream 
)

Creates source file.

Parameters
[out]fs: source file
classConfig: PClassConfig we vant to save
enableTypeStream: true to enable the phoenix_getTypeName function creation

Definition at line 566 of file saveClassConfig.cpp.

566  {
567  saveClassGetTypeNameImpl(fs, classConfig, "", "", enableTypeStream);
568  saveClassConstructorImpl(fs, classConfig, "", "");
569  saveClassCopyConstructorImpl(fs, classConfig, "", "");
570  saveClassDestructorImpl(fs, classConfig, "", "");
571  saveClassEqualOperatorImpl(fs, classConfig, "", "");
572  saveClassSettersImpl(fs, classConfig, "", "");
573  saveClassGettersImpl(fs, classConfig, "", "");
574  saveClassCopyFunctionImpl(fs, classConfig, "", "");
575  saveClassInitialisationFunctionImpl(fs, classConfig, "", "");
576 }
void saveClassGetTypeNameImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration, bool enableTypeStream)
Saves constructor of the class.
void saveClassCopyConstructorImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves copy constructor of the class.
void saveClassGettersImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves the class getters implementation.
void saveClassSettersImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves the class setters implementation.
void saveClassCopyFunctionImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves the copy function of a class.
void saveClassConstructorImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves constructor of the class.
void saveClassEqualOperatorImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves = operator of the class.
void saveClassDestructorImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves destructor of the class.
void saveClassInitialisationFunctionImpl(std::ofstream &fs, const PClassConfig &classConfig, const PString &defTemplate, const PString &templateDeclaration)
Saves the copy function of a class.

References saveClassConstructorImpl(), saveClassCopyConstructorImpl(), saveClassCopyFunctionImpl(), saveClassDestructorImpl(), saveClassEqualOperatorImpl(), saveClassGettersImpl(), saveClassGetTypeNameImpl(), saveClassInitialisationFunctionImpl(), and saveClassSettersImpl().

Referenced by saveClassImpl(), and saveClassImplDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassImplDecl()

bool saveClassImplDecl ( const std::vector< PClassConfig > &  classConfig,
const PPath baseFileName,
const PVecPath listInclude,
bool  enableDataStream,
bool  enableTypeStream 
)

Creates header file.

Parameters
classConfig: class config we want to save
baseFileName: base file name for header or source file
listInclude: list of the include files
enableDataStream: true to enable the serialization/deserialization with DataStream, false otherwise
enableTypeStream: true to enable the phoenix_getTypeName function creation
Returns
true on success, false otherwise

Definition at line 728 of file saveClassConfig.cpp.

728  {
729  if(baseFileName == "") return false;
730  bool hasSource(false), hasTemplate(false);
731  checkClassConfig(hasSource, hasTemplate, classConfig);
732  PPath includeTemplate("");
733  if(hasTemplate){
734  includeTemplate = PString(baseFileName.getFileName() + "_impl.h");
735  }
736 
737  if(!saveClassDecl(classConfig, PString(baseFileName + ".h"), listInclude, enableDataStream, enableTypeStream, includeTemplate)) return false;
738 
739  if(hasSource){
740  if(!saveClassImpl(classConfig, PPath(baseFileName + PString(".cpp")), PPath(baseFileName + PString(".h")), enableTypeStream)) return false;
741  }
742  if(hasTemplate){
743  if(!saveClassTemplate(classConfig, PPath(baseFileName + PString("_impl.h")), PPath(baseFileName + PString(".h")))) return false;
744  }
745  return true;
746 }
Path of a directory or a file.
Definition: PPath.h:17
void saveClassTemplate(std::ofstream &fs, const PClassConfig &classConfig)
Creates template implementation file.
void checkClassConfig(bool &hasSource, bool &hasTemplate, const std::vector< PClassConfig > &classConfig)
Check if the configuration has source or template to determine if the .cpp or _impl....

References checkClassConfig(), PPath::getFileName(), saveClassDecl(), saveClassImpl(), and saveClassTemplate().

Referenced by saveParserClassConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassInitialisationFunctionImpl()

void saveClassInitialisationFunctionImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves the copy function of a class.

Parameters
[out]fs: header file name
classConfig: PClassConfig we vant to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 531 of file saveClassConfig.cpp.

533 {
534  PString name(classConfig.getName());
535  fs << "///Initialisation Function of class " << name << std::endl;
536  fs << templateDeclaration;
537  fs << "void " << name << defTemplate << "::initialisation" << name << "(){" << std::endl;
538  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
539  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
540  if(it->getDefaultValue() != ""){
541  fs << "\tp_" << it->getName() << " = "<<it->getDefaultValue()<<";" << std::endl;
542  }else{
543  PString varType(it->getType());
544  bool isSimpleType = getIsSimpleType(varType);
545  bool isPtr(getIsPointer(varType));
546  if(isPtr){
547  fs << "\tp_" << it->getName() << " = NULL;" << std::endl;
548  }else if(isSimpleType){
549  PString defaultValue(getDefaultValueTypeInCpp(varType));
550  if(defaultValue != ""){
551  fs << "\tp_" << it->getName() << " = "<<defaultValue<<";" << std::endl;
552  }
553  }else if(varType == "PString"){
554  fs << "\tp_" << it->getName() << " = \"\";" << std::endl;
555  }
556  }
557  }
558  fs << "}" << std::endl << std::endl;
559 }
bool getIsPointer(const PString &varType)
Check if the given type is a pointer or not.
PString getDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.

References getDefaultValueTypeInCpp(), getIsPointer(), getIsSimpleType(), PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassSettersImpl()

void saveClassSettersImpl ( std::ofstream &  fs,
const PClassConfig classConfig,
const PString defTemplate,
const PString templateDeclaration 
)

Saves the class setters implementation.

Parameters
[out]fs: header file name
classConfig: PClassConfig we want to save
defTemplate: extra template definition for the class name space
templateDeclaration: basic template declaration before each method (template< ... >)

Definition at line 466 of file saveClassConfig.cpp.

466  {
467  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
468  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
469  fs << "///Sets the " << it->getName() << " of the " << classConfig.getName() << std::endl;
470  fs << "/**\t@param " << it->getName() << " : " << it->getName() << " of the " << classConfig.getName() << std::endl;
471  fs << "*/" << std::endl;
472  fs << templateDeclaration;
473  fs << createSetterDecl(it->getType(), it->getName(), classConfig.getName() + defTemplate, it->getIsPointer()) << "{" << std::endl;
474  fs << "\tp_" << it->getName() << " = " << it->getName() << ";" << std::endl;
475  fs << "}" << std::endl << std::endl;
476  }
477 }
PString createSetterDecl(const PString &varType, const PString &varName, const PString &className, bool isPtr)
Creates a function decl for setters.

References createSetterDecl(), PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by saveClassImpl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveClassTemplate() [1/2]

bool saveClassTemplate ( const std::vector< PClassConfig > &  classConfig,
const PPath sourceFile,
const PPath headerFile 
)

Creates template implementation file.

Parameters
classConfig: class config we want to save
sourceFile: source file name
headerFile: header file name
Returns
true on success, false otherwise

Definition at line 684 of file saveClassConfig.cpp.

684  {
685  if(sourceFile == "" || headerFile == "") return false;
686  std::ofstream fs;
687  fs.open(sourceFile.c_str());
688  if(!fs.is_open()){
689  std::cerr << "saveClassTemplate : can't open file '" << sourceFile << "'" << std::endl;
690  return true;
691  }
692  licenceSave(fs);
693  PString macroDef(makeMultiIncludeDefineMacro(headerFile.getFileName() + "_IMPL"));
694  fs << "#ifndef " << macroDef << std::endl;
695  fs << "#define " << macroDef << std::endl << std::endl;
696  fs << std::endl << "#include \"" << headerFile.getFileName() << "\"" << std::endl << std::endl;
697  for(std::vector<PClassConfig>::const_iterator it(classConfig.begin()); it != classConfig.end(); ++it){
698  saveClassTemplate(fs, *it);
699  }
700  fs << "\n\n#endif\n\n" << std::endl;
701  fs.close();
702  return true;
703 }

References PPath::getFileName(), licenceSave(), makeMultiIncludeDefineMacro(), and saveClassTemplate().

+ Here is the call graph for this function:

◆ saveClassTemplate() [2/2]

void saveClassTemplate ( std::ofstream &  fs,
const PClassConfig classConfig 
)

Creates template implementation file.

Parameters
[out]fs: template implementation file
classConfig: PClassConfig we vant to save

Definition at line 661 of file saveClassConfig.cpp.

661  {
662  const PVecString & listTemplate = classConfig.getListTemplate();
663  if(listTemplate.size() == 0lu){return;}
664 
665  PString defTemplate(getClassDefTemplate(listTemplate));
666  PString templateDeclaration(getClassDeclTempalteDef(listTemplate));
667 
668  saveClassConstructorImpl(fs, classConfig, defTemplate, templateDeclaration);
669  saveClassCopyConstructorImpl(fs, classConfig, defTemplate, templateDeclaration);
670  saveClassDestructorImpl(fs, classConfig, defTemplate, templateDeclaration);
671  saveClassEqualOperatorImpl(fs, classConfig, defTemplate, templateDeclaration);
672  saveClassSettersImpl(fs, classConfig, defTemplate, templateDeclaration);
673  saveClassGettersImpl(fs, classConfig, defTemplate, templateDeclaration);
674  saveClassCopyFunctionImpl(fs, classConfig, defTemplate, templateDeclaration);
675  saveClassInitialisationFunctionImpl(fs, classConfig, defTemplate, templateDeclaration);
676 }

References getClassDeclTempalteDef(), getClassDefTemplate(), PClassConfig::getListTemplate(), saveClassConstructorImpl(), saveClassCopyConstructorImpl(), saveClassCopyFunctionImpl(), saveClassDestructorImpl(), saveClassEqualOperatorImpl(), saveClassGettersImpl(), saveClassInitialisationFunctionImpl(), and saveClassSettersImpl().

Referenced by saveClassImplDecl(), and saveClassTemplate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveDeclGetters()

void saveDeclGetters ( std::ofstream &  fs,
const PClassConfig classConfig 
)

Creates getters header file.

Parameters
[out]fs: header file name
classConfig: class config we want to save

Definition at line 125 of file saveClassConfig.cpp.

125  {
126  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
127  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
128  fs << "\t\t" << createGetterDecl(it->getType(), it->getName(), "", true, it->getIsPointer()) << " const;" << std::endl;
129  fs << "\t\t" << createGetterDecl(it->getType(), it->getName(), "", false, it->getIsPointer()) << ";" << std::endl;
130  }
131 }

References createGetterDecl(), and PClassConfig::getListAttribute().

Referenced by saveClassDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveDeclSetters()

void saveDeclSetters ( std::ofstream &  fs,
const PClassConfig classConfig 
)

Creates setters header file.

Parameters
[out]fs: header file name
classConfig: class config we want to save

Definition at line 114 of file saveClassConfig.cpp.

114  {
115  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
116  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
117  fs << "\t\t" << createSetterDecl(it->getType(), it->getName(), "", it->getIsPointer()) << ";" << std::endl;
118  }
119 }

References createSetterDecl(), and PClassConfig::getListAttribute().

Referenced by saveClassDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveEnumDecl()

void saveEnumDecl ( std::ofstream &  fs,
const PClassConfig classConfig,
bool  enableDataStream,
bool  enableTypeStream 
)

Creates header file.

Parameters
[out]fs: header file name
classConfig: class config we want to save
enableDataStream: true to enable the serialization/deserialization with DataStream, false otherwise
enableTypeStream: true to enable the phoenix_getTypeName function creation

Definition at line 213 of file saveClassConfig.cpp.

213  {
214  PString name(classConfig.getName());
215  fs << "namespace " << name << " {\n";
216  if(classConfig.getClassDocumentation() != "") fs << classConfig.getClassDocumentation() << std::endl;
217  fs << "\tenum " << name << " {\n\t\t";
218  PString comma("");
219  const std::vector<PClassAttribute> & listAttr(classConfig.getListAttribute());
220  for(std::vector<PClassAttribute>::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
221  if(it->getDocumentation() != "") fs << "\t\t" << it->getDocumentation() << std::endl;
222  fs << comma << it->getName();
223  if(it->getDefaultValue() != ""){
224  fs << " = " << it->getDefaultValue();
225  }
226  comma = ",\n\t\t";
227  }
228  fs << "\n\t};" << std::endl;
229  fs << "}" << std::endl << std::endl;
230 
231  if(enableDataStream){
232  fs << "///@brief Generic "<<name << " deserialisation, load and size function for a "<<name << "::"<<name << "" << std::endl;
233  fs << "template<typename Stream>" << std::endl;
234  fs << "struct DataStream<Stream, DataStreamMode::READ, "<<name << "::"<<name << ">{" << std::endl;
235  fs << "\t///Generic function to load/deserialise "<<name << "" << std::endl;
236  fs << "\t/**\t@param[out] ds : Stream to be used" << std::endl;
237  fs << "\t * \t@param data : "<<name << " to be loaded" << std::endl;
238  fs << "\t * \t@return true on success, false otherwise" << std::endl;
239  fs << "\t*/" << std::endl;
240  fs << "\tstatic bool data_stream(Stream & ds, "<<name << "::"<<name << " & data){" << std::endl;
241  fs << "\t\tint value(0);" << std::endl;
242  fs << "\t\tbool b = DataStream<Stream, DataStreamMode::READ, int>::data_stream(ds, value);" << std::endl;
243  fs << "\t\tdata = ("<<name << "::"<<name << ")value;" << std::endl;
244  fs << "\t\treturn b;" << std::endl;
245  fs << "\t}" << std::endl;
246  fs << "};" << std::endl << std::endl;
247 
248  fs << "///@brief Generic "<<name << " serialisation, save and size function for a "<<name << "::"<<name << "" << std::endl;
249  fs << "template<typename Stream>" << std::endl;
250  fs << "struct DataStream<Stream, DataStreamMode::WRITE, "<<name << "::"<<name << ">{" << std::endl;
251  fs << "\t///Generic function to save/serialise "<<name << "" << std::endl;
252  fs << "\t/**\t@param[out] ds : Stream to be used" << std::endl;
253  fs << "\t * \t@param data : "<<name << " to be saved" << std::endl;
254  fs << "\t * \t@return true on success, false otherwise" << std::endl;
255  fs << "\t*/" << std::endl;
256  fs << "\tstatic bool data_stream(Stream & ds, "<<name << "::"<<name << " & data){" << std::endl;
257  fs << "\t\tint value = (int)data;" << std::endl;
258  fs << "\t\treturn DataStream<Stream, DataStreamMode::WRITE, int>::data_stream(ds, value);" << std::endl;
259  fs << "\t}" << std::endl;
260  fs << "};" << std::endl << std::endl;
261  }
262  if(enableTypeStream){
263  fs << "///Get the type name of "<<name << std::endl;
264  fs << "/**\t@return type name of "<<name << " as string" << std::endl;
265  fs << "*/" << std::endl;
266  fs << "template<>" << std::endl;
267  fs << "std::string phoenix_getTypeName<"<<name<<"::"<<name<<">(){" << std::endl;
268  fs << "\treturn \""<<name<<"\";" << std::endl;
269  fs << "}" << std::endl << std::endl;
270  }
271 }

References PClassConfig::getClassDocumentation(), PClassConfig::getListAttribute(), and PClassConfig::getName().

Referenced by saveClassDecl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: