TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Common.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITYCORE_COMMON_H
20 #define TRINITYCORE_COMMON_H
21 
22 #include "Define.h"
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <time.h>
28 #include <cmath>
29 #include <errno.h>
30 #include <signal.h>
31 #include <assert.h>
32 
33 #include <set>
34 #include <unordered_set>
35 #include <list>
36 #include <string>
37 #include <map>
38 #include <unordered_map>
39 #include <queue>
40 #include <sstream>
41 #include <algorithm>
42 #include <memory>
43 #include <vector>
44 #include <array>
45 
46 #include <boost/optional.hpp>
47 #include <boost/utility/in_place_factory.hpp>
48 #include <boost/functional/hash.hpp>
49 
50 #include "Debugging/Errors.h"
51 
52 #include "Threading/LockedQueue.h"
53 
54 #if PLATFORM == PLATFORM_WINDOWS
55 # include <ws2tcpip.h>
56 
57 # if defined(__INTEL_COMPILER)
58 # if !defined(BOOST_ASIO_HAS_MOVE)
59 # define BOOST_ASIO_HAS_MOVE
60 # endif // !defined(BOOST_ASIO_HAS_MOVE)
61 # endif // if defined(__INTEL_COMPILER)
62 
63 #else
64 # include <sys/types.h>
65 # include <sys/ioctl.h>
66 # include <sys/socket.h>
67 # include <netinet/in.h>
68 # include <unistd.h>
69 # include <netdb.h>
70 #endif
71 
72 #if COMPILER == COMPILER_MICROSOFT
73 
74 #include <float.h>
75 
76 #define snprintf _snprintf
77 #define atoll _atoi64
78 #define vsnprintf _vsnprintf
79 #define llabs _abs64
80 
81 #else
82 
83 #define stricmp strcasecmp
84 #define strnicmp strncasecmp
85 
86 #endif
87 
88 inline float finiteAlways(float f) { return std::isfinite(f) ? f : 0.0f; }
89 
90 inline unsigned long atoul(char const* str) { return strtoul(str, nullptr, 10); }
91 inline unsigned long long atoull(char const* str) { return strtoull(str, nullptr, 10); }
92 
93 #define STRINGIZE(a) #a
94 
96 {
97  MINUTE = 60,
98  HOUR = MINUTE*60,
99  DAY = HOUR*24,
100  WEEK = DAY*7,
101  MONTH = DAY*30,
102  YEAR = MONTH*12,
104 };
105 
107 {
112  SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
113 };
114 
116 {
129 
131 };
132 
134 #define DEFAULT_LOCALE LOCALE_enUS
135 
136 #define MAX_LOCALES 11
137 
138 extern "C" TC_COMMON_API char const* localeNames[TOTAL_LOCALES];
139 
140 TC_COMMON_API LocaleConstant GetLocaleByName(const std::string& name);
141 
142 typedef std::vector<std::string> StringVector;
143 
144 #pragma pack(push, 1)
145 
147 {
148  char const* Str[TOTAL_LOCALES];
149 };
150 
151 #pragma pack(pop)
152 
153 // we always use stdlibc++ std::max/std::min, undefine some not C++ standard defines (Win API and some other platforms)
154 #ifdef max
155 #undef max
156 #endif
157 
158 #ifdef min
159 #undef min
160 #endif
161 
162 #ifndef M_PI
163 #define M_PI 3.14159265358979323846
164 #endif
165 
166 #define MAX_QUERY_LEN 32*1024
167 
169 template <typename T>
170 using Optional = boost::optional<T>;
171 
172 namespace Trinity
173 {
175  template<typename T, typename ...Args>
176  std::unique_ptr<T> make_unique(Args&& ...args)
177  {
178  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
179  }
180 }
181 
184 namespace std
185 {
186  template<class K, class V>
187  struct hash<std::pair<K, V>>
188  {
189  public:
190  size_t operator()(std::pair<K, V> const& key) const
191  {
192  return boost::hash_value(key);
193  }
194  };
195 }
196 
197 #endif
TC_COMMON_API LocaleConstant GetLocaleByName(const std::string &name)
Definition: Common.cpp:37
unsigned long long atoull(char const *str)
Definition: Common.h:91
Definition: Common.h:98
Definition: Common.h:126
#define hash
Definition: private_namespace.h:186
std::unique_ptr< T > make_unique(Args &&...args)
std::make_unique implementation (TODO: remove this once C++14 is supported)
Definition: Common.h:176
Definition: Common.h:111
Definition: Common.h:146
const uint8 OLD_TOTAL_LOCALES
Definition: Common.h:133
Definition: Common.h:102
Definition: Common.h:121
Definition: Common.h:108
STL namespace.
Definition: Common.h:118
Definition: Common.h:101
Definition: Common.h:119
Definition: Common.h:97
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.h:138
Definition: Common.h:110
size_t operator()(std::pair< K, V > const &key) const
Definition: Common.h:190
TimeConstants
Definition: Common.h:95
unsigned long atoul(char const *str)
Definition: Common.h:90
LocaleConstant
Definition: Common.h:115
Definition: Common.h:99
Definition: Common.h:100
AccountTypes
Definition: Common.h:106
Definition: Common.h:127
boost::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Common.h:170
Definition: Common.h:109
#define TC_COMMON_API
Definition: Define.h:116
Definition: Common.h:112
float finiteAlways(float f)
Definition: Common.h:88
std::vector< std::string > StringVector
Definition: Common.h:142
Definition: Common.h:117
Definition: Common.h:103
Definition: Common.h:124
uint8_t uint8
Definition: Define.h:152
Definition: Common.h:123
Definition: Common.h:120
Definition: Common.h:172
Definition: Common.h:122
Definition: Common.h:125
Definition: Common.h:128
Definition: Common.h:130