00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __NO_COMPLEX__
00019 #include <complex.h>
00020 #endif
00021
00022
00023
00024
00025 #include "camtype.h"
00026 #include "iostream.h"
00027
00028
00029 #ifndef __CAMTYPEHANDLER__
00030 #define __CAMTYPEHANDLER__
00031
00032 #undef __IMPEXP__
00033 #ifdef __BCPLUSPLUS__
00034 #ifdef __EXPORT_MVASUPPORT_B__
00035 #define __IMPEXP__ __export
00036 #else
00037 #define __IMPEXP__ __import
00038 #endif
00039 #else
00040 #define __IMPEXP__
00041 #endif
00042
00043 #ifdef __STATIC__
00044 #undef __IMPEXP__
00045 #define __IMPEXP__
00046 #endif
00047
00048
00049 class __IMPEXP__ CAMTypeHandler
00050 {
00051
00052 protected :
00053
00054 int dType;
00055 void* dP;
00056
00057 public :
00058
00059
00060
00061
00062 CAMTypeHandler() {dType = 0; dP = 0;};
00063 CAMTypeHandler(const CAMTypeHandler& T)
00064 {
00065 dType = T.dType;
00066 switch (dType)
00067 {
00068 case CAMType::typeNull: dP = 0; break;
00069 case CAMType::typeInt :
00070 dP = new int[1]; *((int*)dP) = *((int*)T.dP); break;
00071 case CAMType::typeLong :
00072 dP = new long[1]; *((long*)dP) = *((long*)T.dP); break;
00073 case CAMType::typeFloat :
00074 dP = new float[1]; *((float*)dP) = *((float*)T.dP); break;
00075 case CAMType::typeDouble :
00076 dP = new double[1]; *((double*)dP) = *((double*)T.dP); break;
00077 #ifndef __NO_COMPLEX__
00078 case CAMType::typeComplex :
00079 dP = new complex[1]; *((complex*)dP) = *((complex*)T.dP); break;
00080 #endif
00081 }
00082 };
00083 CAMTypeHandler(int i)
00084 {dType = CAMType::typeInt; dP= new int[1]; *((int*)dP) = i;};
00085 CAMTypeHandler(long l)
00086 {dType = CAMType::typeLong; dP= new long[1]; *((long*)dP) = l;};
00087 CAMTypeHandler(float f)
00088 {dType = CAMType::typeFloat; dP= new float[1]; *((float*)dP) = f;};
00089 CAMTypeHandler(double d)
00090 {dType = CAMType::typeDouble; dP= new double[1]; *((double*)dP) = d;};
00091 #ifndef __NO_COMPLEX__
00092 CAMTypeHandler(complex c)
00093 {dType = CAMType::typeComplex; dP= new complex[1]; *((complex*)dP) = c;};
00094 #endif
00095 virtual ~CAMTypeHandler()
00096 {
00097 dPDelete();
00098 };
00099
00103 void dPDelete()
00104 {
00105 if(dP != 0)
00106 {
00107 if(dType == CAMType::typeInt)
00108 delete reinterpret_cast<int*>(dP);
00109 else if(dType == CAMType::typeLong)
00110 delete reinterpret_cast<long*>(dP);
00111 else if(dType == CAMType::typeFloat)
00112 delete reinterpret_cast<float*>(dP);
00113 else if(dType == CAMType::typeDouble)
00114 delete reinterpret_cast<double*>(dP);
00115 #ifndef __NO_COMPLEX__
00116 else if(dType == CAMType::typeComplex)
00117 delete reinterpret_cast<complex*>(dP);
00118 #endif
00119 }
00120 };
00121
00122
00123
00124
00125 void operator = (CAMTypeHandler & T)
00126 {
00127 dPDelete();
00128 switch (T.dType)
00129 {
00130 case CAMType::typeNull: dP = 0; break;
00131 case CAMType::typeInt :
00132 dP = new int[1]; *((int*)dP) = *((int*)T.dP); break;
00133 case CAMType::typeLong :
00134 dP = new long[1]; *((long*)dP) = *((long*)T.dP); break;
00135 case CAMType::typeFloat :
00136 dP = new float[1]; *((float*)dP) = *((float*)T.dP); break;
00137 case CAMType::typeDouble :
00138 dP = new double[1]; *((double*)dP) = *((double*)T.dP); break;
00139 #ifndef __NO_COMPLEX__
00140 case CAMType::typeComplex :
00141 dP = new complex[1]; *((complex*)dP) = *((complex*)T.dP); break;
00142 #endif
00143 }
00144 };
00145 void operator = (int i)
00146 {dPDelete(); dType = CAMType::typeInt; dP= new int[1]; *((int*)dP) = i;};
00147 void operator = (long l)
00148 {dPDelete(); dType = CAMType::typeLong; dP= new long[1]; *((long*)dP) = l;};
00149 void operator = (float f)
00150 {dPDelete(); dType = CAMType::typeFloat; dP= new float[1]; *((float*)dP) = f;};
00151 void operator = (double d)
00152 {dPDelete(); dType = CAMType::typeDouble; dP= new double[1]; *((double*)dP) = d;};
00153 #ifndef __NO_COMPLEX__
00154 void operator = (complex c)
00155 {dPDelete(); dType = CAMType::typeComplex; dP= new complex[1]; *((complex*)dP) = c;};
00156 #endif
00157
00158
00159
00160 friend ostream& operator <<(ostream& out_stream, const CAMTypeHandler& A)
00161 { switch (A.dType)
00162 {
00163 case CAMType::typeNull: break;
00164 case CAMType::typeInt :
00165 out_stream << *((int*)A.dP); break;
00166 case CAMType::typeLong :
00167 out_stream << *((long*)A.dP); break;
00168 case CAMType::typeFloat :
00169 out_stream << *((float*)A.dP); break;
00170 case CAMType::typeDouble :
00171 out_stream << *((double*)A.dP); break;
00172 #ifndef __NO_COMPLEX__
00173 case CAMType::typeComplex :
00174 out_stream << *((complex*)A.dP); break;
00175 #endif
00176 }
00177 return out_stream;
00178 };
00179
00180
00181
00182 operator int()
00183 {
00184 int r;
00185 switch (dType)
00186 {
00187 case CAMType::typeInt : r = *((int*)dP); break;
00188 case CAMType::typeLong : r = int(*((long*)dP)); break;
00189 case CAMType::typeFloat : r = int(*((float*)dP)); break;
00190 case CAMType::typeDouble : r = int(*((double*)dP)); break;
00191 #ifndef __NO_COMPLEX__
00192 case CAMType::typeComplex : r = int(real(*((complex*)dP))); break;
00193 #endif
00194 }
00195 return r;
00196 };
00197 operator long()
00198 {
00199 long r;
00200 switch (dType)
00201 {
00202 case CAMType::typeInt : r = long(*((int*)dP)); break;
00203 case CAMType::typeLong : r = (*((long*)dP)); break;
00204 case CAMType::typeFloat : r = long(*((float*)dP)); break;
00205 case CAMType::typeDouble : r = long(*((double*)dP)); break;
00206 #ifndef __NO_COMPLEX__
00207 case CAMType::typeComplex : r = long(real(*((complex*)dP))); break;
00208 #endif
00209 }
00210 return r;
00211 };
00212 operator float()
00213 {
00214 float r;
00215 switch (dType)
00216 {
00217 case CAMType::typeInt : r = float(*((int*)dP)); break;
00218 case CAMType::typeLong : r = float(*((long*)dP)); break;
00219 case CAMType::typeFloat : r = (*((float*)dP)); break;
00220 case CAMType::typeDouble : r = float(*((double*)dP)); break;
00221 #ifndef __NO_COMPLEX__
00222 case CAMType::typeComplex : r = float(real(*((complex*)dP))); break;
00223 #endif
00224 }
00225 return r;
00226 };
00227 operator double()
00228 {
00229 double r;
00230 switch (dType)
00231 {
00232 case CAMType::typeInt : r = double(*((int*)dP)); break;
00233 case CAMType::typeLong : r = double(*((long*)dP)); break;
00234 case CAMType::typeFloat : r = double(*((float*)dP)); break;
00235 case CAMType::typeDouble : r = (*((double*)dP)); break;
00236 #ifndef __NO_COMPLEX__
00237 case CAMType::typeComplex : r = double(real(*((complex*)dP))); break;
00238 #endif
00239 }
00240 return r;
00241 };
00242 #ifndef __NO_COMPLEX__
00243 operator complex()
00244 {
00245 complex r;
00246 switch (dType)
00247 {
00248 case CAMType::typeInt : r = complex(*((int*)dP)); break;
00249 case CAMType::typeLong : r = complex(*((long*)dP)); break;
00250 case CAMType::typeFloat : r = complex(*((float*)dP)); break;
00251 case CAMType::typeDouble : r = complex(*((double*)dP)); break;
00252 case CAMType::typeComplex : r = (*((complex*)dP)); break;
00253 }
00254 return r;
00255 };
00256 #endif
00257
00258 };
00259
00260 #endif
00261
00262
00263
00264
00265
00266
00267
00268