Merge branch 'master' into cairocanvas
[ardour.git] / msvc_extra_headers / ardourext / misc.h.input
1 /*
2     Copyright (C) 2009 John Emmas
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_msvc_extensions_h__
21 #define __ardour_msvc_extensions_h__
22
23 #ifndef _WIN32_WINNT
24 #define _WIN32_WINNT 0x0500
25 #endif
26 #ifndef _CPP_VECTOR
27 #define _CPP_VECTOR  1
28 #endif
29
30 #ifdef __cplusplus
31 #include <vector>
32 #endif
33
34 #include <math.h>
35 #include <float.h>
36 #include <direct.h>
37 #include <boost/regex.h>
38 #include <glib.h>
39 #include <ardourext/float_cast.h>
40
41 // 'std::isnan()' is not available in MSVC. Assume '_isnan(double)'
42 #define isnan(val)  _isnan((double)val)
43
44 // 'std::isinf()' is not available in MSVC. Assume '!_finite(double)'
45 #define isinf(val) !_finite((double)val)
46
47 // 'INFINITY' is not defined in MSVC. Assume 'HUGE_VAL'
48 #ifndef INFINITY
49 #define INFINITY    HUGE_VAL
50 #endif
51
52 // File access modes copied from unistd.h
53 #define F_OK 0
54 #define R_OK 4
55 #define W_OK 2
56 #define X_OK 1
57
58 // Miscellaneous #defines
59 #define __attribute__(x)
60 #define llabs      _abs64
61 #define atoll      _atoi64
62 #define access     _access
63 #define getcwd     _getcwd
64 #define getpid     _getpid
65 #define snprintf   _snprintf
66 #define random      rand
67 #define link        ntfs_link
68 #define unlink      ntfs_unlink
69 #define strcasecmp  stricmp
70 #define strncasecmp strnicmp
71 #define strtok_r( _s, _sep, _lasts ) \
72         ( *(_lasts) = strtok( (_s), (_sep) ) )
73
74 #ifndef PATH_MAX
75 #define PATH_MAX _MAX_PATH
76 #endif
77
78 // Types missing from Win32 'stat.h' (hopefully Windows
79 // will either act sensibly or ignore most of them).
80 #define _S_IFBLK                0x3000
81 #define S_IRWXU                 _S_IRWXU
82 #define S_IXUSR                 _S_IXUSR
83 #define S_IWUSR                 _S_IWUSR
84 #define S_IRUSR                 _S_IRUSR
85 #define S_IXGRP                 _S_IXGRP
86 #define S_IWGRP                 _S_IWGRP
87 #define S_IRGRP                 _S_IRGRP
88 #define S_IXOTH                 _S_IXOTH
89 #define S_IWOTH                 _S_IWOTH
90 #define S_IROTH                 _S_IROTH
91
92 #define _S_IRWXU                (_S_IREAD | _S_IWRITE | _S_IEXEC)
93 #define _S_IXUSR                _S_IEXEC
94 #define _S_IWUSR                _S_IWRITE
95 #define _S_IRUSR                _S_IREAD
96 #define _S_IXGRP                _S_IEXEC
97 #define _S_IWGRP                _S_IWRITE
98 #define _S_IRGRP                _S_IREAD
99 #define _S_IXOTH                _S_IEXEC
100 #define _S_IWOTH                _S_IWRITE
101 #define _S_IROTH                _S_IREAD
102
103 #define S_ISFIFO(m)             _S_ISFIFO(m)
104 #define S_ISDIR(m)              _S_ISDIR(m)
105 #define S_ISCHR(m)              _S_ISCHR(m)
106 #define S_ISBLK(m)              _S_ISBLK(m)
107 #define S_ISREG(m)              _S_ISREG(m)
108
109 #define _S_ISFIFO(m)    (((m) & _S_IFMT) == _S_IFIFO)
110 #define _S_ISDIR(m)             (((m) & _S_IFMT) == _S_IFDIR)
111 #define _S_ISCHR(m)             (((m) & _S_IFMT) == _S_IFCHR)
112 #define _S_ISBLK(m)             (((m) & _S_IFMT) == _S_IFBLK)
113 #define _S_ISREG(m)             (((m) & _S_IFMT) == _S_IFREG)
114
115
116 #if defined(__USE_BSD) || defined(_BSD_SOURCE)
117 /* Convenience macros for operations on timevals.
118    NOTE: `timercmp' does not work for >= or <=.
119    Note also that 'timerset', 'timerclear' and
120    'timercmp' are (perhaps strangely) already
121    defined, along with various other 'time'
122    functions in WinSock.h  */
123 # define timeradd(a, b, result)                                               \
124   do {                                                                        \
125     (result)->tv_sec = (a)->tv_sec + (b)->tv_sec;                             \
126     (result)->tv_usec = (a)->tv_usec + (b)->tv_usec;                          \
127     if ((result)->tv_usec >= 1000000)                                         \
128       {                                                                       \
129     ++(result)->tv_sec;                                               \
130     (result)->tv_usec -= 1000000;                                             \
131       }                                                                       \
132   } while (0)
133 # define timersub(a, b, result)                                               \
134   do {                                                                        \
135     (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;                             \
136     (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;                          \
137     if ((result)->tv_usec < 0) {                                              \
138       --(result)->tv_sec;                                                     \
139       (result)->tv_usec += 1000000;                                           \
140     }                                                                         \
141   } while (0)
142 #endif  /* BSD */
143
144 #if !defined(__BIT_TYPES_DEFINED) || !defined(__BIT_TYPES_DEFINED__)
145 #define __BIT_TYPES_DEFINED__ 1
146 // Doesn't yet define all 'bit types'. Only those
147 // needed by Ardour. More can be added as needed.
148 #ifndef __int8_t_defined
149 #define __int8_t_defined
150 typedef unsigned char      u_int8_t;
151 typedef unsigned short int u_int16_t;
152 typedef unsigned int       u_int32_t;
153 typedef unsigned __int64   u_int64_t;
154
155 typedef signed char        int8_t;
156 typedef unsigned char      uint8_t;
157 typedef short              int16_t;
158 typedef unsigned short     uint16_t;
159 typedef int                int32_t;
160 typedef unsigned           uint32_t;
161 typedef long long          int64_t;
162 typedef unsigned long long uint64_t;
163 #endif  // __int8_t
164
165 #ifndef __register_t_defined
166 #define __register_t_defined
167 typedef int register_t;
168 #endif  // __register_t
169 #endif  // __BIT_TYPESD
170
171 // throw()
172 #ifndef __THROW
173 #ifdef __cplusplus
174 #define __THROW  throw()
175 #else
176 #define __THROW
177 #endif
178 #endif
179
180 // System V compatibility
181 typedef unsigned short ushort;
182 typedef unsigned int   uint;
183
184 // mode_t
185 #ifndef _MODE_T_
186 #define _MODE_T_
187 typedef unsigned short _mode_t;
188
189 #ifndef NO_OLDNAMES
190 typedef _mode_t mode_t;
191 #endif /* NO_OLDNAMES */
192 #endif /* _MODE_T_ */
193
194 // int64 abs()
195 #ifdef __cplusplus // Normal 'C' doesn't permit over-ridden functions !!
196 inline uint64_t abs(int64_t val)
197 {
198         if (val < 0)
199                 return val * (-1);
200         else
201                 return val;
202 }
203 #endif
204
205 // fmin() and fmax()
206 #define fmin(a, b) min((double)a, (double)b)
207 #define fmax(a, b) max((double)a, (double)b)
208
209 // approximate POSIX pipe()
210 #define pipe(handles) _pipe(handles, 4096, _O_BINARY)
211
212 // Windows mkdir() doesn't care about access privileges
213 #define mkdir(path, mode) _mkdir(path)
214
215 // Redefine 'ftruncate()' to use the glib-win32 version
216 #define ftruncate(fd, len) g_win32_ftruncate((gint)fd, (guint)len)
217
218
219 // #include the main headers for Ardour MSVC
220 #ifdef __cplusplus
221 #if defined(LIBPBD_DLL) || defined(PBD_IS_IN_WIN_STATIC_LIB)
222 #include <pbd/msvc_pbd.h>
223
224 #ifdef LIBPBD_DLL
225 #define DEFAULT_COMPARISONS_DEFINED
226 #define DECLARE_DEFAULT_COMPARISONS(Type) \
227         LIBPBD_API bool operator >  (const Type& lhs, const Type& rhs); \
228         LIBPBD_API bool operator <  (const Type& lhs, const Type& rhs); \
229         LIBPBD_API bool operator != (const Type& lhs, const Type& rhs); \
230         LIBPBD_API bool operator == (const Type& lhs, const Type& rhs);
231 #endif
232 #endif
233 #if defined(BUILDING_LIBARDOUR) || defined(LIBARDOUR_IS_IN_WIN_STATIC_LIB)
234 #include <ardour/msvc_libardour.h>
235 #endif
236 #if defined(BUILDING_RUBBERBAND) || defined(RUBBERBAND_IS_IN_WIN_STATIC_LIB)
237 #include <rubberband/msvc_rubberband.h>
238 #endif
239 #endif // __cplusplus
240
241 #ifndef DEFAULT_COMPARISONS_DEFINED
242 #define DEFAULT_COMPARISONS_DEFINED
243 #define DECLARE_DEFAULT_COMPARISONS(Type) \
244         extern bool operator >  (const Type& lhs, const Type& rhs); \
245         extern bool operator <  (const Type& lhs, const Type& rhs); \
246         extern bool operator != (const Type& lhs, const Type& rhs); \
247         extern bool operator == (const Type& lhs, const Type& rhs);
248 #endif
249
250 // round().... Unlike Linux, Windows doesn't seem to support the
251 // concept of a system-wide (or programmable) rounding direction.
252 // Fortunately, 'round to nearest' seems to be the default action
253 // under Linux, so let's copy that until we find out otherwise.
254 #define rint(value)  round(value)
255 #if !defined(LIBPBD_API) || defined(PBD_IS_IN_WIN_STATIC_LIB)
256 extern  double round(double x);
257 #endif
258
259 #endif /* __ardour_msvc_extensions_h__ */