Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
W32Compat.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef _W32Compat_hh_
26 #define _W32Compat_hh_
27 
28 #ifndef WIN32
29 #include <unistd.h>
30 #endif
31 
32 #include <bias_config.h>
33 
34 /// @author Felix Woelk
35 /// @author Jan Woetzel
36 
37 
38 // Windows:
39 #ifdef WIN32
40 
41 // avoid deprecated warnings in VS 2005
42 #ifndef _CRT_SECURE_NO_DEPRECATE
43 # define _CRT_SECURE_NO_DEPRECATE
44 #endif
45 #if !defined(_SCL_SECURE_NO_DEPRECATE) && !defined(_SECURE_SCL_DEPRECATE)
46 # define _SCL_SECURE_NO_DEPRECATE
47 #endif
48 //# define _CRT_NONSTDC_NO_DEPRECATE
49 //# define _AFX_SECURE_NO_DEPRECATE
50 //# define _ATL_SECURE_NO_DEPRECATE
51 
52 
53 // avoid definition of min and max macro in windows.h/windef.h JW 12/2004)
54 # define NOMINMAX
55 
56 // switch for math.h to define M_PI, M_PI_2 in WIN32
57 # define _USE_MATH_DEFINES
58 # include <math.h>
59 
60 ///
61 /// implement Unix quasi-standard functions for code compatibility
62 ///
63 
64 // implement non-standard (double)rint(double x). --its standard but MS ignores!
65 # define rint(x) (floor(x+0.5))
66 # define rintf(x) (floor(x+0.5))
67 # define cbrt(x) (pow(x,1.0/3.0))
68 # define trunc(x) (x<0?floor(x+1):floor(x))
69 # define exp2(x) (exp(x * log(2.0)))
70 # define log2(x) (log(x)/log(2.0))
71 
72 /* Return nonzero value if X is a NaN. We could use `fpclassify' but
73  we already have this functions `__isnan' and it is faster. */
74 # define isnan(x) (x==x ? false : true)
75 
76 /* Return nonzero value is X is positive or negative infinity. */
77 # define isinf(x) (sizeof(x)==sizeof(float) ? (x>FLT_MAX||x<-FLT_MAX)?true:false : \
78  (sizeof(x)==sizeof(double)) ? (x>DBL_MAX||x<-DBL_MAX)?true:false : \
79  x>LDBL_MAX || x<-LDBL_MAX?true:false)
80 
81 // User need to include windows.h !! It is not included here to avoid clashes
82 // this leads to clashes with other libraries for instance with Qt in qthread
83 // redefined as biasusleep and biassleep
84 // maps linux functions to WIN32 Sleep(milliseconds)
85 # define biasusleep(usec_) Sleep((unsigned long)(usec_/1000))
86 # define biasmsleep(msec_) Sleep((unsigned long)(msec_))
87 # define biassleep(sec_) Sleep((unsigned long)(sec_*1000))
88 
89 
90  /* timeval.h 1.0 01/12/19
91  * Defines gettimeofday, timeval, etc. for Win32
92  * copied from Wu Yongwei */
93 #define EPOCHFILETIME (116444736000000000LL)
94 
95 struct timezone {
96  int tz_minuteswest; /* minutes W of Greenwich */
97  int tz_dsttime; /* type of dst correction */
98  };
99 
100 /** \brief linux style function for gettimeofday for windows */
101 BIASCommon_EXPORT int gettimeofday(struct timeval *tv, struct timezone *tz);
102 
103 /** @brief wrapper for mkdir with Unix mode arg ignored
104 * Requires on WIN32:
105 * \verbatim
106 * #include <direct.h>
107 * \endverbatim
108 * @author Jan Woetzel
109 */
110 BIASCommon_EXPORT int mkdir(const char *dirname, int mode_IsIgnored );
111 
112 /// @author woelk 04/2007
113 BIASCommon_EXPORT double copysign(double x, double y);
114 
115 #else // WIN32
116 // and define them for linux
117 # define biasusleep(usec_) usleep(usec_)
118 # define biasmsleep(msec_) usleep(1000*msec_)
119 # define biassleep(sec_) sleep(sec_)
120 
121 #endif // WIN32
122 #endif //_W32Compat_hh_