00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TJTYPES_H
00019 #define TJTYPES_H
00020
00021 #include <tjutils/tjutils.h>
00022 #include <tjutils/tjcomplex.h>
00023
00024
00031
00032
00033 #if SIZEOF_CHAR == 1
00034 typedef char s8bit;
00035 typedef unsigned char u8bit;
00036 #else
00037 #error "sizeof(char)!=1"
00038 #endif
00039
00040 #if SIZEOF_SHORT == 2
00041 typedef short s16bit;
00042 typedef unsigned short u16bit;
00043 #else
00044 #error "sizeof(short)!=2"
00045 #endif
00046
00047 #if SIZEOF_INT == 4
00048 typedef int s32bit;
00049 typedef unsigned int u32bit;
00050 #else
00051 #if SIZEOF_LONG == 4
00052 typedef long s32bit;
00053 typedef unsigned long u32bit;
00054 #else
00055 #error "sizeof(int)!=4 and sizeof(long)!=4"
00056 #endif
00057 #endif
00058
00059
00066 class TypeTraits {
00067
00068 public:
00069
00070
00071 static STD_string type2string(s8bit v) {return itos(v);}
00072 static STD_string type2string(u8bit v) {return itos(v);}
00073 static STD_string type2string(s16bit v) {return itos(v);}
00074 static STD_string type2string(u16bit v) {return itos(v);}
00075 static STD_string type2string(s32bit v) {return itos(v);}
00076 static STD_string type2string(u32bit v) {return itos(v);}
00077 static STD_string type2string(float v) {return ftos(v);}
00078 static STD_string type2string(double v) {return ftos(float(v));}
00079 static STD_string type2string(const STD_complex& v) {return ctos(v);}
00080 static STD_string type2string(const STD_string& v) {return v;}
00081
00082
00083 static void string2type(const STD_string& s, s8bit& v) {v=(s8bit)atoi(s.c_str());}
00084 static void string2type(const STD_string& s, u8bit& v) {v=(u8bit)atoi(s.c_str());}
00085 static void string2type(const STD_string& s, s16bit& v) {v=(s16bit)atoi(s.c_str());}
00086 static void string2type(const STD_string& s, u16bit& v) {v=(u16bit)atoi(s.c_str());}
00087 static void string2type(const STD_string& s, s32bit& v) {v=(s32bit)atoi(s.c_str());}
00088 static void string2type(const STD_string& s, u32bit& v) {v=(u32bit)atoi(s.c_str());}
00089 static void string2type(const STD_string& s, float& v) {v=(float)atof(s.c_str());}
00090 static void string2type(const STD_string& s, double& v) {v=atof(s.c_str());}
00091 static void string2type(const STD_string& s, STD_complex& v) {v=stoc(s);}
00092 static void string2type(const STD_string& s, STD_string& v) {v=s;}
00093
00094
00095 static const char* type2label(s8bit) {return "s8bit";}
00096 static const char* type2label(u8bit) {return "u8bit";}
00097 static const char* type2label(s16bit) {return "s16bit";}
00098 static const char* type2label(u16bit) {return "u16bit";}
00099 static const char* type2label(s32bit) {return "s32bit";}
00100 static const char* type2label(u32bit) {return "u32bit";}
00101 static const char* type2label(float) {return "float";}
00102 static const char* type2label(double) {return "double";}
00103 static const char* type2label(const STD_complex&) {return "complex";}
00104 static const char* type2label(const STD_string&) {return "string";}
00105
00109 static unsigned int typesize(const STD_string& typelabel);
00110
00111
00112 };
00113
00114
00117 #endif