mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-31 01:23:47 +00:00
feat(Core/Logging): rework logging (#4692)
* feat(Core/Logging): rework logging * correct level for sql.sql * del unused config options * Correct build * correct after merge * whitespace 20:29:37 1. 'Player.cpp'. Replace (1) 20:29:37 2. 'ObjectMgr.cpp'. Replace (3) * 1 * correct logging * correct affter merge * 1 * 2 * LOG_LEVEL_WARN * #include "AppenderDB.h" * 3 * 4 * 5 * 1. 'WorldSocket.cpp'. Replace (1) * 6 * 1
This commit is contained in:
46
src/common/Utilities/IteratorPair.h
Normal file
46
src/common/Utilities/IteratorPair.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2008-2021 TrinityCore <http://www.trinitycore.org/>
|
||||
*/
|
||||
|
||||
#ifndef IteratorPair_h__
|
||||
#define IteratorPair_h__
|
||||
|
||||
#include "Define.h"
|
||||
#include <utility>
|
||||
|
||||
namespace acore
|
||||
{
|
||||
/**
|
||||
* @class IteratorPair
|
||||
*
|
||||
* @brief Utility class to enable range for loop syntax for multimap.equal_range uses
|
||||
*/
|
||||
template<class iterator>
|
||||
class IteratorPair
|
||||
{
|
||||
public:
|
||||
constexpr IteratorPair() : _iterators() { }
|
||||
constexpr IteratorPair(iterator first, iterator second) : _iterators(first, second) { }
|
||||
constexpr IteratorPair(std::pair<iterator, iterator> iterators) : _iterators(iterators) { }
|
||||
|
||||
constexpr iterator begin() const { return _iterators.first; }
|
||||
constexpr iterator end() const { return _iterators.second; }
|
||||
|
||||
private:
|
||||
std::pair<iterator, iterator> _iterators;
|
||||
};
|
||||
|
||||
namespace Containers
|
||||
{
|
||||
template<class M>
|
||||
inline auto MapEqualRange(M& map, typename M::key_type const& key) -> IteratorPair<decltype(map.begin())>
|
||||
{
|
||||
return { map.equal_range(key) };
|
||||
}
|
||||
}
|
||||
//! namespace Containers
|
||||
}
|
||||
//! namespace acore
|
||||
|
||||
#endif // IteratorPair_h__
|
||||
120
src/common/Utilities/SmartEnum.h
Normal file
120
src/common/Utilities/SmartEnum.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2008-2021 TrinityCore <http://www.trinitycore.org/>
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_SMARTENUM_H
|
||||
#define TRINITY_SMARTENUM_H
|
||||
|
||||
#include "IteratorPair.h"
|
||||
#include <iterator>
|
||||
|
||||
struct EnumText
|
||||
{
|
||||
EnumText(char const* c, char const* t, char const* d) : Constant(c), Title(t), Description(d) { }
|
||||
// Enum constant of the value
|
||||
char const* const Constant;
|
||||
// Human-readable title of the value
|
||||
char const* const Title;
|
||||
// Human-readable description of the value
|
||||
char const* const Description;
|
||||
};
|
||||
|
||||
namespace acore::Impl::EnumUtilsImpl
|
||||
{
|
||||
template <typename Enum>
|
||||
struct EnumUtils
|
||||
{
|
||||
static size_t Count();
|
||||
static EnumText ToString(Enum value);
|
||||
static Enum FromIndex(size_t index);
|
||||
static size_t ToIndex(Enum index);
|
||||
};
|
||||
}
|
||||
|
||||
class EnumUtils
|
||||
{
|
||||
public:
|
||||
template <typename Enum>
|
||||
static size_t Count() { return acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::Count(); }
|
||||
template <typename Enum>
|
||||
static EnumText ToString(Enum value) { return acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToString(value); }
|
||||
template <typename Enum>
|
||||
static Enum FromIndex(size_t index) { return acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::FromIndex(index); }
|
||||
template <typename Enum>
|
||||
static uint32 ToIndex(Enum value) { return acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToIndex(value);}
|
||||
|
||||
template<typename Enum>
|
||||
static bool IsValid(Enum value)
|
||||
{
|
||||
try
|
||||
{
|
||||
acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToIndex(value);
|
||||
return true;
|
||||
} catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
static bool IsValid(std::underlying_type_t<Enum> value) { return IsValid(static_cast<Enum>(value)); }
|
||||
|
||||
template <typename Enum>
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
using value_type = Enum;
|
||||
using pointer = Enum*;
|
||||
using reference = Enum&;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
|
||||
Iterator() : _index(EnumUtils::Count<Enum>()) {}
|
||||
explicit Iterator(size_t index) : _index(index) { }
|
||||
|
||||
bool operator==(const Iterator& other) const { return other._index == _index; }
|
||||
bool operator!=(const Iterator& other) const { return !operator==(other); }
|
||||
difference_type operator-(Iterator const& other) const { return _index - other._index; }
|
||||
bool operator<(const Iterator& other) const { return _index < other._index; }
|
||||
bool operator<=(const Iterator& other) const { return _index <= other._index; }
|
||||
bool operator>(const Iterator& other) const { return _index > other._index; }
|
||||
bool operator>=(const Iterator& other) const { return _index >= other._index; }
|
||||
|
||||
value_type operator[](difference_type d) const { return FromIndex<Enum>(_index + d); }
|
||||
value_type operator*() const { return operator[](0); }
|
||||
|
||||
Iterator& operator+=(difference_type d) { _index += d; return *this; }
|
||||
Iterator& operator++() { return operator+=(1); }
|
||||
Iterator operator++(int) { Iterator i = *this; operator++(); return i; }
|
||||
Iterator operator+(difference_type d) const { Iterator i = *this; i += d; return i; }
|
||||
|
||||
Iterator& operator-=(difference_type d) { _index -= d; return *this; }
|
||||
Iterator& operator--() { return operator-=(1); }
|
||||
Iterator operator--(int) { Iterator i = *this; operator--(); return i; }
|
||||
Iterator operator-(difference_type d) const { Iterator i = *this; i -= d; return i; }
|
||||
|
||||
private:
|
||||
difference_type _index;
|
||||
};
|
||||
|
||||
template <typename Enum>
|
||||
static Iterator<Enum> Begin() { return Iterator<Enum>(0); }
|
||||
|
||||
template <typename Enum>
|
||||
static Iterator<Enum> End() { return Iterator<Enum>(); }
|
||||
|
||||
template <typename Enum>
|
||||
static acore::IteratorPair<Iterator<Enum>> Iterate() { return { Begin<Enum>(), End<Enum>() }; }
|
||||
|
||||
template <typename Enum>
|
||||
static char const* ToConstant(Enum value) { return ToString(value).Constant; }
|
||||
|
||||
template <typename Enum>
|
||||
static char const* ToTitle(Enum value) { return ToString(value).Title; }
|
||||
|
||||
template <typename Enum>
|
||||
static char const* ToDescription(Enum value) { return ToString(value).Description; }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,6 @@
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include "Util.h"
|
||||
|
||||
25
src/common/Utilities/Tokenize.cpp
Normal file
25
src/common/Utilities/Tokenize.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
|
||||
*/
|
||||
|
||||
#include "Tokenize.h"
|
||||
|
||||
std::vector<std::string_view> acore::Tokenize(std::string_view str, char sep, bool keepEmpty)
|
||||
{
|
||||
std::vector<std::string_view> tokens;
|
||||
|
||||
size_t start = 0;
|
||||
for (size_t end = str.find(sep); end != std::string_view::npos; end = str.find(sep, start))
|
||||
{
|
||||
if (keepEmpty || (start < end))
|
||||
tokens.push_back(str.substr(start, end - start));
|
||||
|
||||
start = end + 1;
|
||||
}
|
||||
|
||||
if (keepEmpty || (start < str.length()))
|
||||
tokens.push_back(str.substr(start));
|
||||
|
||||
return tokens;
|
||||
}
|
||||
24
src/common/Utilities/Tokenize.h
Normal file
24
src/common/Utilities/Tokenize.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
|
||||
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
|
||||
*/
|
||||
|
||||
#ifndef _ACORE_TOKENIZE_H_
|
||||
#define _ACORE_TOKENIZE_H_
|
||||
|
||||
#include "Common.h"
|
||||
#include <string_view>
|
||||
|
||||
namespace acore
|
||||
{
|
||||
std::vector<std::string_view> Tokenize(std::string_view str, char sep, bool keepEmpty);
|
||||
|
||||
/* this would return string_view into temporary otherwise */
|
||||
std::vector<std::string_view> Tokenize(std::string&&, char, bool) = delete;
|
||||
std::vector<std::string_view> Tokenize(std::string const&&, char, bool) = delete;
|
||||
|
||||
/* the delete overload means we need to make this explicit */
|
||||
inline std::vector<std::string_view> Tokenize(char const* str, char sep, bool keepEmpty) { return Tokenize(std::string_view(str ? str : ""), sep, keepEmpty); }
|
||||
}
|
||||
|
||||
#endif // _ACORE_TOKENIZE_H_
|
||||
Reference in New Issue
Block a user