PhoenixGenerator  2.0.0
Set of tools to generate code
saveClassConfig.h File Reference
#include <fstream>
#include "PClassConfig.h"
+ Include dependency graph for saveClassConfig.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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...
 
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)
 
void saveClassCopyConstructorImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
void saveClassCopyFunctionImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
bool saveClassDecl (const std::vector< PClassConfig > &classConfig, const PPath &headerFile, const PVecPath &listInclude, bool enableDataStream, bool enableTypeStream)
 
void saveClassDecl (std::ofstream &fs, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
 Creates header file. More...
 
void saveClassDestructorImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
void saveClassEqualOperatorImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
void saveClassGettersImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
bool saveClassImpl (const std::vector< PClassConfig > &classConfig, const PPath &sourceFile, const PPath &headerFile)
 
void saveClassImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
bool saveClassImplDecl (const std::vector< PClassConfig > &classConfig, const PPath &baseFileName, const PVecPath &listInclude=PVecPath(), bool enableDataStream=false, bool enableTypeStream=false)
 Creates header file. More...
 
void saveClassSettersImpl (std::ofstream &fs, const PClassConfig &classConfig)
 
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...
 

Function Documentation

◆ 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:

◆ 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 
)

◆ saveClassCopyConstructorImpl()

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

◆ saveClassCopyFunctionImpl()

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

◆ saveClassDecl() [1/2]

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

◆ 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 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.
const PVecString & getListParentClass() const
Returns the list of the parents 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 
)

◆ saveClassEqualOperatorImpl()

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

◆ saveClassGettersImpl()

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

◆ saveClassImpl() [1/2]

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

◆ saveClassImpl() [2/2]

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

◆ 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
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
void saveClassTemplate(std::ofstream &fs, const PClassConfig &classConfig)
Creates template implementation file.
void saveClassDecl(std::ofstream &fs, const PClassConfig &classConfig, bool enableDataStream, bool enableTypeStream)
Creates header file.
void saveClassImpl(std::ofstream &fs, const PClassConfig &classConfig, bool enableTypeStream)
Creates source 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:

◆ saveClassSettersImpl()

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

◆ 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 }
PString createGetterDecl(const PString &varType, const PString &varName, const PString &className, bool isConst, bool isPtr)
Creates a function decl for setters.

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 }
PString createSetterDecl(const PString &varType, const PString &varName, const PString &className, bool isPtr)
Creates a function decl for setters.

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

Referenced by saveClassDecl().

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