[7918] Improve portability in work with uint64 string format specifiers and in code...
[getmangos.git] / src / shared / Common.h
blob4edd6e7f89deea85cb1f777eb5cc6dd9b0d6c08b
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_COMMON_H
20 #define MANGOSSERVER_COMMON_H
22 // config.h needs to be included 1st
23 #ifdef HAVE_CONFIG_H
24 #ifdef PACKAGE
25 #undef PACKAGE
26 #endif //PACKAGE
27 #ifdef PACKAGE_BUGREPORT
28 #undef PACKAGE_BUGREPORT
29 #endif //PACKAGE_BUGREPORT
30 #ifdef PACKAGE_NAME
31 #undef PACKAGE_NAME
32 #endif //PACKAGE_NAME
33 #ifdef PACKAGE_STRING
34 #undef PACKAGE_STRING
35 #endif //PACKAGE_STRING
36 #ifdef PACKAGE_TARNAME
37 #undef PACKAGE_TARNAME
38 #endif //PACKAGE_TARNAME
39 #ifdef PACKAGE_VERSION
40 #undef PACKAGE_VERSION
41 #endif //PACKAGE_VERSION
42 #ifdef VERSION
43 #undef VERSION
44 #endif //VERSION
45 # include "config.h"
46 #undef PACKAGE
47 #undef PACKAGE_BUGREPORT
48 #undef PACKAGE_NAME
49 #undef PACKAGE_STRING
50 #undef PACKAGE_TARNAME
51 #undef PACKAGE_VERSION
52 #undef VERSION
53 #endif //HAVE_CONFIG_H
55 #include "Platform/Define.h"
57 #if COMPILER == COMPILER_MICROSOFT
58 # pragma warning(disable:4996) // 'function': was declared deprecated
59 #ifndef __SHOW_STUPID_WARNINGS__
60 # pragma warning(disable:4005) // 'identifier' : macro redefinition
61 # pragma warning(disable:4018) // 'expression' : signed/unsigned mismatch
62 # pragma warning(disable:4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
63 # pragma warning(disable:4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data
64 # pragma warning(disable:4305) // 'identifier' : truncation from 'type1' to 'type2'
65 # pragma warning(disable:4311) // 'variable' : pointer truncation from 'type' to 'type'
66 # pragma warning(disable:4355) // 'this' : used in base member initializer list
67 # pragma warning(disable:4800) // 'type' : forcing value to bool 'true' or 'false' (performance warning)
68 #endif // __SHOW_STUPID_WARNINGS__
69 #endif // __GNUC__
71 // must be the first thing to include for it to work
72 #include "MemoryLeaks.h"
74 #include "Utilities/UnorderedMap.h"
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <string.h>
78 #include <time.h>
79 #include <math.h>
80 #include <errno.h>
81 #include <signal.h>
82 #include <assert.h>
84 #if PLATFORM == PLATFORM_WINDOWS
85 #define STRCASECMP stricmp
86 #else
87 #define STRCASECMP strcasecmp
88 #endif
90 #include <set>
91 #include <list>
92 #include <string>
93 #include <map>
94 #include <queue>
95 #include <sstream>
96 #include <algorithm>
98 #include "LockedQueue.h"
99 #include "Threading.h"
101 #include <ace/Basic_Types.h>
102 #include <ace/Guard_T.h>
103 #include <ace/RW_Thread_Mutex.h>
104 #include <ace/Thread_Mutex.h>
107 #if PLATFORM == PLATFORM_WINDOWS
108 # define FD_SETSIZE 4096
109 # include <ace/config-all.h>
110 // XP winver - needed to compile with standard leak check in MemoryLeaks.h
111 // uncomment later if needed
112 //#define _WIN32_WINNT 0x0501
113 # include <ws2tcpip.h>
114 //#undef WIN32_WINNT
115 #else
116 # include <sys/types.h>
117 # include <sys/ioctl.h>
118 # include <sys/socket.h>
119 # include <netinet/in.h>
120 # include <unistd.h>
121 # include <netdb.h>
122 #endif
124 #if COMPILER == COMPILER_MICROSOFT
126 #include <float.h>
128 #define I64FMT "%016I64X"
129 #define snprintf _snprintf
130 #define atoll __atoi64
131 #define vsnprintf _vsnprintf
132 #define strdup _strdup
133 #define finite(X) _finite(X)
135 #else
137 #define stricmp strcasecmp
138 #define strnicmp strncasecmp
139 #define I64FMT "%016llX"
141 #endif
143 #define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
144 #define UI64LIT(N) ACE_UINT64_LITERAL(N)
146 #define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
147 #define SI64LIT(N) ACE_INT64_LITERAL(N)
149 inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
151 #define atol(a) strtoul( a, NULL, 10)
153 #define STRINGIZE(a) #a
155 enum TimeConstants
157 MINUTE = 60,
158 HOUR = MINUTE*60,
159 DAY = HOUR*24,
160 MONTH = DAY*30,
161 YEAR = MONTH*12,
162 IN_MILISECONDS = 1000
165 enum AccountTypes
167 SEC_PLAYER = 0,
168 SEC_MODERATOR = 1,
169 SEC_GAMEMASTER = 2,
170 SEC_ADMINISTRATOR = 3,
171 SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
174 enum LocaleConstant
176 LOCALE_enUS = 0,
177 LOCALE_koKR = 1,
178 LOCALE_frFR = 2,
179 LOCALE_deDE = 3,
180 LOCALE_zhCN = 4,
181 LOCALE_zhTW = 5,
182 LOCALE_esES = 6,
183 LOCALE_esMX = 7,
184 LOCALE_ruRU = 8
187 #define MAX_LOCALE 9
189 extern char const* localeNames[MAX_LOCALE];
191 LocaleConstant GetLocaleByName(const std::string& name);
193 // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms)
194 #ifdef max
195 #undef max
196 #endif
198 #ifdef min
199 #undef min
200 #endif
202 #ifndef M_PI
203 #define M_PI 3.14159265358979323846
204 #endif
206 #endif