Free Electron
platform.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __platform_h__
8 #define __platform_h__
9 
10 #include "fe/config.h"
11 #include "platform/define.h"
12 
13 #if FE_OS==FE_WIN32 || FE_OS==FE_WIN64
14 #define _CRT_RAND_S
15 #ifndef WIN32_LEAN_AND_MEAN
16  #define WIN32_LEAN_AND_MEAN
17 #endif
18 #define FE_CPLUSPLUS _MSVC_LANG
19 #else
20 #define FE_CPLUSPLUS __cplusplus
21 #endif
22 
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <assert.h>
28 #include <cstddef>
29 
30 #include <iostream>
31 #include <iomanip>
32 #include <fstream>
33 #include <sstream>
34 #include <string>
35 #include <vector>
36 #include <list>
37 #include <map>
38 #include <set>
39 #include <stack>
40 #include <queue>
41 #include <algorithm>
42 #include <functional>
43 #include <atomic>
44 
45 // hash_map is not 'standard', so we have some hoops
46 #if defined(FE_UNORDERED_MAP) && FE_CPLUSPLUS >= 201103L
47 #include <unordered_map>
48 #include <unordered_set>
49 #elif defined(HASH_MAP_IS_MAP)
50 namespace fe_hash
51 {
52  template<class k, class v, class h, class e>
53  class hash_map : public std::map< k,v > { };
54  template<class k, class h, class e>
55  class hash_set : public std::set< k > { };
56 }
57 //#elif defined(GNU_STL_HASH_MAP)
58 #elif FE_COMPILER==FE_GNU
59 #include <ext/hash_map>
60 #include <ext/hash_set>
61 namespace fe_hash = __gnu_cxx;
62 #elif FE_OS==FE_WIN32 || FE_OS==FE_WIN64
63 #include <hash_map>
64 #include <hash_set>
65 #else
66 #include <ext/hash_map>
67 #include <ext/hash_set>
68 #endif
69 
70 #if defined(FE_UNORDERED_MAP) && FE_CPLUSPLUS >= 201103L
71 namespace fe
72 {
73  template<class k, class v, class h, class e>
74  class HashMap : public std::unordered_map< k,v,h,e > { };
75  template<class k, class h, class e>
76  class HashSet : public std::unordered_set< k,h,e > { };
77 }
78 #else
79 namespace fe
80 {
81  template<class k, class v, class h, class e>
82  class HashMap : public ::fe_hash::hash_map< k,v,h,e > { };
83  template<class k, class h, class e>
84  class HashSet : public ::fe_hash::hash_set< k,h,e > { };
85 }
86 #endif
87 
88 #include <time.h>
89 
90 #if FE_OS==FE_WIN32 || FE_OS==FE_WIN64
91 
92  #include <CRTDbg.h>
93  #ifndef NOMINMAX
94  #define NOMINMAX
95  #endif
96  #if FE_COMPILER!=FE_DMC
97  #ifndef AF_IPX
98  #include <winsock2.h>
99  #include <ws2tcpip.h>
100  #endif
101  #endif
102 
103  #include <windows.h> //* causes wacky struct errors (???)
104  #include <mmsystem.h>
105  #include <direct.h>
106 
107  #define mkdir _mkdir
108 
109  #define FE_MESSAGE_LENGTH_MAX 512
110 
111 #elif FE_OS==FE_LINUX
112  #include <sys/time.h>
113  #include <sys/stat.h>
114  #include <sys/types.h>
115  #include <limits.h>
116  #include <unistd.h>
117  #include <errno.h>
118  #include <dlfcn.h>
119  #include <sys/socket.h>
120  #include <arpa/inet.h>
121  #include <netdb.h>
122 
123  #define FE_MESSAGE_LENGTH_MAX 512
124 
125 #elif FE_OS==FE_OSX
126  #include <sys/time.h>
127  #include <sys/stat.h>
128  #include <sys/types.h>
129  #include <unistd.h>
130  #include <errno.h>
131  #include <netinet/in.h>
132  #include <dlfcn.h>
133  #include <sys/socket.h>
134  #include <arpa/inet.h>
135  #include <netdb.h>
136  // and I thought MS was presumptuous...check() is a macro for OSX
137  #include <AssertMacros.h>
138  #ifdef check
139  #undef check
140  #endif
141 
142  #define FE_MESSAGE_LENGTH_MAX 512
143 
144 #elif FE_OS==FE_CYGWIN
145  #include <sys/time.h>
146  #include <sys/types.h>
147  #include <unistd.h>
148  #include <errno.h>
149  #include <netinet/in.h>
150  #include <dlfcn.h>
151  #include <sys/socket.h>
152  #include <arpa/inet.h>
153  #include <netdb.h>
154 
155  #define FE_MESSAGE_LENGTH_MAX 512
156 #endif
157 
158 #if FE_COMPILER==FE_GNU && FE_OS==FE_OSX
159 #ifndef GCC_HASCLASSVISIBILITY
160 #define GCC_HASCLASSVISIBILITY
161 #endif
162 #endif
163 
164 #if FE_COMPILER==FE_MICROSOFT
165  #define FE_DL_EXPORT __declspec(dllexport)
166  #define FE_DL_IMPORT __declspec(dllimport)
167  #define FE_DL_PUBLIC
168  #define FE_DL_LOCAL
169 #elif defined(GCC_HASCLASSVISIBILITY)
170  //* NOTE GCC manual specifies empty FE_DL_IMPORT
171  #define FE_DL_EXPORT __attribute__ ((visibility("default")))
172  #define FE_DL_IMPORT
173  #define FE_DL_PUBLIC FE_DL_EXPORT
174  #define FE_DL_LOCAL __attribute__ ((visibility("hidden")))
175 #else
176  #define FE_DL_EXPORT
177  #define FE_DL_IMPORT
178  #define FE_DL_PUBLIC
179  #define FE_DL_LOCAL
180 #endif
181 
182 #if FE_OS==FE_WIN32 || FE_OS==FE_WIN64
183 #define FE_CDECL __cdecl
184 #else
185 #define FE_CDECL
186 #endif
187 
188 #if FE_COMPILER==FE_GNU || FE_COMPILER==FE_INTEL
189  #include <new>
190 #elif FE_COMPILER==FE_MICROSOFT
191  //* DISABLE: 'this' : used in base member initializer list
192  #pragma warning( disable : 4355 )
193  //* DISABLE: dll-interface complaints
194  #pragma warning( disable : 4275 )
195  #pragma warning( disable : 4251 )
196  #include <new.h>
197 #else
198  #include <new.h>
199 #endif
200 
201 #if FE_OS==FE_WIN32 || FE_OS==FE_WIN64
202  #include <mbstring.h>
203 #else
204  #include <ctype.h>
205 #endif
206 
207 #ifdef FE_BOOST_EXCEPTIONS
208 #include "boost/exception/diagnostic_information.hpp"
209 #endif
210 
211 //* fePlatform is a static lib; FE_PLATFORM_PORT should not be defined.
212 //* You should not be importing or exporting anything from fePlatform.
213 //* In Win32, you can get multiple symbols and MSVCRT lib problems.
214 //* For global static variables, put them in memory.h and memory.cc.
215 //#ifdef MODULE_platform
216 //#define FE_PLATFORM_PORT FE_DL_EXPORT
217 //#else
218 //#define FE_PLATFORM_PORT FE_DL_IMPORT
219 //#endif
220 
221 #ifdef FE_EXPORT_MEMORY
222 #define FE_MEM_PORT FE_DL_EXPORT
223 #else
224 #define FE_MEM_PORT FE_DL_IMPORT
225 #endif
226 
227 #if FE_CODEGEN>FE_DEBUG
228 #define FEASSERT(condition)
229 #elif FE_OS==FE_WIN32 || FE_OS==FE_WIN64
230 #define FEASSERT(condition) _ASSERTE(condition)
231 #else
232 #define FEASSERT(condition) assert(condition)
233 #endif
234 
235 //* suppress 'unused variable' warning/error
236 #define FE_MAYBE_UNUSED(x) (void)x
237 
238 #define FE_SSE FE_USE_SSE
239 
240 #if FE_USE_PRINTF
241 #define fe_printf printf
242 #define fe_fprintf fprintf
243 #else
244 inline void fe_printf_ignore(const char*, ...){}
245 inline void fe_fprintf_ignore(FILE*, const char *, ...){}
246 #define fe_printf fe_printf_ignore
247 #define fe_fprintf fe_fprintf_ignore
248 #endif
249 
250 #include "platform/datatypes.h"
251 #include "platform/error.h"
252 #include "platform/count.h"
253 #include "platform/String.h"
254 #include "platform/type_name.h"
255 #include "platform/Result.h"
256 #include "platform/DL_Loader.h"
257 #include "platform/Mutex.h"
258 #include "platform/memory.h"
259 #include "platform/Regex.h"
260 #include "platform/Thread.h"
261 #include "platform/backtrace.h"
262 #include "platform/debug.h"
263 #include "platform/System.h"
264 #include "platform/Exception.h"
265 #include "platform/UnitTest.h"
266 
267 #endif /* __platform_h__ */
268 
kernel
Definition: namespace.dox:3