Platform.hpp
Go to the documentation of this file.
1 
4 #ifndef GOSU_PLATFORM_HPP
5 #define GOSU_PLATFORM_HPP
6 
7 #ifdef __BIG_ENDIAN__
8 # define GOSU_IS_BIG_ENDIAN
9 # define IDENTITY_FUN bigToNative
10 # define IDENTITY_FUN2 nativeToBig
11 # define CONV_FUN littleToNative
12 # define CONV_FUN2 nativeToLittle
13 #else
14 # define GOSU_IS_LITTLE_ENDIAN
15 # define IDENTITY_FUN littleToNative
16 # define IDENTITY_FUN2 nativeToLittle
17 # define CONV_FUN bigToNative
18 # define CONV_FUN2 nativeToBig
19 #endif
20 
21 #include <algorithm>
22 
23 namespace Gosu
24 {
25  template<typename T> T IDENTITY_FUN(T t) { return t; }
26  template<typename T> T IDENTITY_FUN2(T t) { return t; }
27 
28  template<typename T>
29  T CONV_FUN(T t)
30  {
31  char* begin = reinterpret_cast<char*>(&t);
32  std::reverse(begin, begin + sizeof t);
33  return t;
34  }
35 
36  template<typename T> T CONV_FUN2(T t) { return CONV_FUN(t); }
37 }
38 
39 #undef IDENTITY_FUN
40 #undef IDENTITY_FUN2
41 #undef CONV_FUN
42 #undef CONV_FUN2
43 
44 #if defined(_MSC_VER)
45 # define GOSU_NORETURN __declspec(noreturn)
46 #elif defined(__GNUC__)
47 # define GOSU_NORETURN __attribute__ ((noreturn))
48 #endif
49 
50 #if defined(WIN32)
51 # define GOSU_IS_WIN
52 #else
53 # define GOSU_IS_UNIX
54 # if defined(__linux) || defined(__FreeBSD__)
55 # define GOSU_IS_X
56 # else
57 # define GOSU_IS_MAC
58 # include <TargetConditionals.h>
59 # if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
60 # define GOSU_IS_IPHONE
61 # endif
62 # endif
63 #endif
64 
65 #ifndef SWIG
66 # if (defined(_MSC_VER) && _MSC_VER >= 1700) || ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__))
67 # define GOSU_CPP11_ENABLED
68 # endif
69 #endif
70 
71 #ifdef GOSU_CPP11_ENABLED
72 # define GOSU_UNIQUE_PTR std::unique_ptr
73 # define GOSU_MOVE_UNIQUE_PTR(ptr) std::move(ptr)
74 #else
75 # define GOSU_UNIQUE_PTR std::auto_ptr
76 # define GOSU_MOVE_UNIQUE_PTR(ptr) (ptr)
77 #endif
78 
79 #ifndef GOSU_DEPRECATED
80 # if defined(GOSU_IS_WIN)
81 # define GOSU_DEPRECATED __declspec(deprecated)
82 # elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
83 # define GOSU_DEPRECATED __attribute__((__deprecated__))
84 # else
85 # define GOSU_DEPRECATED
86 # endif
87 #endif
88 
89 #endif