PhoenixGenerator  3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
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 getIsPointerType (const PString &varType)
 Say if a given type is a pointer type (i.e. it ends with a '*').
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_getListNestedType(), and generator_typeIsList().

Referenced by data_stream_trait_wrapper_classAttributeFromMessage(), data_stream_trait_wrapper_classAttributeGetSize(), data_stream_trait_wrapper_classAttributeToMessage(), data_stream_trait_wrapper_classImplCheck(), generator_getListNestedType(), getRustType(), 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}

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(), generator_getListNestedType(), generator_typeIsList(), getRustAttributeDefaultValue(), getRustType(), getRustTypeIsCopy(), pythonGetDefaultTestValue(), and wrapper_generator_class_implNewc().

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

50 {
51 if(type == "PString" || type == "std::string"){
52 return "\"\"";
53 }else if(type == "PPath"){
54 return "\"\"";
55 }else if(type == "char"){
56 return "0";
57 }else if(type == "unsigned char"){
58 return "0";
59 }else if(type == "int" || type == "short"){
60 return "0";
61 }else if(type == "unsigned int" || type == "unsigned short"){
62 return "0U";
63 }else if(type == "long int" || type == "long" || type == "ssize_t"){
64 return "0l";
65 }else if(type == "size_t" || type == "long unsigned int"){
66 return "0LU";
67 }else if(type == "bool"){
68 return "false";
69 }else if(type == "float"){
70 return "0.0f";
71 }else if(type == "double"){
72 return "0.0";
73 }else{
74 return "";
75 }
76}

References getDefaultValueTypeInCpp().

Referenced by class_getAttributeDefaultInit(), and getDefaultValueTypeInCpp().

Here is the call graph for this function:
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 82 of file type_utils.cpp.

82 {
83 if(type == "PString" || type == "std::string"){
84 return "\"\"";
85 }else if(type == "PPath"){
86 return "\"\"";
87 }else if(type == "char" || type == "unsigned char" || type == "int" || type == "short" || type == "unsigned int" || type == "unsigned short"){
88 return "0";
89 }else if(type == "long int" || type == "long" || type == "ssize_t" || type == "size_t" || type == "long unsigned int"){
90 return "0";
91 }else if(type == "bool"){
92 return "False";
93 }else if(type == "float" || type == "double"){
94 return "0.0";
95 }else{
96 return "";
97 }
98}

References getDefaultValueTypeInPython().

Referenced by getDefaultValueTypeInPython().

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

◆ getIsPointerType()

bool getIsPointerType ( const PString & varType)

Say if a given type is a pointer type (i.e. it ends with a '*').

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

Definition at line 41 of file type_utils.cpp.

41 {
42 if(varType.size() == 0LU){return false;}
43 return varType.find('*') && varType.back() == '*';
44}

References getIsPointerType().

Referenced by class_getAttributeDefaultInit(), class_hasPointerAttribute(), class_savePointerOwnershipSpecialMembersImpl(), CppTraitConfigStream::classExtraFunctionImplementation(), copy_hasPointerAttribute(), getIsPointerType(), getRustAttributeDefaultValue(), getRustType(), getRustTypeIsCopy(), RustTraitGetterSetter::implMethodDeclaration(), CppTraitGetter::publicMethodDeclaration(), CppTraitSetter::publicMethodDeclaration(), CppTraitGetter::publicMethodImplementation(), CppTraitSetter::publicMethodImplementation(), and RustTraitGetterSetter::testFunction().

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 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}

References getIsSimpleType().

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

Here is the call graph for this function:
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 104 of file type_utils.cpp.

104 {
105 if(type == "PString" || type == "std::string"){
106 return "\"Some string\"";
107 }else if(type == "PPath"){
108 return "PPath(\"Some/Path\")";
109 }else if(type == "char"){
110 return "8";
111 }else if(type == "unsigned char"){
112 return "32";
113 }else if(type == "int" || type == "short"){
114 return "42";
115 }else if(type == "unsigned int" || type == "unsigned short"){
116 return "32u";
117 }else if(type == "long int" || type == "long" || type == "ssize_t"){
118 return "328l";
119 }else if(type == "size_t" || type == "long unsigned int"){
120 return "3423420LU";
121 }else if(type == "bool"){
122 return "true";
123 }else if(type == "float"){
124 return "1.0f";
125 }else if(type == "double"){
126 return "1.0";
127 }else{
128 return "";
129 }
130}

References getTestDefaultValueTypeInCpp().

Referenced by class_createTestClassCopy(), and getTestDefaultValueTypeInCpp().

Here is the call graph for this function:
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 136 of file type_utils.cpp.

136 {
137 if(type == "PString" || type == "std::string"){
138 return "\"Some string\"";
139 }else if(type == "PPath"){
140 return "\"Some/Path\"";
141 }else if(type == "char" || type == "unsigned char" || type == "int" || type == "short" || type == "unsigned int" || type == "unsigned short"){
142 return "42";
143 }else if(type == "long int" || type == "long" || type == "ssize_t" || type == "size_t" || type == "long unsigned int" || type == "time_t"){
144 return "328";
145 }else if(type == "bool"){
146 return "True";
147 }else if(type == "float" || type == "double"){
148 return "1.0";
149 }else{
150 return "";
151 }
152}

References getTestDefaultValueTypeInPython().

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

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

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

References getIsSimpleType(), and makeVarType().

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

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