PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
type_utils.cpp File Reference
#include "type_utils.h"
+ Include dependency graph for type_utils.cpp:

Go to the source code of this file.

Functions

PString generator_getListNestedType (const PString &type)
 Get the nested type inside a std::list.
 
bool generator_typeIsList (const PString &type)
 Say if a given type is a std::list.
 
PString getDefaultValueTypeInCpp (const PString &type)
 Get the default value of a type in C++.
 
bool getIsSimpleType (const PString &varType)
 Check if the given type is a simple type.
 
PString getTestDefaultValueTypeInCpp (const PString &type)
 Get the default value of a type in C++.
 
PString makeVarType (const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
 Makes the var type by taking account of the type.
 

Function Documentation

◆ generator_getListNestedType()

PString generator_getListNestedType ( const PString & type)

Get the nested type inside a std::list.

Parameters
type: type of be used
Returns
nested type in the std::list

Definition at line 22 of file type_utils.cpp.

22 {
23 if(!generator_typeIsList(type)){return "";}
24 PString subType(type.substr(9lu));
25 return subType.eraseFirstLastChar("<> \t\n");
26}
bool generator_typeIsList(const PString &type)
Say if a given type is a std::list.

References generator_typeIsList().

Referenced by data_stream_trait_wrapper_classAttributeFromMessage(), data_stream_trait_wrapper_classAttributeGetSize(), data_stream_trait_wrapper_classAttributeToMessage(), data_stream_trait_wrapper_classImplCheck(), and pythonGetDefaultTestValue().

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

◆ generator_typeIsList()

bool generator_typeIsList ( const PString & type)

Say if a given type is a std::list.

Parameters
type: type of be checked
Returns
true if the type is a std::list

Definition at line 14 of file type_utils.cpp.

14 {
15 return type.isSameBegining("std::list");
16}

Referenced by data_stream_trait_wrapper_classAttributeFromMessage(), data_stream_trait_wrapper_classAttributeGetSize(), data_stream_trait_wrapper_classAttributeToMessage(), data_stream_trait_wrapper_classImplCheck(), generator_getListNestedType(), pythonGetDefaultTestValue(), and wrapper_generator_class_implNewc().

+ 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 41 of file type_utils.cpp.

41 {
42 if(type == "PString" || type == "std::string"){
43 return "\"\"";
44 }else if(type == "PPath"){
45 return "\"\"";
46 }else if(type == "char"){
47 return "0";
48 }else if(type == "unsigned char"){
49 return "0";
50 }else if(type == "int" || type == "short"){
51 return "0";
52 }else if(type == "unsigned int" || type == "unsigned short"){
53 return "0u";
54 }else if(type == "long int" || type == "long" || type == "ssize_t"){
55 return "0l";
56 }else if(type == "size_t" || type == "long unsigned int"){
57 return "0lu";
58 }else if(type == "bool"){
59 return "false";
60 }else if(type == "float"){
61 return "0.0f";
62 }else if(type == "double"){
63 return "0.0";
64 }else{
65 return "";
66 }
67}

Referenced by class_saveClassInitialisationFunctionImpl().

+ 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 32 of file type_utils.cpp.

32 {
33 PString restVarName(varType.replace("unsigned", "").eraseChar(" \n\t*&"));
34 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");
35}

Referenced by class_createCheckClassEquality(), class_saveClassInitialisationFunctionImpl(), WrapperTraitGetterSetter::classMethodDeclaration(), WrapperTraitGetterSetter::classMethodImplementation(), data_stream_trait_wrapper_classAttributeFromMessage(), data_stream_trait_wrapper_classAttributeGetSize(), data_stream_trait_wrapper_classAttributeToMessage(), data_stream_trait_wrapper_classImplCheck(), makeVarType(), project_wrapper_attributeDef(), WrapperTraitGetterSetter::registerClassGetterSetter(), WrapperTraitGetterSetter::registerClassMember(), wrapper_generator_class_implDealloc(), and wrapper_generator_class_implNewc().

+ Here is the caller graph for this function:

◆ getTestDefaultValueTypeInCpp()

PString getTestDefaultValueTypeInCpp ( 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 73 of file type_utils.cpp.

73 {
74 if(type == "PString" || type == "std::string"){
75 return "\"Some string\"";
76 }else if(type == "PPath"){
77 return "\"Some/Path\"";
78 }else if(type == "char"){
79 return "8";
80 }else if(type == "unsigned char"){
81 return "32";
82 }else if(type == "int" || type == "short"){
83 return "42";
84 }else if(type == "unsigned int" || type == "unsigned short"){
85 return "32u";
86 }else if(type == "long int" || type == "long" || type == "ssize_t"){
87 return "328l";
88 }else if(type == "size_t" || type == "long unsigned int"){
89 return "3423420lu";
90 }else if(type == "bool"){
91 return "true";
92 }else if(type == "float"){
93 return "1.0f";
94 }else if(type == "double"){
95 return "1.0";
96 }else{
97 return "";
98 }
99}

Referenced by class_createTestClassCopy().

+ 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 109 of file type_utils.cpp.

109 {
110 PString varTypeName("");
111// std::cout << "makeVarType : varType = '" << varType << "'" << std::endl;
112 bool isSimpleType = getIsSimpleType(varType);
113 if(isSimpleType || isPtr){
114 if(isConst && !isSetter && (!isSimpleType || isPtr)){varTypeName += "const ";}
115 varTypeName += varType;
116 if(isRef && !isPtr){varTypeName += " &";}
117 }else{
118 if(isConst && !isPtr){varTypeName += "const ";}
119 varTypeName += varType + " &";
120 }
121 return varTypeName;
122}
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.

References getIsSimpleType().

Referenced by getter_createGetterDecl(), and setter_createSetterDecl().

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