PhoenixGenerator
2.8.0
Set of tools to generate code
Toggle main menu visibility
Loading...
Searching...
No Matches
type_utils.cpp
Go to the documentation of this file.
1
/***************************************
2
Auteur : Pierre Aubert
3
Mail : pierre.aubert@lapp.in2p3.fr
4
Licence : CeCILL-C
5
****************************************/
6
7
8
#include "
type_utils.h
"
9
11
14
bool
generator_typeIsList
(
const
PString & type){
15
return
type.isSameBegining(
"std::list"
);
16
}
17
19
22
PString
generator_getListNestedType
(
const
PString & type){
23
if
(!
generator_typeIsList
(type)){
return
""
;}
24
PString subType(type.substr(9lu));
25
return
subType.eraseFirstLastChar(
"<> \t\n"
);
26
}
27
29
32
bool
getIsSimpleType
(
const
PString & varType){
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
}
36
38
41
PString
getDefaultValueTypeInCpp
(
const
PString & type){
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
}
68
70
73
PString
getDefaultValueTypeInPython
(
const
PString & type){
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
""
;
88
}
89
}
90
92
95
PString
getTestDefaultValueTypeInCpp
(
const
PString & type){
96
if
(type ==
"PString"
|| type ==
"std::string"
){
97
return
"\"Some string\""
;
98
}
else
if
(type ==
"PPath"
){
99
return
"PPath(\"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
}
122
124
127
PString
getTestDefaultValueTypeInPython
(
const
PString & type){
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"
|| type ==
"time_t"
){
135
return
"328"
;
136
}
else
if
(type ==
"bool"
){
137
return
"True"
;
138
}
else
if
(type ==
"float"
|| type ==
"double"
){
139
return
"1.0"
;
140
}
else
{
141
return
""
;
142
}
143
}
144
146
153
PString
makeVarType
(
const
PString & varType,
bool
isSetter,
bool
isConst,
bool
isRef,
bool
isPtr){
154
PString varTypeName(
""
);
155
// std::cout << "makeVarType : varType = '" << varType << "'" << std::endl;
156
bool
isSimpleType =
getIsSimpleType
(varType);
157
if
(isSimpleType || isPtr){
158
if
(isConst && !isSetter && (!isSimpleType || isPtr)){varTypeName +=
"const "
;}
159
varTypeName += varType;
160
if
(isRef && !isPtr){varTypeName +=
" &"
;}
161
}
else
{
162
if
(isConst && !isPtr){varTypeName +=
"const "
;}
163
varTypeName += varType +
" &"
;
164
}
165
return
varTypeName;
166
}
167
168
169
170
getTestDefaultValueTypeInCpp
PString getTestDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.
Definition
type_utils.cpp:95
generator_getListNestedType
PString generator_getListNestedType(const PString &type)
Get the nested type inside a std::list.
Definition
type_utils.cpp:22
getDefaultValueTypeInPython
PString getDefaultValueTypeInPython(const PString &type)
Get default value for a given type in Python.
Definition
type_utils.cpp:73
generator_typeIsList
bool generator_typeIsList(const PString &type)
Say if a given type is a std::list.
Definition
type_utils.cpp:14
getTestDefaultValueTypeInPython
PString getTestDefaultValueTypeInPython(const PString &type)
Get default test value for a given type in Python.
Definition
type_utils.cpp:127
makeVarType
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.
Definition
type_utils.cpp:153
getDefaultValueTypeInCpp
PString getDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.
Definition
type_utils.cpp:41
getIsSimpleType
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.
Definition
type_utils.cpp:32
type_utils.h
src
Representation
type_utils.cpp
Generated by
1.17.0