PhoenixGenerator  2.2.0
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++.
 
PString getDefaultValueTypeInPython (const PString &type)
 Get default value for a given type in Python.
 
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 getTestDefaultValueTypeInPython (const PString &type)
 Get default test value for a given type in Python.
 
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:

◆ getDefaultValueTypeInPython()

PString getDefaultValueTypeInPython ( const PString & type)

Get default value for a given type in Python.

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

Definition at line 73 of file type_utils.cpp.

73 {
74 if(type == "PString" || type == "std::string"){
75 return "\"\"";
76 }else if(type == "PPath"){
77 return "\"\"";
78 }else if(type == "char" || type == "unsigned char" || type == "int" || type == "short" || type == "unsigned int" || type == "unsigned short"){
79 return "0";
80 }else if(type == "long int" || type == "long" || type == "ssize_t" || type == "size_t" || type == "long unsigned int"){
81 return "0";
82 }else if(type == "bool"){
83 return "False";
84 }else if(type == "float" || type == "double"){
85 return "0.0";
86 }else{
87 return "\"default_value\"";
88 }
89}

◆ 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 95 of file type_utils.cpp.

95 {
96 if(type == "PString" || type == "std::string"){
97 return "\"Some string\"";
98 }else if(type == "PPath"){
99 return "\"Some/Path\"";
100 }else if(type == "char"){
101 return "8";
102 }else if(type == "unsigned char"){
103 return "32";
104 }else if(type == "int" || type == "short"){
105 return "42";
106 }else if(type == "unsigned int" || type == "unsigned short"){
107 return "32u";
108 }else if(type == "long int" || type == "long" || type == "ssize_t"){
109 return "328l";
110 }else if(type == "size_t" || type == "long unsigned int"){
111 return "3423420lu";
112 }else if(type == "bool"){
113 return "true";
114 }else if(type == "float"){
115 return "1.0f";
116 }else if(type == "double"){
117 return "1.0";
118 }else{
119 return "";
120 }
121}

Referenced by class_createTestClassCopy().

+ Here is the caller graph for this function:

◆ getTestDefaultValueTypeInPython()

PString getTestDefaultValueTypeInPython ( const PString & type)

Get default test value for a given type in Python.

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

Definition at line 127 of file type_utils.cpp.

127 {
128 if(type == "PString" || type == "std::string"){
129 return "\"Some string\"";
130 }else if(type == "PPath"){
131 return "\"Some/Path\"";
132 }else if(type == "char" || type == "unsigned char" || type == "int" || type == "short" || type == "unsigned int" || type == "unsigned short"){
133 return "42";
134 }else if(type == "long int" || type == "long" || type == "ssize_t" || type == "size_t" || type == "long unsigned int"){
135 return "328";
136 }else if(type == "bool"){
137 return "True";
138 }else if(type == "float" || type == "double"){
139 return "1.0";
140 }else if(type.isSameBegining("std::vector")){
141 return "[0, 1, 2, 3, 4]";
142 }
143 else{
144 return "\"default_value\"";
145 }
146}

Referenced by NanobindTraitCheckStream::testFunction(), NanobindTraitDataStream::testFunction(), and NanobindTraitProperty::testFunction().

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

156 {
157 PString varTypeName("");
158// std::cout << "makeVarType : varType = '" << varType << "'" << std::endl;
159 bool isSimpleType = getIsSimpleType(varType);
160 if(isSimpleType || isPtr){
161 if(isConst && !isSetter && (!isSimpleType || isPtr)){varTypeName += "const ";}
162 varTypeName += varType;
163 if(isRef && !isPtr){varTypeName += " &";}
164 }else{
165 if(isConst && !isPtr){varTypeName += "const ";}
166 varTypeName += varType + " &";
167 }
168 return varTypeName;
169}
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.

References getIsSimpleType().

Referenced by getter_createGetterDecl(), NanobindTraitProperty::registerProperty(), and setter_createSetterDecl().

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