[9545] Rename ObjectDefines.h -> ObjectGuid.h
[getmangos.git] / src / shared / Common.h
blobef752e071d98f207912111d83c4264438f510794
1 /*
2 * Copyright (C) 2005-2010 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:4244) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
61 # pragma warning(disable:4355) // 'this' : used in base member initializer list
62 #endif // __SHOW_STUPID_WARNINGS__
63 #endif // __GNUC__
65 // must be the first thing to include for it to work
66 #include "MemoryLeaks.h"
68 #include "Utilities/UnorderedMap.h"
69 #include <stdio.h>
70 #include <stdlib.h>
71 #include <string.h>
72 #include <time.h>
73 #include <math.h>
74 #include <errno.h>
75 #include <signal.h>
76 #include <assert.h>
78 #if defined(__sun__)
79 #include <ieeefp.h> // finite() on Solaris
80 #endif
82 #include <set>
83 #include <list>
84 #include <string>
85 #include <map>
86 #include <queue>
87 #include <sstream>
88 #include <algorithm>
90 #include "LockedQueue.h"
91 #include "Threading.h"
93 #include <ace/Basic_Types.h>
94 #include <ace/Guard_T.h>
95 #include <ace/RW_Thread_Mutex.h>
96 #include <ace/Thread_Mutex.h>
98 #if PLATFORM == PLATFORM_WINDOWS
99 # define FD_SETSIZE 4096
100 # include <ace/config-all.h>
101 // XP winver - needed to compile with standard leak check in MemoryLeaks.h
102 // uncomment later if needed
103 //#define _WIN32_WINNT 0x0501
104 # include <ws2tcpip.h>
105 //#undef WIN32_WINNT
106 #else
107 # include <sys/types.h>
108 # include <sys/ioctl.h>
109 # include <sys/socket.h>
110 # include <netinet/in.h>
111 # include <unistd.h>
112 # include <netdb.h>
113 #endif
115 #if COMPILER == COMPILER_MICROSOFT
117 # include <float.h>
119 # define I32FMT "%08I32X"
120 # define I64FMT "%016I64X"
121 # define snprintf _snprintf
122 # define vsnprintf _vsnprintf
123 # define finite(X) _finite(X)
125 #else
127 # define stricmp strcasecmp
128 # define strnicmp strncasecmp
130 # define I32FMT "%08X"
131 # if ACE_SIZEOF_LONG == 8
132 # define I64FMT "%016lX"
133 # else
134 # define I64FMT "%016llX"
135 # endif /* ACE_SIZEOF_LONG == 8 */
137 #endif
139 #define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
140 #define UI64LIT(N) ACE_UINT64_LITERAL(N)
142 #define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
143 #define SI64LIT(N) ACE_INT64_LITERAL(N)
145 #define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
147 inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
149 #define atol(a) strtoul( a, NULL, 10)
151 #define STRINGIZE(a) #a
153 // used for creating values for respawn for example
154 #define MAKE_PAIR64(l, h) uint64( uint32(l) | ( uint64(h) << 32 ) )
155 #define PAIR64_HIPART(x) (uint32)((uint64(x) >> 32) & UI64LIT(0x00000000FFFFFFFF))
156 #define PAIR64_LOPART(x) (uint32)(uint64(x) & UI64LIT(0x00000000FFFFFFFF))
158 #define MAKE_PAIR32(l, h) uint32( uint16(l) | ( uint32(h) << 16 ) )
159 #define PAIR32_HIPART(x) (uint16)((uint32(x) >> 16) & 0x0000FFFF)
160 #define PAIR32_LOPART(x) (uint16)(uint32(x) & 0x0000FFFF)
162 enum TimeConstants
164 MINUTE = 60,
165 HOUR = MINUTE*60,
166 DAY = HOUR*24,
167 MONTH = DAY*30,
168 YEAR = MONTH*12,
169 IN_MILISECONDS = 1000
172 enum AccountTypes
174 SEC_PLAYER = 0,
175 SEC_MODERATOR = 1,
176 SEC_GAMEMASTER = 2,
177 SEC_ADMINISTRATOR = 3,
178 SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
181 enum LocaleConstant
183 LOCALE_enUS = 0, // also enGB
184 LOCALE_koKR = 1,
185 LOCALE_frFR = 2,
186 LOCALE_deDE = 3,
187 LOCALE_zhCN = 4,
188 LOCALE_zhTW = 5,
189 LOCALE_esES = 6,
190 LOCALE_esMX = 7,
191 LOCALE_ruRU = 8
194 #define MAX_LOCALE 9
196 LocaleConstant GetLocaleByName(const std::string& name);
198 extern char const* localeNames[MAX_LOCALE];
200 struct LocaleNameStr
202 char const* name;
203 LocaleConstant locale;
206 // used for iterate all names including alternative
207 extern LocaleNameStr fullLocaleNameList[];
209 //operator new[] based version of strdup() function! Release memory by using operator delete[] !
210 inline char * mangos_strdup(const char * source)
212 char * dest = new char[strlen(source) + 1];
213 strcpy(dest, source);
214 return dest;
217 // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some pother platforms)
218 #ifdef max
219 # undef max
220 #endif
222 #ifdef min
223 # undef min
224 #endif
226 #ifndef M_PI
227 # define M_PI 3.14159265358979323846
228 #endif
230 #ifndef M_PI_F
231 # define M_PI_F float(M_PI)
232 #endif
234 #endif