1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // Classe pour nom, taille, ... de types de donnees
|
---|
3 | // C.Magneville 10/2000
|
---|
4 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
5 |
|
---|
6 | #include "datatype.h"
|
---|
7 | #include <typeinfo>
|
---|
8 | #include <string.h>
|
---|
9 |
|
---|
10 | #include <complex>
|
---|
11 |
|
---|
12 | namespace SOPHYA {
|
---|
13 |
|
---|
14 | template <class T>
|
---|
15 | DataTypeInfo<T>::DataTypeInfo()
|
---|
16 | {
|
---|
17 | }
|
---|
18 | #if defined(__SGICC__)
|
---|
19 | template <class T>
|
---|
20 | string DataTypeInfo<T>::getTypeName()
|
---|
21 | {
|
---|
22 | if (typeid(T) == typeid(uint_1)) return("uint_1");
|
---|
23 | else if (typeid(T) == typeid(uint_2)) return("uint_2");
|
---|
24 | else if (typeid(T) == typeid(int_2)) return("int_2");
|
---|
25 | else if (typeid(T) == typeid(int_4)) return("int_4");
|
---|
26 | else if (typeid(T) == typeid(int_8)) return("int_8");
|
---|
27 | else if (typeid(T) == typeid(uint_4)) return("uint_4");
|
---|
28 | else if (typeid(T) == typeid(uint_8)) return("uint_8");
|
---|
29 | else if (typeid(T) == typeid(r_4)) return("r_4");
|
---|
30 | else if (typeid(T) == typeid(r_8)) return("r_8");
|
---|
31 | else if (typeid(T) == typeid(complex<r_4>)) return(" complex<r_4> ");
|
---|
32 | else if (typeid(T) == typeid(complex<r_8>)) return(" complex<r_8> ");
|
---|
33 | #ifdef SO_LDBLE128
|
---|
34 | else if (typeid(T) == typeid(r_16)) return("r_16");
|
---|
35 | else if (typeid(T) == typeid(complex<r_16>)) return(" complex<r_16> ");
|
---|
36 | #endif
|
---|
37 | else return("???unknowntype???");
|
---|
38 | }
|
---|
39 | template <class T>
|
---|
40 | int DataTypeInfo<T>::getTypeId()
|
---|
41 | {
|
---|
42 | if (typeid(T) == typeid(uint_1)) return(1);
|
---|
43 | else if (typeid(T) == typeid(int_1)) return(2);
|
---|
44 | else if (typeid(T) == typeid(uint_2)) return(3);
|
---|
45 | else if (typeid(T) == typeid(int_2)) return(4);
|
---|
46 | else if (typeid(T) == typeid(uint_4)) return(5);
|
---|
47 | else if (typeid(T) == typeid(int_4)) return(6);
|
---|
48 | else if (typeid(T) == typeid(uint_8)) return(7);
|
---|
49 | else if (typeid(T) == typeid(int_8)) return(8);
|
---|
50 | else if (typeid(T) == typeid(r_4)) return(9);
|
---|
51 | else if (typeid(T) == typeid(r_8)) return(10);
|
---|
52 | else if (typeid(T) == typeid(complex<r_4>)) return(11);
|
---|
53 | else if (typeid(T) == typeid(complex<r_8>)) return(12);
|
---|
54 | #ifdef SO_LDBLE128
|
---|
55 | else if (typeid(T) == typeid(r_16)) return(13);
|
---|
56 | else if (typeid(T) == typeid(complex<r_16>)) return(14);
|
---|
57 | #endif
|
---|
58 | else return(0);
|
---|
59 | }
|
---|
60 | #else
|
---|
61 | //! Return the type name of T, as a string, (Example: T=uint_8 --> "uint_8")
|
---|
62 | template <class T>
|
---|
63 | string DataTypeInfo<T>::getTypeName() { return("???unknowntype???"); }
|
---|
64 | DECL_TEMP_SPEC
|
---|
65 | string DataTypeInfo<uint_1>::getTypeName() { return("uint_1"); }
|
---|
66 | DECL_TEMP_SPEC
|
---|
67 | string DataTypeInfo<int_1>::getTypeName() { return("int_1"); }
|
---|
68 | DECL_TEMP_SPEC
|
---|
69 | string DataTypeInfo<uint_2>::getTypeName() { return("uint_2"); }
|
---|
70 | DECL_TEMP_SPEC
|
---|
71 | string DataTypeInfo<int_2>::getTypeName() { return("int_2"); }
|
---|
72 | DECL_TEMP_SPEC
|
---|
73 | string DataTypeInfo<uint_4>::getTypeName() { return("uint_4"); }
|
---|
74 | DECL_TEMP_SPEC
|
---|
75 | string DataTypeInfo<int_4>::getTypeName() { return("int_4"); }
|
---|
76 | DECL_TEMP_SPEC
|
---|
77 | string DataTypeInfo<uint_8>::getTypeName() { return("uint_8"); }
|
---|
78 | DECL_TEMP_SPEC
|
---|
79 | string DataTypeInfo<int_8>::getTypeName() { return("int_8"); }
|
---|
80 | DECL_TEMP_SPEC
|
---|
81 | string DataTypeInfo<r_4>::getTypeName() { return("r_4"); }
|
---|
82 | DECL_TEMP_SPEC
|
---|
83 | string DataTypeInfo<r_8>::getTypeName() { return("r_8"); }
|
---|
84 | DECL_TEMP_SPEC
|
---|
85 | string DataTypeInfo< complex<r_4> >::getTypeName() { return(" complex<r_4> "); }
|
---|
86 | DECL_TEMP_SPEC
|
---|
87 | string DataTypeInfo< complex<r_8> >::getTypeName() { return(" complex<r_8> "); }
|
---|
88 | #ifdef SO_LDBLE128
|
---|
89 | DECL_TEMP_SPEC
|
---|
90 | string DataTypeInfo<r_16>::getTypeName() { return("r_16"); }
|
---|
91 | DECL_TEMP_SPEC
|
---|
92 | string DataTypeInfo< complex<r_16> >::getTypeName() { return(" complex<r_16> "); }
|
---|
93 | #endif
|
---|
94 | /*!
|
---|
95 | \ brief Return an identifier associated to T
|
---|
96 | uint_1 -> 1 , int_1 -> 2
|
---|
97 | uint_2 -> 3 , int_2 -> 4
|
---|
98 | uint_4 -> 5 , int_4 -> 6
|
---|
99 | uint_8 -> 7 , int_8 -> 8
|
---|
100 | r_4 -> 9 , r_8 -> 10
|
---|
101 | complex<r_4> -> 11 , complex<r_8> -> 12
|
---|
102 | */
|
---|
103 | template <class T>
|
---|
104 | int DataTypeInfo<T>::getTypeId() { return(0); }
|
---|
105 | DECL_TEMP_SPEC
|
---|
106 | int DataTypeInfo<uint_1>::getTypeId() { return(1); }
|
---|
107 | DECL_TEMP_SPEC
|
---|
108 | int DataTypeInfo<int_1>::getTypeId() { return(2); }
|
---|
109 | DECL_TEMP_SPEC
|
---|
110 | int DataTypeInfo<uint_2>::getTypeId() { return(3); }
|
---|
111 | DECL_TEMP_SPEC
|
---|
112 | int DataTypeInfo<int_2>::getTypeId() { return(4); }
|
---|
113 | DECL_TEMP_SPEC
|
---|
114 | int DataTypeInfo<uint_4>::getTypeId() { return(5); }
|
---|
115 | DECL_TEMP_SPEC
|
---|
116 | int DataTypeInfo<int_4>::getTypeId() { return(6); }
|
---|
117 | DECL_TEMP_SPEC
|
---|
118 | int DataTypeInfo<uint_8>::getTypeId() { return(7); }
|
---|
119 | DECL_TEMP_SPEC
|
---|
120 | int DataTypeInfo<int_8>::getTypeId() { return(8); }
|
---|
121 | DECL_TEMP_SPEC
|
---|
122 | int DataTypeInfo<r_4>::getTypeId() { return(9); }
|
---|
123 | DECL_TEMP_SPEC
|
---|
124 | int DataTypeInfo<r_8>::getTypeId() { return(10); }
|
---|
125 | DECL_TEMP_SPEC
|
---|
126 | int DataTypeInfo< complex<r_4> >::getTypeId() { return(11); }
|
---|
127 | DECL_TEMP_SPEC
|
---|
128 | int DataTypeInfo< complex<r_8> >::getTypeId() { return(12); }
|
---|
129 | #ifdef SO_LDBLE128
|
---|
130 | DECL_TEMP_SPEC
|
---|
131 | int DataTypeInfo<r_16>::getTypeId() { return(13); }
|
---|
132 | DECL_TEMP_SPEC
|
---|
133 | int DataTypeInfo< complex<r_16> >::getTypeId() { return(14); }
|
---|
134 | #endif
|
---|
135 |
|
---|
136 | #endif
|
---|
137 |
|
---|
138 |
|
---|
139 | string DecodeGCCTypeName(string gcctype)
|
---|
140 | // seulement pour gcc/g++ qui ne code pas correctement
|
---|
141 | {
|
---|
142 | #if defined(__GNUG__)
|
---|
143 | string type("");
|
---|
144 | const char* str = gcctype.c_str();
|
---|
145 | int lstr = (int) strlen(str);
|
---|
146 | if(lstr<=0) return string("Linux Decoding error: lstr<=0");
|
---|
147 |
|
---|
148 | // Le dernier caractere donne le type
|
---|
149 | lstr--;
|
---|
150 | if (str[lstr]=='v') type = "void";
|
---|
151 | else if(str[lstr]=='b') type = "bool";
|
---|
152 | else if(str[lstr]=='c') type = "char";
|
---|
153 | else if(str[lstr]=='s') type = "short";
|
---|
154 | else if(str[lstr]=='i') type = "int";
|
---|
155 | else if(str[lstr]=='l') type = "long";
|
---|
156 | else if(str[lstr]=='x') type = "long long";
|
---|
157 | else if(str[lstr]=='f') type = "float";
|
---|
158 | else if(str[lstr]=='d') type = "double";
|
---|
159 | else if(str[lstr]=='r') type = "long double";
|
---|
160 | else return string("Linux Decoding error: bad last char");
|
---|
161 | if(lstr==0) return type;
|
---|
162 |
|
---|
163 | // Les caracteres precedents donnent: signed, unsigned, *, & ou const.
|
---|
164 | // Mais si on a un Z, alors c'est un complexe (code ...t7complex1Z...)
|
---|
165 | for(int i=0; i<(int)strlen(str); i++) {
|
---|
166 | lstr--;
|
---|
167 | if (str[lstr]=='U') type = "unsigned " + type;
|
---|
168 | else if(str[lstr]=='S') type = "signed " + type;
|
---|
169 | else if(str[lstr]=='P') type = type + "*";
|
---|
170 | else if(str[lstr]=='R') type = type + "&";
|
---|
171 | else if(str[lstr]=='C') type = "const " + type;
|
---|
172 | else if(str[lstr]=='Z') { // Complexe
|
---|
173 | type = "complex<" + type + ">";
|
---|
174 | for(int j=0;j<(int)strlen(str);j++) {
|
---|
175 | if (str[j]=='P') type = type + "*";
|
---|
176 | else if(str[j]=='R') type = type + "&";
|
---|
177 | else if(str[j]=='C') type = "const " + type;
|
---|
178 | else if(str[j]=='t') break;
|
---|
179 | else return string("Linux Decoding error: bad char 1,2 for Z");
|
---|
180 | }
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | else return string("Linux Decoding error: bad last-1,last-2 char");
|
---|
184 | if(lstr==0) break;
|
---|
185 | }
|
---|
186 |
|
---|
187 | return type;
|
---|
188 | #else
|
---|
189 | return gcctype;
|
---|
190 | #endif
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
195 | #pragma define_template DataTypeInfo<uint_1>
|
---|
196 | #pragma define_template DataTypeInfo<int_1>
|
---|
197 | #pragma define_template DataTypeInfo<uint_2>
|
---|
198 | #pragma define_template DataTypeInfo<int_2>
|
---|
199 | #pragma define_template DataTypeInfo<int_4>
|
---|
200 | #pragma define_template DataTypeInfo<int_8>
|
---|
201 | #pragma define_template DataTypeInfo<uint_4>
|
---|
202 | #pragma define_template DataTypeInfo<uint_8>
|
---|
203 | #pragma define_template DataTypeInfo<r_4>
|
---|
204 | #pragma define_template DataTypeInfo<r_8>
|
---|
205 | #pragma define_template DataTypeInfo< complex<r_4> >
|
---|
206 | #pragma define_template DataTypeInfo< complex<r_8> >
|
---|
207 | #ifdef SO_LDBLE128
|
---|
208 | #pragma define_template DataTypeInfo<r_16>
|
---|
209 | #pragma define_template DataTypeInfo< complex<r_16> >
|
---|
210 | #endif
|
---|
211 |
|
---|
212 | #endif
|
---|
213 |
|
---|
214 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
215 | template class DataTypeInfo<uint_1>;
|
---|
216 | template class DataTypeInfo<int_1>;
|
---|
217 | template class DataTypeInfo<uint_2>;
|
---|
218 | template class DataTypeInfo<int_2>;
|
---|
219 | template class DataTypeInfo<int_4>;
|
---|
220 | template class DataTypeInfo<int_8>;
|
---|
221 | template class DataTypeInfo<uint_4>;
|
---|
222 | template class DataTypeInfo<uint_8>;
|
---|
223 | template class DataTypeInfo<r_4>;
|
---|
224 | template class DataTypeInfo<r_8>;
|
---|
225 | template class DataTypeInfo< complex<r_4> >;
|
---|
226 | template class DataTypeInfo< complex<r_8> >;
|
---|
227 | #ifdef SO_LDBLE128
|
---|
228 | template class DataTypeInfo<r_16>;
|
---|
229 | template class DataTypeInfo< complex<r_16> >;
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | #endif
|
---|
233 |
|
---|
234 | } // FIN namespace SOPHYA
|
---|