TrinityCore
Loading...
Searching...
No Matches
Common.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef TRINITYCORE_COMMON_H
19#define TRINITYCORE_COMMON_H
20
21#include "Define.h"
22#include <array>
23#include <string>
24#include <cstdlib>
25
26#if TRINITY_COMPILER == TRINITY_COMPILER_MICROSOFT
27
28#define atoll _atoi64
29#define llabs _abs64
30
31#else
32
33#define stricmp strcasecmp
34#define strnicmp strncasecmp
35
36#endif
37
38inline unsigned long atoul(char const* str) { return strtoul(str, nullptr, 10); }
39inline unsigned long long atoull(char const* str) { return strtoull(str, nullptr, 10); }
40
41#define STRINGIZE(a) #a
42
44{
45 MINUTE = 60,
47 DAY = HOUR*24,
48 WEEK = DAY*7,
49 MONTH = DAY*30,
50 YEAR = MONTH*12,
51 IN_MILLISECONDS = 1000
52};
53
55{
60 SEC_CONSOLE = 4 // must be always last in list, accounts must have less security level always also
61};
62
64{
77
79};
80
82#define DEFAULT_LOCALE LOCALE_enUS
83
84enum class CascLocaleBit : uint8
85{
86 None = 0,
87 enUS = 1,
88 koKR = 2,
89 Reserved = 3,
90 frFR = 4,
91 deDE = 5,
92 zhCN = 6,
93 esES = 7,
94 zhTW = 8,
95 enGB = 9,
96 enCN = 10,
97 enTW = 11,
98 esMX = 12,
99 ruRU = 13,
100 ptBR = 14,
101 itIT = 15,
102 ptPT = 16
103};
104
105TC_COMMON_API extern char const* localeNames[TOTAL_LOCALES];
106
107TC_COMMON_API LocaleConstant GetLocaleByName(std::string_view name);
108
110
111constexpr inline bool IsValidLocale(LocaleConstant locale)
112{
113 return locale < TOTAL_LOCALES && locale != LOCALE_none;
114}
115
116#pragma pack(push, 1)
117
119{
120 constexpr char const* operator[](LocaleConstant locale) const
121 {
122 return Str[locale];
123 }
124
125 std::array<char const*, TOTAL_LOCALES> Str;
126};
127
128#pragma pack(pop)
129
130// we always use stdlib std::max/std::min, undefine some not C++ standard defines (Win API and some other platforms)
131#ifdef max
132#undef max
133#endif
134
135#ifdef min
136#undef min
137#endif
138
139#ifndef M_PI
140#define M_PI 3.14159265358979323846
141#endif
142
143#ifndef M_PI_4
144#define M_PI_4 0.785398163397448309616
145#endif
146
147#define MAX_QUERY_LEN 32*1024
148
149#endif
unsigned long long atoull(char const *str)
Definition: Common.h:39
LocaleConstant
Definition: Common.h:64
@ LOCALE_zhCN
Definition: Common.h:69
@ LOCALE_deDE
Definition: Common.h:68
@ LOCALE_zhTW
Definition: Common.h:70
@ LOCALE_ptBR
Definition: Common.h:75
@ LOCALE_itIT
Definition: Common.h:76
@ LOCALE_none
Definition: Common.h:74
@ LOCALE_esES
Definition: Common.h:71
@ TOTAL_LOCALES
Definition: Common.h:78
@ LOCALE_ruRU
Definition: Common.h:73
@ LOCALE_frFR
Definition: Common.h:67
@ LOCALE_enUS
Definition: Common.h:65
@ LOCALE_koKR
Definition: Common.h:66
@ LOCALE_esMX
Definition: Common.h:72
constexpr bool IsValidLocale(LocaleConstant locale)
Definition: Common.h:111
CascLocaleBit
Definition: Common.h:85
TC_COMMON_API char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:20
unsigned long atoul(char const *str)
Definition: Common.h:38
const uint8 OLD_TOTAL_LOCALES
Definition: Common.h:81
TC_COMMON_API LocaleConstant GetLocaleByName(std::string_view name)
Definition: Common.cpp:36
TimeConstants
Definition: Common.h:44
@ IN_MILLISECONDS
Definition: Common.h:51
@ MINUTE
Definition: Common.h:45
@ HOUR
Definition: Common.h:46
@ DAY
Definition: Common.h:47
@ MONTH
Definition: Common.h:49
@ WEEK
Definition: Common.h:48
@ YEAR
Definition: Common.h:50
AccountTypes
Definition: Common.h:55
@ SEC_PLAYER
Definition: Common.h:56
@ SEC_ADMINISTRATOR
Definition: Common.h:59
@ SEC_GAMEMASTER
Definition: Common.h:58
@ SEC_MODERATOR
Definition: Common.h:57
@ SEC_CONSOLE
Definition: Common.h:60
TC_COMMON_API CascLocaleBit WowLocaleToCascLocaleBit[TOTAL_LOCALES]
Definition: Common.cpp:45
uint8_t uint8
Definition: Define.h:145
#define TC_COMMON_API
Definition: Define.h:100
Definition: Common.h:119
std::array< char const *, TOTAL_LOCALES > Str
Definition: Common.h:125
constexpr char const * operator[](LocaleConstant locale) const
Definition: Common.h:120