source: Sophya/trunk/SophyaLib/BaseTools/datatype.cc

Last change on this file was 3750, checked in by ansari, 16 years ago

Prise en charge de float 128 bits (r_16, complex<r_16>) par les NDataBlock<T> et PPersist, controlee par le flag de compilation SO_LDBLE128 defini ds machdefs.h , Reza 03/03/2010

File size: 7.8 KB
Line 
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
12namespace SOPHYA {
13
14template <class T>
15DataTypeInfo<T>::DataTypeInfo()
16{
17}
18#if defined(__SGICC__)
19template <class T>
20string 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}
39template <class T>
40int 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")
62template <class T>
63string DataTypeInfo<T>::getTypeName() { return("???unknowntype???"); }
64DECL_TEMP_SPEC
65string DataTypeInfo<uint_1>::getTypeName() { return("uint_1"); }
66DECL_TEMP_SPEC
67string DataTypeInfo<int_1>::getTypeName() { return("int_1"); }
68DECL_TEMP_SPEC
69string DataTypeInfo<uint_2>::getTypeName() { return("uint_2"); }
70DECL_TEMP_SPEC
71string DataTypeInfo<int_2>::getTypeName() { return("int_2"); }
72DECL_TEMP_SPEC
73string DataTypeInfo<uint_4>::getTypeName() { return("uint_4"); }
74DECL_TEMP_SPEC
75string DataTypeInfo<int_4>::getTypeName() { return("int_4"); }
76DECL_TEMP_SPEC
77string DataTypeInfo<uint_8>::getTypeName() { return("uint_8"); }
78DECL_TEMP_SPEC
79string DataTypeInfo<int_8>::getTypeName() { return("int_8"); }
80DECL_TEMP_SPEC
81string DataTypeInfo<r_4>::getTypeName() { return("r_4"); }
82DECL_TEMP_SPEC
83string DataTypeInfo<r_8>::getTypeName() { return("r_8"); }
84DECL_TEMP_SPEC
85string DataTypeInfo< complex<r_4> >::getTypeName() { return(" complex<r_4> "); }
86DECL_TEMP_SPEC
87string DataTypeInfo< complex<r_8> >::getTypeName() { return(" complex<r_8> "); }
88#ifdef SO_LDBLE128
89DECL_TEMP_SPEC
90string DataTypeInfo<r_16>::getTypeName() { return("r_16"); }
91DECL_TEMP_SPEC
92string 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*/
103template <class T>
104int DataTypeInfo<T>::getTypeId() { return(0); }
105DECL_TEMP_SPEC
106int DataTypeInfo<uint_1>::getTypeId() { return(1); }
107DECL_TEMP_SPEC
108int DataTypeInfo<int_1>::getTypeId() { return(2); }
109DECL_TEMP_SPEC
110int DataTypeInfo<uint_2>::getTypeId() { return(3); }
111DECL_TEMP_SPEC
112int DataTypeInfo<int_2>::getTypeId() { return(4); }
113DECL_TEMP_SPEC
114int DataTypeInfo<uint_4>::getTypeId() { return(5); }
115DECL_TEMP_SPEC
116int DataTypeInfo<int_4>::getTypeId() { return(6); }
117DECL_TEMP_SPEC
118int DataTypeInfo<uint_8>::getTypeId() { return(7); }
119DECL_TEMP_SPEC
120int DataTypeInfo<int_8>::getTypeId() { return(8); }
121DECL_TEMP_SPEC
122int DataTypeInfo<r_4>::getTypeId() { return(9); }
123DECL_TEMP_SPEC
124int DataTypeInfo<r_8>::getTypeId() { return(10); }
125DECL_TEMP_SPEC
126int DataTypeInfo< complex<r_4> >::getTypeId() { return(11); }
127DECL_TEMP_SPEC
128int DataTypeInfo< complex<r_8> >::getTypeId() { return(12); }
129#ifdef SO_LDBLE128
130DECL_TEMP_SPEC
131int DataTypeInfo<r_16>::getTypeId() { return(13); }
132DECL_TEMP_SPEC
133int DataTypeInfo< complex<r_16> >::getTypeId() { return(14); }
134#endif
135
136#endif
137
138
139string 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
187return type;
188#else
189return 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)
215template class DataTypeInfo<uint_1>;
216template class DataTypeInfo<int_1>;
217template class DataTypeInfo<uint_2>;
218template class DataTypeInfo<int_2>;
219template class DataTypeInfo<int_4>;
220template class DataTypeInfo<int_8>;
221template class DataTypeInfo<uint_4>;
222template class DataTypeInfo<uint_8>;
223template class DataTypeInfo<r_4>;
224template class DataTypeInfo<r_8>;
225template class DataTypeInfo< complex<r_4> >;
226template class DataTypeInfo< complex<r_8> >;
227#ifdef SO_LDBLE128
228template class DataTypeInfo<r_16>;
229template class DataTypeInfo< complex<r_16> >;
230#endif
231
232#endif
233
234} // FIN namespace SOPHYA
Note: See TracBrowser for help on using the repository browser.