v0.4.1
Fast, portable C library for geometry input/output
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules
global.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2017, Fougue Ltd. <http://www.fougue.pro>
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 **
9 ** 1. Redistributions of source code must retain the above copyright
10 ** notice, this list of conditions and the following disclaimer.
11 **
12 ** 2. Redistributions in binary form must reproduce the above
13 ** copyright notice, this list of conditions and the following
14 ** disclaimer in the documentation and/or other materials provided
15 ** with the distribution.
16 **
17 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ****************************************************************************/
29 
41 #pragma once
42 
43 /* "config.h" is generated by cmake, it should reside in the out-of-source
44  * build dir.
45  * In CMakeFiles.txt, the directory where resides "config.h" is added to the
46  * include path list
47  */
48 #include "config.h"
49 
50 /* GMIO_OS_WIN */
51 #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) \
52  || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
53  || defined(__NT__)
54 # define GMIO_OS_WIN
55 #endif
56 
57 /* GMIO_OS_LINUX */
58 #if defined(__linux) || defined(__linux__) || defined(linux)
59 # define GMIO_OS_LINUX
60 #endif
61 
62 /* GMIO_OS_MAC */
63 #if defined(__APPLE__)
64 # define GMIO_OS_MAC
65 #endif
66 
67 /* GMIO_DECL_IMPORT */
68 /* GMIO_DECL_EXPORT */
69 #ifdef GMIO_OS_WIN
70 # define GMIO_DECL_EXPORT __declspec(dllexport)
71 # define GMIO_DECL_IMPORT __declspec(dllimport)
72 #else
73 
74 # define GMIO_DECL_EXPORT
75 
76 # define GMIO_DECL_IMPORT
77 #endif
78 
79 /* GMIO_API */
80 #ifdef GMIO_DLL
81 # ifdef GMIO_MAKING_DLL
82 # define GMIO_API GMIO_DECL_EXPORT
83 # else
84 # define GMIO_API GMIO_DECL_IMPORT
85 # endif /* GMIO_MAKING_DLL */
86 #else
87 
89 # define GMIO_API
90 #endif
91 
92 /* GMIO_HAVE_INT64_TYPE */
93 #if defined(GMIO_HAVE_INT64_T) \
94  || defined(GMIO_HAVE_MSVC_INT64) \
95  || defined(GMIO_HAVE_LONG_LONG)
96 # define GMIO_HAVE_INT64_TYPE
97 #endif
98 
99 /* Typedefs for specific width integers */
100 #ifdef GMIO_HAVE_STDINT_H
101 # include <stdint.h>
102 #else
103 typedef char int8_t;
104 typedef unsigned char uint8_t;
105 
106 # if GMIO_SIZEOF_SHORT == 2
107 typedef short int16_t;
108 typedef unsigned short uint16_t;
109 # else
110 # error Not supported: sizeof(short) != 2
111 # endif
112 
113 # if GMIO_SIZEOF_INT == 4
114 typedef int int32_t;
115 typedef unsigned int uint32_t;
116 # elif GMIO_SIZEOF_LONG == 4
117 typedef long int32_t;
118 typedef unsigned long uint32_t;
119 # else
120 # error Failed to find a 32bit integer type with 'int' and 'long'
121 # endif
122 
123 # ifndef GMIO_HAVE_INT64_T
124 # if defined(GMIO_HAVE_MSVC_INT64)
125 typedef __int64_t int64_t;
126 typedef unsigned __int64_t uint64_t;
127 # elif defined(GMIO_HAVE_LONG_LONG)
128 typedef long long int64_t;
129 typedef unsigned long long uint64_t;
130 # endif
131 #endif
132 
133 # ifdef GMIO_HAVE_INT64_TYPE
134 typedef int64_t intmax_t;
135 typedef uint64_t uintmax_t;
136 # else
137 typedef int32_t intmax_t;
138 typedef uint32_t uintmax_t;
139 # endif
140 
141 # define INT16_MAX 0x7FFF
142 # define UINT16_MAX 0xFFFF
143 # define INT32_MAX 0x7FFFFFFF
144 # define UINT32_MAX 0xFFFFFFFF
145 
146 #endif
147 
148 /* GMIO_HAVE_C99_BOOL */
149 #ifndef __cplusplus
150 # if defined(GMIO_HAVE_C99_BOOL)
151 # include <stdbool.h>
152 # endif
153 # if !defined(__bool_true_false_are_defined) && !defined(DOXYGEN)
154 typedef int bool;
155 enum gmio_bool_value
156 {
157  false = 0,
158  true = 1
159 };
160 # define __bool_true_false_are_defined 1
161 # endif
162 #endif
163 
164 /* GMIO_UNUSED */
166 #define GMIO_UNUSED(x) (void)x;
167 
168 /* GMIO_INLINE */
169 #ifndef GMIO_INLINE
170 # if defined(__GNUC__)
171 # define GMIO_INLINE __inline__ static /* Compatible with C90 */
172 # elif defined(_MSC_VER)
173 # define GMIO_INLINE __inline static
174 # elif !defined(DOXYGEN)
175 # define GMIO_INLINE static
176 # else
177 
178 # define GMIO_INLINE
179 # endif
180 #endif
181 
182 /* GMIO_RESTRICT */
183 #ifndef GMIO_RESTRICT
184 # if defined(__GNUC__)
185 # define GMIO_RESTRICT __restrict__ /* Compatible with C90 */
186 # elif defined(_MSC_VER)
187 # define GMIO_RESTRICT __restrict
188 # elif defined(GMIO_HAVE_C99_RESTRICT) /* TODO: add cmake detection */
189 # define GMIO_RESTRICT restrict
190 # else
191 
192 # define GMIO_RESTRICT
193 # endif
194 #endif
195 
196 /* GMIO_C_LINKAGE_BEGIN */
197 /* GMIO_C_LINKAGE_END */
198 #ifdef __cplusplus
199 # define GMIO_C_LINKAGE_BEGIN extern "C" {
200 # define GMIO_C_LINKAGE_END }
201 #else
202 
203 # define GMIO_C_LINKAGE_BEGIN
204 
205 # define GMIO_C_LINKAGE_END
206 #endif
207 
208 /* GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE */
209 /* GMIO_PRAGMA_MSVC_WARNING_POP */
210 #if defined(_MSC_VER) && _MSC_VER >= 1400 /* Visual C++ 2008 */
211 # define GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(__code__) \
212  __pragma(warning(push)) \
213  __pragma(warning(disable: __code__))
214 # define GMIO_PRAGMA_MSVC_WARNING_POP() \
215  __pragma(warning(pop))
216 #else
217 
225 # define GMIO_PRAGMA_MSVC_WARNING_PUSH_AND_DISABLE(__code__)
226 
233 # define GMIO_PRAGMA_MSVC_WARNING_POP()
234 #endif
235 
237 #define GMIO_ARRAY_SIZE(array) sizeof(array) / sizeof(*array)
238 
Fougue © 2017