PhoenixGenerator  2.0.4
Set of tools to generate code
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
14bool generator_typeIsList(const PString & type){
15 return type.isSameBegining("std::list");
16}
17
19
22PString 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
32bool 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
41PString 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
73PString getTestDefaultValueTypeInCpp(const PString & type){
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}
100
102
109PString makeVarType(const PString & varType, bool isSetter, bool isConst, bool isRef, bool isPtr){
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}
123
124
PString getTestDefaultValueTypeInCpp(const PString &type)
Get the default value of a type in C++.
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 makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.
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.