00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef DISC_TYPE_H
00012 #define DISC_TYPE_H
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "Utility/Pstring.h"
00022 #include "AppTypes/Vektor.h"
00023 #include "AppTypes/Tenzor.h"
00024 #include "AppTypes/SymTenzor.h"
00025 #include "AppTypes/AntiSymTenzor.h"
00026 #include "AppTypes/dcomplex.h"
00027
00028
00030
00031
00032
00033 struct DiscTypeBase {
00034
00035 enum { CHAR, SHORT, INT, LONG, FLOAT, DOUBLE, DCOMPLEX, FCOMPLEX,
00036 SCALAR, VEKTOR, TENZOR, SYMTENZOR, ANTISYMTENZOR, UNKNOWN };
00037
00038
00039 static int scalarType(const string &s) {
00040 if (s.length() == 0 || s.length() == 2 || s.length() > 3)
00041 return UNKNOWN;
00042 char c = tolower(s[s.length() - 1]);
00043 if (c == 'c')
00044 return CHAR;
00045 else if (c == 's')
00046 return SHORT;
00047 else if (c == 'i')
00048 return INT;
00049 else if (c == 'l')
00050 return LONG;
00051 else if (c == 'f')
00052 return FLOAT;
00053 else if (c == 'd')
00054 return DOUBLE;
00055 else if (c == 'y')
00056 return FCOMPLEX;
00057 else if (c == 'z')
00058 return DCOMPLEX;
00059 else
00060 return UNKNOWN;
00061 }
00062
00063
00064
00065 static int dim(const string &s) {
00066 if (s.length() == 0 || s.length() == 2 || s.length() > 3)
00067 return (-1);
00068 if (s.length() == 1)
00069 return 0;
00070 char c = s[1];
00071 if (c < '1' || c > '9')
00072 return (-1);
00073 return (c - '1' + 1);
00074 }
00075
00076
00077 static int appType(const string &s) {
00078 if (s.length() == 0 || s.length() == 2 || s.length() > 3)
00079 return UNKNOWN;
00080 if (s.length() == 1)
00081 return SCALAR;
00082 char c = tolower(s[0]);
00083 if (c == 'v')
00084 return VEKTOR;
00085 else if (c == 't')
00086 return TENZOR;
00087 else if (c == 's')
00088 return SYMTENZOR;
00089 else if (c == 'a')
00090 return ANTISYMTENZOR;
00091 else
00092 return UNKNOWN;
00093 }
00094 };
00095
00096
00098
00099
00100 template<class T>
00101 struct DiscType : public DiscTypeBase {
00102 static string str() { return string("u"); }
00103 };
00104
00105
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 #define DEFINE_DISCTYPE_SCALAR(TYPE, STRING) \
00118 template<> \
00119 struct DiscType< TYPE > : public DiscTypeBase { \
00120 static string str() { return string(STRING); } \
00121 };
00122
00123 DEFINE_DISCTYPE_SCALAR(char, "c")
00124 DEFINE_DISCTYPE_SCALAR(short, "s")
00125 DEFINE_DISCTYPE_SCALAR(int, "i")
00126 DEFINE_DISCTYPE_SCALAR(long, "l")
00127 DEFINE_DISCTYPE_SCALAR(float, "f")
00128 DEFINE_DISCTYPE_SCALAR(double, "d")
00129
00130 DEFINE_DISCTYPE_SCALAR(unsigned char, "c")
00131 DEFINE_DISCTYPE_SCALAR(unsigned short, "s")
00132 DEFINE_DISCTYPE_SCALAR(unsigned int, "i")
00133 DEFINE_DISCTYPE_SCALAR(unsigned long, "l")
00134
00135 #ifdef IPPL_HAS_TEMPLATED_COMPLEX
00136 DEFINE_DISCTYPE_SCALAR(complex<float>, "y")
00137 DEFINE_DISCTYPE_SCALAR(complex<double>, "z")
00138 #else
00139 DEFINE_DISCTYPE_SCALAR(complex, "z")
00140 #endif
00141
00142
00144
00145
00146
00147
00148
00149
00150 #define DEFINE_DISCTYPE_APPTYPE(TYPE, STRING) \
00151 template<class T, unsigned D> \
00152 struct DiscType< TYPE<T, D> > : public DiscTypeBase { \
00153 static string str() { \
00154 CTAssert(D < 10); \
00155 string retval = STRING; \
00156 retval += "0"; \
00157 retval += DiscType<T>::str(); \
00158 retval[1] += D; \
00159 return retval; \
00160 } \
00161 };
00162
00163 DEFINE_DISCTYPE_APPTYPE(Vektor, "v")
00164 DEFINE_DISCTYPE_APPTYPE(Tenzor, "t")
00165 DEFINE_DISCTYPE_APPTYPE(SymTenzor, "s")
00166 DEFINE_DISCTYPE_APPTYPE(AntiSymTenzor, "a")
00167
00168 #endif
00169
00170
00171
00172
00173
00174