MeVisLab Toolbox Reference
mlUtilsSystem.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2007, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef ML_UTILS_SYSTEM_H
14 #define ML_UTILS_SYSTEM_H
15 
17 
18 //------------------------------------------------------------------------------------
25 //------------------------------------------------------------------------------------
26 #ifndef MEVIS_TARGET
28 #if !defined(MEVIS_TARGET)
29 # error "The compiler definition MEVIS_TARGET is not set! It must specify the name of the compiled executable (without _d etc.)"
30 #endif
31 #endif
32 
33 
34 //------------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------------
39 #ifndef ML_UTILS_NAMESPACE
40 #define ML_UTILS_NAMESPACE ml
41 #endif
42 
46 #ifndef ML_UTILS_START_NAMESPACE
47 #define ML_UTILS_START_NAMESPACE namespace ML_UTILS_NAMESPACE {
48 #endif
49 
51 #ifndef ML_UTILS_END_NAMESPACE
52 #define ML_UTILS_END_NAMESPACE }
53 #endif
55 
56 #include "mlTypeDefs.h"
57 
58 ML_UTILS_START_NAMESPACE
59 
60 //------------------------------------------------------------------------------------
61 //
64 //
65 //------------------------------------------------------------------------------------
66 
69 template<typename T> T mlMin(T a, T b){ return a < b ? a : b; }
70 
73 template<typename T> T mlMax(T a, T b){ return a > b ? a : b; }
74 
76 template<typename T> T mlAbs(T a){ return a < 0? a * static_cast<T>(-1) : a; }
78 
81 inline MLuint8 mlAbs(MLuint8 a){ return a; }
82 inline MLuint16 mlAbs(MLuint16 a){ return a; }
83 inline MLuint32 mlAbs(MLuint32 a){ return a; }
84 inline MLuint64 mlAbs(MLuint64 a){ return a; }
86 
87 ML_UTILS_END_NAMESPACE
88 
89 // The following block is currently for VC7 only, but might be necessary for VC8 too!
90 #ifdef WIN32
91  #if _MSC_VER >= 1300
92 //------------------------------------------------------------------------------------
93 //
95 // e.g., fabs(static_cast<int>(10)) could have been fabs(float),
96 // fabs(double), or fabs(long double).
98 //
99 //------------------------------------------------------------------------------------
100 
101 // We include \c cmath, so that always the standard functions are defined when these
102 // overloads are defined.
103 #include <ThirdPartyWarningsDisable.h>
104 #include <cmath>
105 #include <ThirdPartyWarningsRestore.h>
106 
107 //inline double pow(float f, double value) { return pow(static_cast<double> (f), value); }
108 //inline double pow(int i, double value) { return pow(static_cast<double> (i), value); }
109 //inline double pow(int i, float value) { return pow(static_cast<double> (i), value); }
110 //inline long double pow(int i, long double value) { return pow(static_cast<long double>(i), value); }
111 
112 
113 
114 inline long double pow( __int64 i, int value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
115 inline long double pow(unsigned __int64 i, int value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
116 inline long double pow( __int64 i, float value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
117 inline long double pow(unsigned __int64 i, float value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
118 inline long double pow( __int64 i, double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
119 inline long double pow(unsigned __int64 i, double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
120 inline long double pow( __int64 i, long double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
121 inline long double pow(unsigned __int64 i, long double value) { return pow(static_cast<long double>(i), static_cast<long double>(value)); }
122 
123 
124 // There is a bug with resolving _abs64 by the linker. Look at this thread:
125 // http://groups.google.de/group/microsoft.public.vc.language/browse_thread/thread/f9607404c1e6d910/9555d0cd44ab2219
126 // //
127 // As workaround we implement these functions without _abs64().
128 #if _MSC_VER < 1600
129 // function is already defined under VC10:
130 inline __int64 abs ( __int64 i) { return (i < 0 ? -i : i); }
131 #endif // _MSC_VER < 1600
132 inline unsigned __int64 abs (unsigned __int64 i) { return i; }
133 inline long double fabs( __int64 i) { return static_cast<long double>(i < 0 ? -i : i); }
134 inline long double fabs(unsigned __int64 i) { return static_cast<long double>(i); }
135 
136 #if _MSC_VER >= 1600
137 inline double pow (float f, double d ) { return pow(static_cast<double>(f), d); }
138 #endif // _MSC_VER >= 1600
139 inline double pow (double d, float f ) { return pow(d, static_cast<double>(f)); }
140 inline double pow (double d, unsigned int i ) { return pow(d, static_cast<double>(i)); }
141 inline long double pow (double d, __int64 i ) { return pow(static_cast<long double>(d), static_cast<long double>(i)); }
142 inline long double pow (double d, unsigned __int64 i ) { return pow(static_cast<long double>(d), static_cast<long double>(i)); }
143 inline long double pow (double d, long double ld) { return pow(static_cast<long double>(d), ld); }
144 inline long double pow (long double ld, double d ) { return pow(ld, static_cast<long double>(d)); }
145 
146 template <typename T> inline double atan (T value) { return atan (static_cast<double>(value)); }
147 template <typename T> inline double ceil (T value) { return ceil (static_cast<double>(value)); }
148 template <typename T> inline double exp (T value) { return exp (static_cast<double>(value)); }
149 template <typename T> inline double fabs (T value) { return fabs (static_cast<double>(value)); }
150 template <typename T> inline double floor(T value) { return floor(static_cast<double>(value)); }
151 template <typename T> inline double log (T value) { return log (static_cast<double>(value)); }
152 template <typename T> inline double sqrt (T value) { return sqrt (static_cast<double>(value)); }
153 template <typename T> inline double pow (int i, T value) { return pow (static_cast<double>(i), value); }
154 template <typename T> inline double pow (unsigned int i, T value) { return pow (static_cast<double>(i), value); }
155 template <typename T> inline long double pow ( __int64 i, T value) { return pow (static_cast<long double>(i), static_cast<long double>(value)); }
156 template <typename T> inline long double pow (unsigned __int64 i, T value) { return pow (static_cast<long double>(i), static_cast<long double>(value)); }
157 #if _MSC_VER < 1600
158 template <typename T> inline double pow (float f, T value) { return pow (static_cast<double>(f), value); }
159 #endif // _MSC_VER < 1600
161 
162  #endif
163 #endif // WIN32 && _MSCVER >= 1300 && _MSC_VER < 1400
164 
165 //------------------------------------------------------------------------------------
166 //
170 //
171 //------------------------------------------------------------------------------------
172 
173 #define ML_TYPENAME typename
175 
176 
177 #endif // __mlUtilsSystem_H
178 
179 
@ T
Definition: SoKeyGrabber.h:71
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
unsigned int MLuint32
Definition: mlTypeDefs.h:191
unsigned char MLuint8
Definition: mlTypeDefs.h:115
unsigned short MLuint16
Definition: mlTypeDefs.h:148
MLuint64 mlAbs(MLuint64 a)
Definition: mlUtilsSystem.h:84
T mlMax(T a, T b)
Defines ML specific max template since max template is platform dependent.
Definition: mlUtilsSystem.h:73
DT abs(DT val)
T mlMin(T a, T b)
Defines ML specific min template since min template is platform dependent.
Definition: mlUtilsSystem.h:69