Thea
Platform.hpp
Go to the documentation of this file.
1 //============================================================================
2 //
3 // This file is part of the Thea toolkit.
4 //
5 // This software is distributed under the BSD license, as detailed in the
6 // accompanying LICENSE.txt file. Portions are derived from other works:
7 // their respective licenses and copyright information are reproduced in
8 // LICENSE.txt and/or in the relevant source files.
9 //
10 // Author: Siddhartha Chaudhuri
11 // First version: 2009
12 //
13 //============================================================================
14 
20 #ifndef __Thea_Platform_hpp__
21 #define __Thea_Platform_hpp__
22 
23 #include <cstddef>
24 
25 #define WIN32_LEAN_AND_MEAN
26 
27 #if !defined(THEA_DEBUG_BUILD) && (!defined(NDEBUG) || defined(_DEBUG))
28 # define THEA_DEBUG_BUILD
29 #endif
30 
31 // NDEBUG needed for assert to be deactivated on release builds
32 #if !defined(THEA_DEBUG_BUILD) && !defined(NDEBUG)
33 # define NDEBUG
34 #endif
35 
36 #ifdef _MSC_VER
37 # define THEA_WINDOWS 1
38  // NOMINMAX required to stop windows.h messing up std::min
39 # ifndef NOMINMAX
40 # define NOMINMAX
41 # endif
42 
43  // Disable pesky warnings of the type: "class <member-classname> needs to have dll-interface to be used by clients of class"
44  // and "non dll-interface class <subclass> used as base for dll-interface class <superclass>."
45 # pragma warning( disable: 4251 )
46 # pragma warning( disable: 4275 )
47 
48  // Disable numerical type conversion "possible loss of precision" warnings
49 # pragma warning( disable: 4244 )
50 
51 #elif defined(__FreeBSD__)
52 # define THEA_FREEBSD 1
53 #elif defined(__OpenBSD__)
54 # define THEA_OPENBSD 1
55 #elif defined(__linux__)
56 # define THEA_LINUX 1
57 #elif defined(__APPLE__)
58  // Retain old OSX tag for backwards-compatibility
59 # define THEA_MAC 1
60 # define THEA_OSX 1
61  // Prevent OS X fp.h header from being included; it defines pi as a constant, which creates a conflict with G3D
62 # define __FP__
63 #else
64 # error Unknown platform
65 #endif
66 
67 #if defined(THEA_FREEBSD) || defined(THEA_OPENBSD)
68 # define THEA_BSD 1
69 #endif
70 
71 // http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros
72 // http://sourceforge.net/p/predef/wiki/Architectures/
73 #if defined(_M_X64) || defined(__x86_64__) || defined(__amd_64__)
74 # define THEA_64BIT 1
75 # define THEA_X64 1
76 #elif defined(_M_IA64) || defined(__ia64) || defined(__ia64__)
77 # define THEA_64BIT 1
78 # define THEA_ITANIUM 1
79 #elif defined(__i386) || defined(_M_IX86)
80 # define THEA_32BIT 1
81 # define THEA_X86 1
82 #elif defined(__aarch64__) || defined(__aarch64)
83 # define THEA_64BIT 1
84 # define THEA_ARM 1
85 #elif defined(_M_ARM) || defined(__arm) || defined(__arm__)
86 # define THEA_32BIT 1
87 # define THEA_ARM 1
88 #elif defined(__powerpc__) || defined(__PPC__) || defined(__POWERPC__)
89 # if defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__) || defined(_LP64)
90 # define THEA_64BIT 1
91 # else
92 # define THEA_32BIT 1
93 # endif
94 # define THEA_POWERPC 1
95 #endif
96 
97 // Symbol visibility flags
98 #include "SymbolVisibility.hpp"
99 
100 // Calling conventions
101 #if defined(_MSC_VER) && defined(THEA_32BIT) // also clang and icc on Windows?
102 # if defined(__GNUC__)
103 # define THEA_CDECL __attribute__((cdecl))
104 # define THEA_STDCALL __attribute__((stdcall))
105 # else
106 # define THEA_CDECL __cdecl
107 # define THEA_STDCALL __stdcall
108 # endif
109 #else
110 # define THEA_CDECL
111 # define THEA_STDCALL
112 #endif
113 
115 #define THEA_ICALL THEA_STDCALL
116 
121 #ifdef _MSC_VER
122 // Microsoft's version http://msdn.microsoft.com/en-us/library/d9x1s805.aspx
123 # define THEA_PRAGMA(x) __pragma(x)
124 #else
125 // C99 standard http://www.delorie.com/gnu/docs/gcc/cpp_45.html
126 # define THEA_PRAGMA(x) _Pragma(#x)
127 #endif
128 
130 #ifdef _MSC_VER
131 # define THEA_BEGIN_PACKED_CLASS(byte_align) THEA_PRAGMA( pack(push, byte_align) )
132 #else
133 # define THEA_BEGIN_PACKED_CLASS(byte_align)
134 #endif
135 
137 #ifdef _MSC_VER
138 # define THEA_END_PACKED_CLASS(byte_align) ; THEA_PRAGMA( pack(pop) )
139 #elif defined(__GNUC__)
140 # define THEA_END_PACKED_CLASS(byte_align) __attribute__((aligned(byte_align))) ;
141 #else
142 # define THEA_END_PACKED_CLASS(byte_align) ;
143 #endif
144 
145 namespace Thea {
146 
147 // The following typedefs are here and not in NumericType.hpp since they are needed by headers that NumericType.hpp itself
148 // depends on.
149 
161 typedef std::ptrdiff_t intx;
162 
173 typedef std::size_t uintx;
174 
175 } // namespace Thea
176 
177 #endif
std::ptrdiff_t intx
A signed integer suitable for indexing a structure held in memory.
Definition: Platform.hpp:161
std::size_t uintx
An unsigned integer suitable for indexing a structure held in memory.
Definition: Platform.hpp:173
Root namespace for the Thea library.