logog
logger optimized for games
platform.hpp
Go to the documentation of this file.
1 
5 #ifndef __LOGOG_PLATFORM_HPP__
6 #define __LOGOG_PLATFORM_HPP__
7 
8 #ifdef DOXYGEN
9 
10 #define LOGOG_FLAVOR_WINDOWS 1
11 
12 #define LOGOG_FLAVOR_POSIX 1
13 #endif
14 
15 #ifndef LOGOG_FLAVOR_WINDOWS
16 #ifndef LOGOG_FLAVOR_POSIX
17 
18 /* The user hasn't told us which flavor we're running on, so we must make a guess as to which platform is valid. */
19 
20 /* If this is MSVC, then it's Windows like */
21 #ifdef _MSC_VER
22 #define LOGOG_FLAVOR_WINDOWS 1
23 #endif // _MSC_VER
24 
25 /* gcc probably means Posix */
26 #ifdef __GNUC__
27 #define LOGOG_FLAVOR_POSIX 1
28 #endif
29 
30 #ifdef __CYGWIN__
31 #ifdef LOGOG_UNICODE
32 #error LOGOG_UNICODE not supported on Cygwin platform because Cygwin does not support vsnwprintf
33 #endif
34 /* Cygwin lacks vsnprintf support in headers but it's in the libraries. First we
35  * need to define the constants size_t and va_list, then define vsnprintf */
36 #include <cstdio>
37 #include <cstdlib>
38 #include <cstdarg>
39 extern int vsnprintf(char *str, size_t size, const char *format, va_list ap);
40 #define LOGOG_USE_TR1 1
41 #endif // __CYGWIN__
42 
43 #ifdef __linux__
44 #define LOGOG_USE_TR1 1
45 #endif
46 
47 #ifdef __APPLE__
48 #ifndef __clang__
49 #define LOGOG_USE_TR1 1
50 #else
51 #if !(__has_include(<unordered_map>))
52 #define LOGOG_USE_TR1 1
53 #endif // !(__has_include(<unordered_map>))
54 #endif // __clang
55 #endif // __APPLE__
56 
57 /* Detect IBM's XL C++ */
58 #ifdef __IBMCPP__
59 // Enable use of TR1 unorderd_map etc.
60 #define __IBMCPP_TR1__ 1
61 #ifdef __PPC__
62 #define LOGOG_FLAVOR_POSIX 1
63 #endif // __PPC__
64 #endif // __IBMCPP__
65 
66 /* If we've recognized it already, it's a relatively modern compiler */
67 #if defined( LOGOG_FLAVOR_WINDOWS ) || defined( LOGOG_FLAVOR_POSIX )
68 #define LOGOG_HAS_UNORDERED_MAP 1
69 #endif // defined(...)
70 
71 /* PS3 */
72 #ifdef SN_TARGET_PS3
73 #include "proprietary/ps3.hpp"
74 #endif
75 
76 #endif // LOGOG_FLAVOR_POSIX
77 #endif // LOGOG_FLAVOR_WINDOWS
78 
79 #ifdef LOGOG_FLAVOR_WINDOWS
80 /* Detect Xbox 360 */
81 #if _XBOX_VER >= 200
82 #include "proprietary/xbox360.hpp"
83 #else
84 /* Windows has been detected. */
85 
91 #ifdef LOGOG_LEAK_DETECTION_WINDOWS
92 #define _CRTDBG_MAP_ALLOC
93 #include <stdlib.h>
94 #include <crtdbg.h>
95 
96 #ifdef _DEBUG
97 #ifndef DBG_NEW
98 #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
99 #define new DBG_NEW
100 #endif
101 #endif // _DEBUG
102 #endif // LOGOG_LEAK_DETECTION_WINDOWS
103 
104 #include "windows.h"
105 #endif // _XBOX_VER
106 #endif // LOGOG_FLAVOR_WINDOWS
107 
108 #ifndef LOGOG_FLAVOR_WINDOWS
109 #ifndef LOGOG_FLAVOR_POSIX
110 #error Platform flavor not detected. Please see platform.hpp to configure this platform.
111 #endif
112 #endif
113 
114 // For the FILE type.
115 #include <cstdio>
116 // For POSIX file access.
117 #include <cstdlib>
118 // For Ubuntu 11 and ptrdiff_t
119 #include <cstddef>
120 
121 #include <ctime>
122 
123 #if defined(LOGOG_LEAK_DETECTION) || defined(LOGOG_INTERNAL_DEBUGGING)
124 #include <cstdio>
125 #include <iostream>
126 #endif // LOGOG_LEAK_DETECTION || LOGOG_INTERNAL_DEBUGGING
127 
128 #ifdef LOGOG_FLAVOR_POSIX
129 #include <sys/time.h>
130 // for uint64_t
131 #include <inttypes.h>
132 #include <wchar.h>
133 // for strstr support
134 #include <cstring>
135 #endif
136 
137 // For Unicode support
138 #include <typeinfo>
139 
140 // How this compiler prefers to represent a pragma when described within a macro
141 #ifdef LOGOG_FLAVOR_WINDOWS
142 #define LOGOG_MICROSOFT_PRAGMA_IN_MACRO( x ) __pragma( x )
143 #else // LOGOG_FLAVOR_WINDOWS
144 #define LOGOG_MICROSOFT_PRAGMA_IN_MACRO( x )
145 #endif
146 
147 /* ----------------------------------------------------------- */
148 /* Here's the stuff your compiler may have a problem with... */
149 
151 
153 #define LOGOG_HASH std::tr1::hash
154 
156 #ifdef LOGOG_HAS_UNORDERED_MAP
157 #ifdef LOGOG_USE_TR1
158 #include <tr1/unordered_map>
159 #else
160 #include <unordered_map>
161 #endif // LOGOG_USE_TR1
162 #ifdef _GLIBCXX_UNORDERED_MAP
163 #define LOGOG_UNORDERED_MAP std::unordered_map
164 #else // _GLIBCXX_UNORDERED_MAP
165 #define LOGOG_UNORDERED_MAP std::tr1::unordered_map
166 #endif // _GLIBCXX_UNORDERED_MAP
167 #else // LOGOG_HAS_UNORDERED_MAP
168 #include <hash_map>
169 #define LOGOG_UNORDERED_MAP std::hash_map
170 #endif // LOGOG_HAS_UNORDERED_MAP
171 
173 #define LOGOG_INTERNAL_FAILURE abort();
174 
175 /* ----------------------------------------------- */
176 /* Here's the stuff that's pretty standard in STL by now. */
177 
179 #define LOGOG_PAIR std::pair
180 #include <list>
182 #define LOGOG_LIST std::list
183 #include <vector>
185 #define LOGOG_VECTOR std::vector
186 #include <set>
188 #define LOGOG_SET std::set
189 
190 #define LOGOG_EQUAL_TO std::equal_to
191 
193 
195 #define LOGOG_DEFAULT_PORT 9987
196 
198 #include <cstdarg>
199 
200 
201 
202 #endif // __LOGOG_PLATFORM_HPP