mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-21 20:56:23 +00:00
refactor(Core/Misc): add braces and impove codestyle (#6402)
This commit is contained in:
@@ -34,87 +34,88 @@ namespace Acore::Impl::EnumUtilsImpl
|
||||
|
||||
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);}
|
||||
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)
|
||||
template<typename Enum>
|
||||
static bool IsValid(Enum value)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToIndex(value);
|
||||
return true;
|
||||
} catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Acore::Impl::EnumUtilsImpl::EnumUtils<Enum>::ToIndex(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
static bool IsValid(std::underlying_type_t<Enum> value) { return IsValid(static_cast<Enum>(value)); }
|
||||
|
||||
template <typename Enum>
|
||||
class Iterator
|
||||
catch (...)
|
||||
{
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Iterator() : _index(EnumUtils::Count<Enum>()) {}
|
||||
explicit Iterator(size_t index) : _index(index) { }
|
||||
template<typename Enum>
|
||||
static bool IsValid(std::underlying_type_t<Enum> value) { return IsValid(static_cast<Enum>(value)); }
|
||||
|
||||
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; }
|
||||
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;
|
||||
|
||||
value_type operator[](difference_type d) const { return FromIndex<Enum>(_index + d); }
|
||||
value_type operator*() const { return operator[](0); }
|
||||
Iterator() : _index(EnumUtils::Count<Enum>()) {}
|
||||
explicit Iterator(size_t index) : _index(index) { }
|
||||
|
||||
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; }
|
||||
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; }
|
||||
|
||||
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; }
|
||||
value_type operator[](difference_type d) const { return FromIndex<Enum>(_index + d); }
|
||||
value_type operator*() const { return operator[](0); }
|
||||
|
||||
private:
|
||||
difference_type _index;
|
||||
};
|
||||
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; }
|
||||
|
||||
template <typename Enum>
|
||||
static Iterator<Enum> Begin() { return Iterator<Enum>(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; }
|
||||
|
||||
template <typename Enum>
|
||||
static Iterator<Enum> End() { return Iterator<Enum>(); }
|
||||
private:
|
||||
difference_type _index;
|
||||
};
|
||||
|
||||
template <typename Enum>
|
||||
static Acore::IteratorPair<Iterator<Enum>> Iterate() { return { Begin<Enum>(), End<Enum>() }; }
|
||||
template <typename Enum>
|
||||
static Iterator<Enum> Begin() { return Iterator<Enum>(0); }
|
||||
|
||||
template <typename Enum>
|
||||
static char const* ToConstant(Enum value) { return ToString(value).Constant; }
|
||||
template <typename Enum>
|
||||
static Iterator<Enum> End() { return Iterator<Enum>(); }
|
||||
|
||||
template <typename Enum>
|
||||
static char const* ToTitle(Enum value) { return ToString(value).Title; }
|
||||
template <typename Enum>
|
||||
static Acore::IteratorPair<Iterator<Enum>> Iterate() { return { Begin<Enum>(), End<Enum>() }; }
|
||||
|
||||
template <typename Enum>
|
||||
static char const* ToDescription(Enum value) { return ToString(value).Description; }
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user