| Perspective3D_api Documentation Perspective3D

perspective_sys.h
Aller à la documentation de ce fichier.
1
19 #ifndef PERSPECTIVE_SYS_H
20 #define PERSPECTIVE_SYS_H
21
22 #include <cstdint> /* Types de taille fixe */
23 #include <cstring> /* memset(), memcpy() ... */
24
25 #ifndef __cplusplus
26 #error Compilateur C++ requis !
27 #endif // __cplusplus
28
29 /* Détection du système d'exploitation. */
30 #if defined(linux) || defined(__linux) || defined(__linux__)
31 #define PSYS_LINUX /* Linux */
32 #define PSYS_POSIX
33 #endif // linux
34
35 #if defined(WIN32) || defined(_WIN32) || defined(__WINDOWS__) || defined(__TOS_WIN__) || defined(PREDEF_COMPILER_VISUALC) || defined(__MINGW32__) || defined(__CYGWIN__)
36 #define PSYS_WINDOWS /* Windows */
37 #include "windows.h"
38 #include "winnt.h" // Pour les macros spécifiques à l'architecture.
39 #ifdef _MSC_VER
40 #define PSYS_WIN_MSVC
41 #endif // _MSC_VER
42
43 #ifdef __MINGW32__
44 #define PSYS_MINGW
45 #endif // __MINGW32__
46
47 #ifdef __MINGW32__
48 #define PSYS_CYGWIN
49 #endif // __CYGWIN__
50
51 #endif // WIN32
52
53 #if defined(__ANDROID__)
54 #define PSYS_ANDROID
55 #include <android/api-level.h> /* Nécessaire pour avoir __ANDROID_API__ */
56 // #define PSYS_POSIX /* Nécessite le NDK */
57 #endif // __ANDROID__
58
59 #if defined(__BEOS__)
60 #define PSYS_BEOS /* BEOS */
61 #define PSYS_POSIX
62 #endif // __BEOS__
63
64 #if defined(_AIX)
65 #define PSYS_AIX
66 #define PSYS_POSIX
67 #endif // _AIX
68
69 #if defined (__hpux)
70 #define PSYS_HP_UX
71 #define PSYS_POSIX
72 #endif // __hpux
73
74 #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
75 #include <sys/param.h>
76 #if defined(BSD)
77 #define PSYS_BSD
78 #if defined(__FreeBSD__)
79 #define PSYS_FREEBSD /* FreeBSD */
80 #elif defined(__OpenBSD__)
81 #define PSYS_OPENBSD /* OpenBSD */
82 #elif defined(__NetBSD__)
83 #define PSYS_NETBSD /* NetBSD */
84 #elif defined(__DragonFly__)
85 #define PSYS_DRAGONFLY_BSD /* DragonFly BSD */
86 #endif // __FreeBSD__
87 #define PSYS_POSIX
88 #endif // BSD
89 #endif // __unix__
90
91 #if defined(__sun) && defined(__SVR4)
92 #define PSYS_SOLARIS
93 #endif // __sun
94
95 #if (defined(__APPLE__) && defined(__MACH__))
96 // #ifdef __MACOSX__
97 // #define PSYS_MACOSX
98 // #endif // __MACOSX__
99
100 #include <TargetConditionals.h>
101 #if TARGET_IPHONE_SIMULATOR == 1 /* iOS dans Xcode */
102 #define PSYS_IOS
103 #elif TARGET_OS_IPHONE == 1 /* iOS sur iPhone, iPad, etc. */
104 #define PSYS_IOS
105 #elif TARGET_OS_MAC == 1 /* OSX */
106 #define PSYS_MACOSX
107 #define PSYS_POSIX
108 #endif // TARGET_IPHONE_SIMULATOR
109 #endif // __APPLE__
110
111 /* Détection du compilateur. */
112 #if defined(_MSC_VER)
113 #define PSYS_CXX_MSVC
114 #include <intrin.h>
115 #elif defined(__IBMC__) || defined(__IBMCPP__)
116 #define PSYS_CXX_IBM_XL
117 #elif defined(__PGI)
118 #define PSYS_CXX_PGC
119 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
120 #define PSYS_CXX_SOLARIS_STUDIO
121 #elif defined(__CC_ARM)
122 #define PSYS_CXX_ARM_COMPILER
123 #elif defined(__BORLANDC__) || defined(__CODEGEARC__)
124 #define PSYS_CXX_CPPBUILDER
125 #elif defined(__DMC__)
126 #define PSYS_CXX_DMD
127 #elif defined(__OPEN64__) || defined(__OPENCC__)
128 #define PSYS_CXX_OPEN64
129 #elif defined(__ICC) || defined(__INTEL_COMPILER) /* A définir avant le contrôle __GNUC__, ICC le défini également ! */
130 #define PSYS_CXX_ICC
131 #elif defined(__clang__) /* Même topo, Clang définit __GNUC__ */
132 #define PSYS_CXX_CLANG
133 #include <features.h>
134 #elif defined(__GNUC__)
135 #define PSYS_CXX_GCC
136 #ifdef PSYS_LINUX
137 #include <features.h>
138 #endif // PSYS_LINUX
139 #endif // _MSC_VER
140
141 /* GlibC */
142 #if defined(__GNU_LIBRARY__) && defined(__GLIBC__) && defined(__GLIBC_MINOR__)
143 #define PSYS_GLIBC
144 #endif // __GNU_LIBRARY__
145
146 /* Architecture X86 */
147 #if defined(i386) || defined(__i386) || defined(__i386__) || \
148 defined(__i486__) || defined(__i586__) || defined(__i686__) || \
149 defined(__X86__) || defined(_X86_) || defined(__I86__) || \
150 defined(__IA32__) || defined (_M_IX86) || defined(__THW_INTEL__) || defined(__INTEL__)
151 #define PARCH_X86
152 #endif // __i386__
153
154 /* Architecture X86_64 */
155 #if defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64)
156 #define PARCH_X86_64
157 #endif // __amd64__
158
159 /* ARM */
160 #if defined(__arm__) || defined(__arm) || defined(_M_ARM) || defined(_ARM) || defined(__TARGET_ARCH_ARM)
161 #define PARCH_ARM
162 #endif // __arm__
163
164 /* ARM Thumb */
165 #if defined(__thumb__) || defined(_M_ARMT) || defined(__TARGET_ARCH_THUMB)
166 #define PARCH_ARM_THUMB
167 #endif // __thumb__
168
169 /* Itanium 64 */
170 #if defined(__ia64) || defined(__itanium__) || defined(_M_IA64)
171 #define PARCH_IA64
172 #endif // __ia64
173
174 /* PowerPC */
175 #if defined(__powerpc__) || defined(__ppc__) || defined(__PPC__)
176 #define PARCH_POWERPC
177 #if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(__64BIT__) || defined(_LP64) || defined(__LP64__)
178 #define PARCH_POWERPC_64
179 #else
180 #define PARCH_POWERPC_32
181 #endif // __powerpc64__
182 #endif // __powerpc__
183
184 /* SPARC */
185 #if defined(__sparc)
186 #define PARCH_SPARC
187 #endif // __sparc
188
189 /* Restriction de la plate-forme */
190 #if !defined(PSYS_LINUX) && !defined(PSYS_WINDOWS) && !defined(PSYS_MACOSX)
191 #error Plateforme non supportée.
192 #endif // PSYS_LINUX ...
193
194 /* Compatible PC. */
195 #if defined(PARCH_X86) || defined(PARCH_X86_64)
196 #define PARCH_X86_X64
197 #else
198 #error Architecture non supportée.
199 #endif // PARCH_X86
200
201 #if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
202 defined(PARCH_X86_X64) || defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(__MIPSEL__)
203 #define PARCH_LITTLE_ENDIAN
204 #elif (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || \
205 defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(__MIPSEB__)
206 #define PARCH_BIG_ENDIAN
207 #endif // __BYTE_ORDER__
208
209 #if defined(PARCH_LITTLE_ENDIAN) && defined(PARCH_BIG_ENDIAN)
210 #error "PARCH_LITTLE_ENDIAN && PARCH_BIG_ENDIAN ???"
211 #endif // PARCH_LITTLE_ENDIAN && PARCH_BIG_ENDIAN
212
213 #if 1 /* Force la détection du boutisme */
214 #if !defined(PARCH_LITTLE_ENDIAN) && !defined(PARCH_BIG_ENDIAN)
215 #error "!PARCH_LITTLE_ENDIAN && !PARCH_BIG_ENDIAN ???"
216 #endif // !PARCH_LITTLE_ENDIAN && !PARCH_BIG_ENDIAN
217 #endif // 1
218
219 #if defined (PSYS_ANDROID) /* Avant Linux !!! */
220 #if __ANDROID_API__ == 1
221 #define PSYS_ANDROID_VERSION_STR "1.0"
222 #elif __ANDROID_API__ == 2
223 #define PSYS_ANDROID_VERSION_STR "1.1"
224 #elif __ANDROID_API__ == 3
225 #define PSYS_ANDROID_VERSION_STR "1.5"
226 #elif __ANDROID_API__ == 4
227 #define PSYS_ANDROID_VERSION_STR "1.6"
228 #elif __ANDROID_API__ == 5
229 #define PSYS_ANDROID_VERSION_STR "2.0"
230 #elif __ANDROID_API__ == 6
231 #define PSYS_ANDROID_VERSION_STR "2.0.1"
232 #elif __ANDROID_API__ == 7
233 #define PSYS_ANDROID_VERSION_STR "2.1"
234 #elif __ANDROID_API__ == 8
235 #define PSYS_ANDROID_VERSION_STR "2.2"
236 #elif __ANDROID_API__ == 9
237 #define PSYS_ANDROID_VERSION_STR "2.3"
238 #elif __ANDROID_API__ == 10
239 #define PSYS_ANDROID_VERSION_STR "2.3.3"
240 #elif __ANDROID_API__ == 11
241 #define PSYS_ANDROID_VERSION_STR "3.0"
242 #elif __ANDROID_API__ == 12
243 #define PSYS_ANDROID_VERSION_STR "3.1"
244 #elif __ANDROID_API__ == 13
245 #define PSYS_ANDROID_VERSION_STR "3.2"
246 #elif __ANDROID_API__ == 14
247 #define PSYS_ANDROID_VERSION_STR "4.0"
248 #elif __ANDROID_API__ == 15
249 #define PSYS_ANDROID_VERSION_STR "4.0.3"
250 #elif __ANDROID_API__ == 16
251 #define PSYS_ANDROID_VERSION_STR "4.1"
252 #elif __ANDROID_API__ == 17
253 #define PSYS_ANDROID_VERSION_STR "4.2"
254 #elif __ANDROID_API__ == 18
255 #define PSYS_ANDROID_VERSION_STR "4.3"
256 #elif __ANDROID_API__ == 19
257 #define PSYS_ANDROID_VERSION_STR "4.4"
258 #elif __ANDROID_API__ == 20
259 #define PSYS_ANDROID_VERSION_STR "4.4W"
260 #elif __ANDROID_API__ == 21
261 #define PSYS_ANDROID_VERSION_STR "5.0"
262 #elif __ANDROID_API__ == 22
263 #define PSYS_ANDROID_VERSION_STR "5.1"
264 #elif __ANDROID_API__ == 23
265 #define PSYS_ANDROID_VERSION_STR "6.0"
266 #elif __ANDROID_API__ == 24
267 #define PSYS_ANDROID_VERSION_STR "7.0"
268 #elif __ANDROID_API__ == 25
269 #define PSYS_ANDROID_VERSION_STR "7.1"
270 #else
271 #define PSYS_ANDROID_VERSION_STR "> 7.1"
272 #endif // __ANDROID_API__
273 #define PSYS_PLATEFORME_STR "Android " PSYS_ANDROID_VERSION_STR
274 #elif defined(PSYS_LINUX)
275 #ifdef PSYS_GLIBC
276 #define PSYS_PLATEFORME_STR "GNU/Linux"
277 #else
278 #define PSYS_PLATEFORME_STR "Linux"
279 #endif // PSYS_GLIBC
280 #elif defined(PSYS_WINDOWS)
281 #define PSYS_PLATEFORME_STR "Windows"
282 #elif defined(PSYS_MACOSX)
283 #define PSYS_PLATEFORME_STR "Mac OS X"
284 #elif defined PSYS_IOS
285 #define PSYS_PLATEFORME_STR "iOS"
286 #elif defined(PSYS_FREEBSD)
287 #define PSYS_PLATEFORME_STR "FreeBSD"
288 #elif defined(PSYS_OPENBSD)
289 #define PSYS_PLATEFORME_STR "OpenBSD"
290 #elif defined(PSYS_NETBSD)
291 #define PSYS_PLATEFORME_STR "NetBSD"
292 #elif defined(PSYS_DRAGONFLY_BSD)
293 #define PSYS_PLATEFORME_STR "DragonFly BSD"
294 #elif defined(PSYS_BEOS)
295 #define PSYS_PLATEFORME_STR "BeOS"
296 #elif defined(PSYS_SOLARIS)
297 #define PSYS_PLATEFORME_STR "Solaris"
298 #elif defined(PSYS_HP_UX)
299 #define PSYS_PLATEFORME_STR "HP-UX"
300 #elif defined(PSYS_AIX)
301 #define PSYS_PLATEFORME_STR "IBM AIX"
302 #else
303
306 #define PSYS_PLATEFORME_STR "~"
307 #endif // PSYS_ANDROID
308
309 #if defined(PARCH_X86)
310 #define PSYS_ARCH_STR "x86"
311 #elif defined(PARCH_X86_64)
312 #define PSYS_ARCH_STR "x86_64"
313 #elif defined(PARCH_IA64)
314 #define PSYS_ARCH_STR "IA64"
315 #elif defined(PARCH_POWERPC)
316 #define PSYS_ARCH_STR "PPC"
317 #elif defined(PARCH_SPARC)
318 #define PSYS_ARCH_STR "SPARC"
319 #elif defined (PARCH_ARM)
320 #define PSYS_ARCH_STR "ARM"
321 #elif defined(PARCH_ARM_THUMB)
322 #define PSYS_ARCH_STR "ARM Thumb"
323 #else
324
327 #define PSYS_ARCH_STR "~"
328 #endif // PARCH_X86
329
330 #if defined(PSYS_CXX_GCC)
331 #define PSYS_COMPILATEUR_STR "GCC"
332 #elif defined(PSYS_CXX_CLANG)
333 #define PSYS_COMPILATEUR_STR "Clang"
334 #elif defined(PSYS_CXX_ICC)
335 #define PSYS_COMPILATEUR_STR "Intel C++"
336 #elif defined(PSYS_CXX_MSVC)
337 #define PSYS_COMPILATEUR_STR "Microsoft Visual C++"
338 #elif defined(PSYS_CXX_PGC)
339 #define PSYS_COMPILATEUR_STR "PGC/PGC++"
340 #elif defined(PSYS_CXX_IBM_XL)
341 #define PSYS_COMPILATEUR_STR "IBM XL"
342 #elif defined(PSYS_CXX_SOLARIS_STUDIO)
343 #define PSYS_COMPILATEUR_STR "Solaris Studio"
344 #elif defined(PSYS_CXX_ARM_COMPILER)
345 #define PSYS_COMPILATEUR_STR "ARM Compiler"
346 #elif defined(PSYS_CXX_CPPBUILDER)
347 #define PSYS_COMPILATEUR_STR "Borland C++"
348 #elif defined(PSYS_CXX_DMD)
349 #define PSYS_COMPILATEUR_STR "Digital Mars C++"
350 #elif defined (PSYS_CXX_OPEN64)
351 #define PSYS_COMPILATEUR_STR "Open64"
352 #else
353
356 #define PSYS_COMPILATEUR_STR "~"
357 #endif // PSYS_CXX_GCC
358
359 #define PSYS_CPP_VERSION __cplusplus
360
361 #if (PSYS_CPP_VERSION >= 201703L)
362 #define PSYS_CPP17
363 #endif // PSYS_CPP_VERSION
364 #if (PSYS_CPP_VERSION >= 201402L)
365 #define PSYS_CPP14
366 #endif // PSYS_CPP_VERSION
367 #if (PSYS_CPP_VERSION >= 201103L)
368 #define PSYS_CPP11
369 #endif // PSYS_CPP_VERSION
370 #if (PSYS_CPP_VERSION >= 199711L)
371 #define PSYS_CPP98
372 #endif // PSYS_CPP_VERSION
373
374 #if !defined(PSYS_CPP11)
375 #define nullptr ((void*) 0)
376 #endif // PSYS_CPP11
377
381 #if !defined(PSYS_CPP11) && !defined(thread_local)
382 #if (defined(PSYS_CXX_GCC) && defined(_GLIBCXX_HAVE_TLS)) || defined(PSYS_CXX_CLANG)
383 #define PSYS_TLS __thread
384 #elif defined(PSYS_CXX_MSVC)
385 #define PSYS_TLS __declspec(thread)
386 #else
387 #ifdef PSYS_CXX_ICC
388 #ifdef PSYS_LINUX
389 #define PSYS_TLS __thread
390 #elif defined(PSYS_WINDOWS)
391 #define PSYS_TLS __declspec(thread)
392 #else
393 #define PSYS_TLS
394 #endif // PSYS_LINUX
395 #else
396 #define PSYS_TLS
397 #endif // PSYS_CXX_ICC
398 #endif // PSYS_CXX_GCC
399 #else
400 #define PSYS_TLS thread_local
401 #endif // PSYS_CPP11
402
406 #if (defined(PSYS_CXX_GCC) || defined(PSYS_CXX_CLANG)) && !defined(PSYS_MINGW) // MinGW a quelques problèmes pour le moment avec __restrict__ ...
407 #define __restrict__ PSYS_restrict
408 #elif defined(PSYS_CXX_MSVC)
409 #define __restrict PSYS_restrict
410 #else
411 #define PSYS_restrict
412 #endif // PSYS_CXX_GCC ...
413
414 #undef F_INLINE
415 #undef F_CONST
416 #undef F_PURE
417 #undef P_UNUSED
418 #undef F_DEOPTIM
419
420 #ifdef PSYS_CXX_GCC
421 #define F_DEOPTIM __attribute__((optimize("O0")))
422 #else
423
426 #define F_DEOPTIM
427 #endif // PSYS_CXX_GCC
428
429 #if defined(PSYS_CXX_GCC)
430 #define F_INLINE static inline __attribute__ ((always_inline)) /* Fonctions */
431 #define M_INLINE inline __attribute__ ((always_inline)) /* Méthodes */
432 #define F_CONST __attribute__ ((const))
433 #define F_PURE __attribute__ ((pure))
434 #define likely(x) __builtin_expect(!!(x), 1)
435 #define unlikely(x) __builtin_expect(!!(x), 0)
436 #elif defined(PSYS_CXX_CLANG)
437 #define F_INLINE static inline __attribute__ ((always_inline))
438 #define M_INLINE inline __attribute__ ((always_inline))
439 #define F_CONST __attribute__ ((const))
440 #define F_PURE
441 #define likely(x) __builtin_expect(!!(x), 1)
442 #define unlikely(x) __builtin_expect(!!(x), 0)
443 #elif defined(PSYS_CXX_MSVC)
444 #define F_INLINE static inline
445 #define M_INLINE __forceinline
446 #define F_CONST
447 #define F_PURE
448 #define likely(x)
449 #define unlikely(x)
450 #else
451
454 #define F_INLINE inline
455
459 #define M_INLINE inline
460
464 #define F_CONST
465
469 #define F_PURE
470 #endif // PSYS_CXX_GCC
471
475 #define P_UNUSED(X) ((void)(X))
476
477 #if !defined(DLL_IMPORT) || !defined(DLL_EXPORT) || !defined(DLL_LOCAL) || !defined(DLL_INTERNAL)
478 #undef DLL_IMPORT
479 #undef DLL_EXPORT
480 #undef DLL_LOCAL
481 #undef DLL_INTERNAL
482
483 #ifdef PSYS_WINDOWS // Windows, MinGW ou Cygwin
484 #define DLL_IMPORT __declspec(dllimport)
485 #define DLL_EXPORT __declspec(dllexport)
486 #define DLL_LOCAL
487 #define DLL_INTERNAL DLL_LOCAL
488 #else
489 #if __GNUC__ >= 4
490 #define DLL_IMPORT __attribute__ ((visibility ("default")))
491 #define DLL_EXPORT __attribute__ ((visibility ("default")))
492 #define DLL_LOCAL __attribute__ ((visibility ("hidden")))
493 #define DLL_INTERNAL __attribute__ ((visibility ("internal"))) /* Attention, la visiblité "internal" peut provoquer des incompatibilités avec l'ABI si du code interne est appelé depuis l'extérieur (via un pointeur de fonction par exemple). */
494 #else
495 #define DLL_IMPORT
496 #define DLL_EXPORT
497 #define DLL_LOCAL
498 #define DLL_INTERNAL
499 #endif // __GNUC__
500 #endif // PSYS_WINDOWS
501 #endif // !DLL_IMPORT || !DLL_EXPORT || !DLL_LOCAL || !DLL_INTERNAL
502
503 #if defined(PSYS_CXX_GCC) && defined(PARCH_X86_X64)
504 #define FAST_CALL __attribute__ ((fastcall))
505 #elif defined(PSYS_CXX_MSVC) && defined(PARCH_X86_X64)
506 #define FAST_CALL __fastcall
507 #else
508
511 #define FAST_CALL
512 #endif // PSYS_CXX_GCC && PARCH_X86_X64
513
514 #ifdef DLL_API
515 #undef DLL_API /* Lors de la compilation du client... */
516 #endif // DLL_API
517
518 #if INTERNE_PERSPECTIVE3D /* Lors de la compilation de la bibliothèque... */
519 #define DLL_API DLL_EXPORT
520 #else
521
524 #define DLL_API DLL_IMPORT
525 #endif // INTERNE_PERSPECTIVE3D
526
527 #if defined(PSYS_CPP11)
528 #define register /* Déprécié depuis C++11. */
529 #endif // PSYS_CPP11
530
531 #define P_INTERDIT_COPIE(CLASSE) CLASSE(const CLASSE &) = delete;\
532 CLASSE &operator=(const CLASSE &) = delete;
533
534 #define P_INTERDIT_COPIE_TEMPLATE(CLASSE, T) CLASSE(const CLASSE<T> &) = delete;\
535 CLASSE &operator=(const CLASSE<T> &) = delete;
536
537 #define P_INTERDIT_COPIE_TEMPLATE2(CLASSE, T1, T2) CLASSE(const CLASSE<T1, T2> &) = delete;\
538 CLASSE &operator=(const CLASSE<T1, T2> &) = delete;
539
540 #define P_INTERDIT_COPIE_TEMPLATE3(CLASSE, T1, T2, T3) CLASSE(const CLASSE<T1, T2, T3> &) = delete;\
541 CLASSE &operator=(const CLASSE<T1, T2, T3> &) = delete;
542
543 #define P_INTERDIT_COPIE_TEMPLATE_N(CLASSE, ...) CLASSE(const CLASSE<__VA_ARGS__> &) = delete;\
544 CLASSE &operator=(const CLASSE<__VA_ARGS__> &) = delete;
545
550 #ifdef PSYS_CPP17 /* C++17 */
551 #define EXPLICIT_FALLTHROUGH [[fallthrough]]
552 #elif defined(PSYS_CPP14) || defined(PSYS_CPP11) /* C++14 ou C++11... */
553 #if defined(PSYS_CXX_GCC)
554 #define EXPLICIT_FALLTHROUGH [[gnu::fallthrough]]
555 #elif defined(PSYS_CXX_CLANG)
556 #define EXPLICIT_FALLTHROUGH [[clang::fallthrough]]
557 #else
558 #define EXPLICIT_FALLTHROUGH
559 #endif // PSYS_CXX_GCC
560 #else /* C++03 ou C */
561 //#define EXPLICIT_FALLTHROUGH
562 #if defined(PSYS_CXX_GCC)
563 #define EXPLICIT_FALLTHROUGH __attribute__ ((fallthrough))
564 //#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
565 #elif defined(PSYS_CXX_CLANG)
566 #define EXPLICIT_FALLTHROUGH
567 #pragma clang diagnostic ignored "-Wimplicit-fallthrough"
568 #else
569
572 #define EXPLICIT_FALLTHROUGH
573 #endif // PSYS_CXX_GCC
574 #endif // PSYS_CPP17
575
576 #ifdef SUPPORT_DL
577
580 #ifdef PSYS_WINDOWS
581 //#include <Windows.h>
582 #define DL_LOAD(name) LoadLibraryA(name)
583 #define DL_LOAD_GLOBAL(name) LoadLibraryA(name)
584 #define DL_UNLOAD(handle) FreeLibrary((HMODULE) handle)
585 #define DL_GETPROC(handle, name) GetProcAddress((HMODULE) handle, name)
586 #define DL_HANDLE_T (HMODULE)
587 #define DL_PROC_ATTR __stdcall
588 #elif defined(PSYS_POSIX)
589 #include <dlfcn.h>
590 #define DL_LOAD(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
591 #define DL_LOAD_GLOBAL(name) dlopen(name, RTLD_LAZY | RTLD_GLOBAL)
592 #define DL_UNLOAD(handle) (dlclose(handle) == 0)
593 #define DL_GETPROC(handle, name) dlsym(handle, name)
594 #define DL_HANDLE_T (void *)
595 #define DL_PROC_ATTR
596 #else
597 #define DL_LOAD(name) (nullptr)
598 #define DL_LOAD_GLOBAL(name) (nullptr)
599 #define DL_UNLOAD(name) (0)
600 #define DL_GETPROC(handle, name) (nullptr)
601 #define DL_HANDLE_T (void *)
602 #define DL_PROC_ATTR
603 #endif // PSYS_WINDOWS
604 #define DL_DECLARE(PROTO_RETURN, PROTO_ARGUMENTS, VAR_NAME, DL, FUNC_NAME) PROTO_RETURN (DL_PROC_ATTR *VAR_NAME) PROTO_ARGUMENTS = (PROTO_RETURN (*) PROTO_ARGUMENTS) DL_GETPROC(DL, #FUNC_NAME)
605 #endif // SUPPORT_DL
606
611 typedef signed int pint;
612 typedef unsigned int puint;
613 typedef signed short pshort;
614 typedef unsigned short pushort;
615 typedef signed long long plong;
616 typedef unsigned long long pulong;
617
618 #ifdef PSYS_WIN_MSVC
619 typedef __int8 pint8;
620 typedef unsigned __int8 puint8;
621 typedef __int16 pint16;
622 typedef unsigned __int16 puint16;
623 typedef __int32 pint32;
624 typedef unsigned __int32 puint32;
625 typedef __int64 pint64;
626 typedef unsigned __int64 puint64;
627 #else
628 typedef int8_t pint8;
629 typedef uint8_t puint8;
630 typedef int16_t pint16;
631 typedef uint16_t puint16;
632 typedef int32_t pint32;
633 typedef uint32_t puint32;
634 typedef int64_t pint64;
635 typedef uint64_t puint64;
636 #endif // PSYS_WIN_MSVC
637
638 #define Ptest_ptr(PTR) ((PTR) != nullptr)
639
640 #ifdef PSYS_CPP11
641 #include <utility> /* std::swap, std::move... */
642 #endif // PSYS_CPP11
643
647 namespace PerspectiveSys
648 {
649 #ifdef PSYS_CPP11
650 // template<typename T> static inline void swap(T& a, T& b)
651 // {
652 // T c(std::move(a));
653 // a = std::move(b);
654 // b = std::move(c);
655 // }
656
657 template<typename T> static inline void swap(T& a, T& b)
658 {
659 std::swap<T>(a, b);
660 }
661 #else
662 template<typename T> static inline void swap(T& a, T& b)
663 {
664 T c(a);
665 a = b;
666 b = c;
667 }
668 #endif // PSYS_CPP11
669
670 template<typename T> static inline void swap_xor(T& a, T& b)
671 {
672 a ^= b;
673 b ^= a;
674 a ^= b;
675 }
676
680 M_INLINE bool PetitBoutisme() F_CONST;
681 bool PetitBoutisme()
682 {
683 #if defined(PARCH_LITTLE_ENDIAN)
684 return true;
685 #elif defined(PARCH_BIG_ENDIAN)
686 return false;
687 #else
688 static const pint test_b = 1;
689 return ((*reinterpret_cast<const char *>(&test_b)) == 1);
690 #endif // PARCH_LITTLE_ENDIAN
691 }
692
696 template<typename T> static inline T InverseOctsInt(const T* v)
697 {
698 T ret;
699
700 switch (sizeof(T))
701 {
702 case 1: // 8 bits
703 {
704 return *v;
705 }
706 case 2: // 16 bits
707 {
708 ret = *v;
709 return (((ret >> 8) & 0xFFU) | ((ret & 0xFFU) << 8));
710 }
711 case 4: // 32 bits
712 {
713 ret = *v;
714 return (((ret & 0xFF000000U) >> 24) | ((ret & 0x00FF0000U) >> 8) | ((ret & 0x0000FF00U) << 8) | ((ret & 0x000000FFU) << 24));
715 }
716 case 8: // 64 bits
717 {
718 ret = *v;
719 return (((ret & 0xFF00000000000000ULL) >> 56) | ((ret & 0x00FF000000000000ULL) >> 40) |
720 ((ret & 0x0000FF0000000000ULL) >> 24) | ((ret & 0x000000FF00000000ULL) >> 8) |
721 ((ret & 0x00000000FF000000ULL) << 8) | ((ret & 0x0000000000FF0000ULL) << 24) |
722 ((ret & 0x000000000000FF00ULL) << 40) | ((ret & 0x00000000000000FFULL) << 56));
723 }
724 default:
725 {
726 break;
727 }
728 }
729
730 /* Inversion générique: */
731 char * dest = reinterpret_cast<char *>(&ret);
732 char const * source = ((char const *) v) + sizeof(T) - 1;
733 for(unsigned long iter = sizeof(T); iter>0; --iter)
734 {
735 *dest++ = *source--;
736 }
737 return ret;
738 }
739
743 template<typename T> static inline T InverseOcts(const T* v)
744 {
745 #if 0
746 T ret;
747 char * dest = ((char *) &ret);
748 switch (sizeof(T))
749 {
750 case 1: // 8 bits
751 {
752 return *v;
753 }
754 case 2: // 16 bits
755 {
756 ret = *v;
757 PerspectiveSys::swap(dest[0], dest[1]);
758 return ret;
759 }
760 case 4: // 32 bits
761 {
762 ret = *v;
763 PerspectiveSys::swap(dest[0], dest[3]);
764 PerspectiveSys::swap(dest[1], dest[2]);
765 return ret;
766 }
767 case 8: // 64 bits
768 {
769 ret = *v;
770 PerspectiveSys::swap(dest[0], dest[7]);
771 PerspectiveSys::swap(dest[1], dest[6]);
772 PerspectiveSys::swap(dest[2], dest[5]);
773 PerspectiveSys::swap(dest[3], dest[4]);
774 return ret;
775 }
776 default:
777 {
778 break;
779 }
780 }
781 #else // Beaucoup de casts. C'est moins beau, mais plus rapide (particulièrement avec gcc -O2, qui utilise l'instruction bswap à la place des opérations bits à bits. C'est dans ce cas 4x plus rapide)...
782 switch (sizeof(T))
783 {
784 case 1: // 8 bits
785 {
786 return *v;
787 }
788 case 2: // 16 bits
789 {
790 puint16 ret = *reinterpret_cast<const puint16*>(v);
791 ret = (((ret >> 8) & 0xFFU) | ((ret & 0xFFU) << 8));
792 const T *r = reinterpret_cast<T*>(&ret);
793 return *r;
794 }
795 case 4: // 32 bits
796 {
797 puint32 ret = *reinterpret_cast<const puint32*>(v);
798 ret = (((ret & 0xFF000000U) >> 24) | ((ret & 0x00FF0000U) >> 8) | ((ret & 0x0000FF00U) << 8) | ((ret & 0x000000FFU) << 24));
799 const T *r = reinterpret_cast<T*>(&ret);
800 return *r;
801 }
802 case 8: // 64 bits
803 {
804 puint64 ret = *reinterpret_cast<const puint64*>(v);
805 ret = (((ret & 0xFF00000000000000ULL) >> 56) | ((ret & 0x00FF000000000000ULL) >> 40) |
806 ((ret & 0x0000FF0000000000ULL) >> 24) | ((ret & 0x000000FF00000000ULL) >> 8) |
807 ((ret & 0x00000000FF000000ULL) << 8) | ((ret & 0x0000000000FF0000ULL) << 24) |
808 ((ret & 0x000000000000FF00ULL) << 40) | ((ret & 0x00000000000000FFULL) << 56));
809 const T *r = reinterpret_cast<T*>(&ret);
810 return *r;
811 }
812 default:
813 {
814 break;
815 }
816 }
817 T ret;
818 char * dest = reinterpret_cast<char *>(&ret);
819 #endif // 0
820 /* Inversion générique: */
821 char const * source = ((char const *) v) + sizeof(T) - 1;
822 for(unsigned long iter = sizeof(T); iter>0; --iter)
823 {
824 *dest++ = *source--;
825 }
826 return ret;
827 }
828
832 template<typename T> static inline T Conv_PetitBoutisme(const T* v)
833 /* Conversion exclusive vers petit-boutisme. */
834 {
835 if (PetitBoutisme()) // Si architecture petit-boutiste, on touche à rien.
836 {
837 return *v;
838 }
839 return InverseOcts<T>(v);
840 }
841
842 template<typename T> static inline T Conv_PetitBoutisme(T v)
843 {
844 return Conv_PetitBoutisme<T>(&v);
845 }
846
850 template<typename T> static inline T Conv_GrandBoutisme(const T* v)
851 {
852 if (!PetitBoutisme()) // Si architecture grand-boutiste, on touche à rien.
853 {
854 return *v;
855 }
856 return InverseOcts<T>(v);
857 }
858
859 template<typename T> static inline T Conv_GrandBoutisme(T v)
860 {
861 return Conv_GrandBoutisme<T>(&v);
862 }
863
867 template<typename T> static inline T Conv_PetitBoutismeInt(const T* v)
868 /* Conversion exclusive vers petit-boutisme. */
869 {
870 if (PetitBoutisme()) // Si architecture petit-boutiste, on touche à rien.
871 {
872 return *v;
873 }
874 return InverseOctsInt<T>(v);
875 }
876
877 template<typename T> static inline T Conv_PetitBoutismeInt(T v)
878 {
879 return Conv_PetitBoutismeInt<T>(&v);
880 }
881
885 template<typename T> static inline T Conv_GrandBoutismeInt(const T* v)
886 {
887 if (!PetitBoutisme()) // Si architecture grand-boutiste, on touche à rien.
888 {
889 return *v;
890 }
891 return InverseOctsInt<T>(v);
892 }
893
894 template<typename T> static inline T Conv_GrandBoutismeInt(T v)
895 {
896 return Conv_GrandBoutismeInt<T>(&v);
897 }
898
899 } // namespace PerspectiveSys
900
901 #define Pmemset std::memset
902 #define Pmemcpy std::memcpy
903 #define Pmemmove std::memmove
904
905 #endif // PERSPECTIVE_SYS_H
pint8
int8_t pint8
Definition: perspective_sys.h:628
pshort
signed short pshort
Definition: perspective_sys.h:613
F_CONST
#define F_CONST
Attribut de fonction fonction const (GCC ou Clang).
Definition: perspective_sys.h:464
puint16
uint16_t puint16
Definition: perspective_sys.h:631
pint
signed int pint
Types entiers.
Definition: perspective_sys.h:611
pulong
unsigned long long pulong
Definition: perspective_sys.h:616
puint64
uint64_t puint64
Definition: perspective_sys.h:635
PerspectiveSys
Espace de nommage des fonctions dépendantes de l&#39;architecture.
Definition: perspective_sys.h:647
M_INLINE
#define M_INLINE
Attribut de méthode force inline (GCC ou Clang)).
Definition: perspective_sys.h:459
pint32
int32_t pint32
Definition: perspective_sys.h:632
pushort
unsigned short pushort
Definition: perspective_sys.h:614
pint16
int16_t pint16
Definition: perspective_sys.h:630
puint
unsigned int puint
Definition: perspective_sys.h:612
pint64
int64_t pint64
Definition: perspective_sys.h:634
PerspectiveSys::PetitBoutisme
M_INLINE bool PetitBoutisme() F_CONST
Contrôle l&#39;ordre des octets sur l&#39;architecture actuelle (evalué à l&#39;exécution).
Definition: perspective_sys.h:681
puint32
uint32_t puint32
Definition: perspective_sys.h:633
puint8
uint8_t puint8
Definition: perspective_sys.h:629
plong
signed long long plong
Definition: perspective_sys.h:615