ML Reference
MeVis/Foundation/Sources/MLUtilities/mlUtilsSystem.h
Go to the documentation of this file.
00001 // **InsertLicense** code
00002 //----------------------------------------------------------------------------------
00004 
00009 //----------------------------------------------------------------------------------
00010 #ifndef __mlUtilsSystem_H
00011 #define __mlUtilsSystem_H
00012 
00013 // Include the C-Parts of system definitions.
00014 #ifndef __mlUtilsSystemC_H
00015 #include "mlUtilsSystemC.h"
00016 #endif
00017 
00018 
00019 //------------------------------------------------------------------------------------
00026 //------------------------------------------------------------------------------------
00027 #ifndef MEVIS_TARGET
00028 
00029 #if !defined(MEVIS_TARGET)
00030 # error "The compiler definition MEVIS_TARGET is not set! It must specify the name of the compiled executable (without _d etc.)"
00031 #endif
00032 #endif
00033 
00034 
00035 //------------------------------------------------------------------------------------
00037 
00038 //------------------------------------------------------------------------------------
00040 #ifndef ML_UTILS_NAMESPACE
00041 #define ML_UTILS_NAMESPACE       ml
00042 #endif
00043 
00047 #ifndef ML_UTILS_START_NAMESPACE
00048 #define ML_UTILS_START_NAMESPACE namespace ML_UTILS_NAMESPACE {
00049 #endif
00050 
00052 #ifndef ML_UTILS_END_NAMESPACE
00053 #define ML_UTILS_END_NAMESPACE   }
00054 #endif
00055 
00056 
00057 
00058 //---------------------------------------------------------------------------
00060 //---------------------------------------------------------------------------
00061 
00062 #ifndef __mlTrace_H
00063 #include "mlTrace.h"
00064 #endif
00065 
00066 #ifndef __mlErrorMacros_H
00067 #include "mlErrorMacros.h"
00068 #endif
00069 
00070 #ifndef __mlMacros_H
00071 #include "mlMacros.h"
00072 #endif
00073 
00075 
00076 
00077 // Include system dependent headers.
00078 #ifdef WIN32
00079 #include "mlSystemWarningsDisable.h"
00080 #include <windows.h>
00081 #include "mlSystemWarningsRestore.h"
00082 #endif
00083 
00084 ML_UTILS_START_NAMESPACE
00085 
00086 //------------------------------------------------------------------------------------
00087 //
00089 
00090 //
00091 //------------------------------------------------------------------------------------
00092 
00095 template<typename T> T mlMin(T a, T b){ return a < b ? a : b; }
00096 
00099 template<typename T> T mlMax(T a, T b){ return a > b ? a : b; }
00100 
00102 template<typename T> T mlAbs(T a){ return (((a) < 0) ? ((a) * (-1)) : (a)); }
00104 
00106 
00107 inline MLuint8  mlAbs(MLuint8  a){ return a; }
00108 inline MLuint16 mlAbs(MLuint16 a){ return a; }
00109 inline MLuint32 mlAbs(MLuint32 a){ return a; }
00110 inline MLuint64 mlAbs(MLuint64 a){ return a; }
00112 
00113 ML_UTILS_END_NAMESPACE
00114 
00115 // The following block is currently for VC7 only, but might be necessary for VC8 too!
00116 #ifdef WIN32
00117   #if _MSC_VER >= 1300
00118 //------------------------------------------------------------------------------------
00119 //
00121 //            e.g., fabs(static_cast<int>(10)) could have been fabs(float),
00122 //            fabs(double), or fabs(long double).
00124 //
00125 //------------------------------------------------------------------------------------
00126 
00127 // We include \c cmath, so that always the standard functions are defined when these
00128 // overloads are defined.
00129 #include <mlSystemWarningsDisable.h>
00130 #include <cmath>
00131 #include <mlSystemWarningsRestore.h>
00132 
00133 
00134 //inline double      pow(float f, double      value) { return pow(static_cast<double>     (f), value); }
00135 //inline double      pow(int i,   double      value) { return pow(static_cast<double>     (i), value); }
00136 //inline double      pow(int i,   float       value) { return pow(static_cast<double>     (i), value); }
00137 //inline long double pow(int i,   long double value) { return pow(static_cast<long double>(i), value); }
00138 
00139 
00140 
00141 inline long double pow(         __int64 i, int         value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00142 inline long double pow(unsigned __int64 i, int         value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00143 inline long double pow(         __int64 i, float       value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00144 inline long double pow(unsigned __int64 i, float       value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00145 inline long double pow(         __int64 i, double      value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00146 inline long double pow(unsigned __int64 i, double      value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00147 inline long double pow(         __int64 i, long double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00148 inline long double pow(unsigned __int64 i, long double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
00149 
00150 
00151 // There is a bug with resolving _abs64 by the linker. Look at this thread:
00152 // http://groups.google.de/group/microsoft.public.vc.language/browse_thread/thread/f9607404c1e6d910/9555d0cd44ab2219
00153 // //
00154 // As workaround we implement these functions without _abs64().
00155 #if _MSC_VER < 1600
00156 // function is already defined under VC10:
00157 inline          __int64 abs (         __int64 i) { return (i < 0 ? -i : i); }
00158 #endif // _MSC_VER < 1600
00159 inline unsigned __int64 abs (unsigned __int64 i) { return i; }
00160 inline long double      fabs(         __int64 i) { return static_cast<long double>(i < 0 ? -i : i); }
00161 inline long double      fabs(unsigned __int64 i) { return static_cast<long double>(i); }
00162 
00163 #if _MSC_VER >= 1600
00164 inline double      pow (float        f,           double d ) { return pow(static_cast<double>(f),      d);                           }
00165 #endif // _MSC_VER >= 1600
00166 inline double      pow (double       d,            float f ) { return pow(d,                           static_cast<double>(f));      }
00167 inline double      pow (double       d,     unsigned int i ) { return pow(d,                           static_cast<double>(i));      }
00168 inline long double pow (double       d,          __int64 i ) { return pow(static_cast<long double>(d), static_cast<long double>(i)); }
00169 inline long double pow (double       d, unsigned __int64 i ) { return pow(static_cast<long double>(d), static_cast<long double>(i)); }
00170 inline long double pow (double       d,      long double ld) { return pow(static_cast<long double>(d), ld);                          }
00171 inline long double pow (long double ld,           double d ) { return pow(ld,                          static_cast<long double>(d)); }
00172 
00173 template <typename T> inline double      atan (T value)                 { return atan (static_cast<double>(value)); }
00174 template <typename T> inline double      ceil (T value)                 { return ceil (static_cast<double>(value)); }
00175 template <typename T> inline double      exp  (T value)                 { return exp  (static_cast<double>(value)); }
00176 template <typename T> inline double      fabs (T value)                 { return fabs (static_cast<double>(value)); }
00177 template <typename T> inline double      floor(T value)                 { return floor(static_cast<double>(value)); }
00178 template <typename T> inline double      log  (T value)                 { return log  (static_cast<double>(value)); }
00179 template <typename T> inline double      sqrt (T value)                 { return sqrt (static_cast<double>(value)); }
00180 template <typename T> inline double      pow  (int              i, T value) { return pow  (static_cast<double>(i),      value); }
00181 template <typename T> inline double      pow  (unsigned int     i, T value) { return pow  (static_cast<double>(i),      value); }
00182 template <typename T> inline long double pow  (         __int64 i, T value) { return pow  (static_cast<long double>(i), static_cast<long double>(value)); }
00183 template <typename T> inline long double pow  (unsigned __int64 i, T value) { return pow  (static_cast<long double>(i), static_cast<long double>(value)); }
00184 #if _MSC_VER < 1600
00185 template <typename T> inline double      pow  (float            f, T value) { return pow  (static_cast<double>(f),      value); }
00186 #endif // _MSC_VER < 1600
00187 
00188 
00189   #endif
00190 #endif // WIN32 && _MSCVER >= 1300 && _MSC_VER < 1400
00191 
00192 //------------------------------------------------------------------------------------
00193 //
00195 
00196 //
00197 //------------------------------------------------------------------------------------
00198 
00199 #ifndef ML_TYPENAME
00200 
00206 #define ML_TYPENAME typename
00207 
00208 // Undefined ML_TYPENAME for platforms which do not support it,
00209 // e.g., WIN32 compilers older than .NET.
00210 #ifdef WIN32
00211 #if _MSC_VER <= 1200
00212 #  undef  ML_TYPENAME
00213 #  define ML_TYPENAME
00214 #endif
00215 #endif
00216 
00217 #endif
00218 
00219 
00220 
00221 //---------------------------------------------------------------------------
00225 //---------------------------------------------------------------------------
00226 #ifdef _MSC_VER
00227 
00228 #pragma warning(disable : 4201 )
00229 
00230 
00231 #pragma warning(disable : 4251)
00232 
00233 #pragma warning(disable : 4710)
00234 
00235 #pragma warning(disable : 4786 )
00236 
00237 #pragma warning(disable : 4514 )
00238 
00240 #pragma warning( push, 3 )
00241 
00243 #pragma warning(disable : 4018 )
00244 #endif
00245 
00247 #include <mlSystemWarningsDisable.h>
00248 #include <iostream>
00249 #include <list>
00250 #include <sstream>
00251 #include <string>
00252 #include <vector>
00253 #include <mlSystemWarningsRestore.h>
00254 
00255 #if defined (__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3)
00256   // Including string.h here is required since gcc version 4.3. Older gcc
00257   // versions provide it in a header file that is included above.
00258   #include <string.h>
00259 #endif
00260 
00261 
00262 #ifdef _MSC_VER
00263 
00264 #pragma warning( pop )
00265 #endif
00266 
00267 #endif // __mlUtilsSystem_H
00268 
00269