mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Misc: Resolve c++17 TODOs left in code as comments
This commit is contained in:
@@ -23,16 +23,12 @@
|
||||
#include "Errors.h"
|
||||
#include <array>
|
||||
#include <string>
|
||||
//#include <string_view>
|
||||
#include <string_view>
|
||||
#include <openssl/evp.h>
|
||||
#include <cstring>
|
||||
#include "advstd.h" // data/size
|
||||
|
||||
class BigNumber;
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
namespace Impl
|
||||
namespace Trinity::Impl
|
||||
{
|
||||
struct GenericHashImpl
|
||||
{
|
||||
@@ -62,26 +58,11 @@ namespace Impl
|
||||
return hash.GetDigest();
|
||||
}
|
||||
|
||||
private: // c++17
|
||||
template <typename T>
|
||||
static void UpdateData_OLDCPP(GenericHash& hash, T const& data)
|
||||
{
|
||||
hash.UpdateData(data);
|
||||
}
|
||||
|
||||
template <typename T, typename... TRest>
|
||||
static void UpdateData_OLDCPP(GenericHash& hash, T const& data, TRest&&... rest)
|
||||
{
|
||||
hash.UpdateData(data);
|
||||
UpdateData_OLDCPP(hash, std::forward<TRest>(rest)...);
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename... Ts>
|
||||
static auto GetDigestOf(Ts&&... pack) -> std::enable_if_t<advstd::conjunction<advstd::negation<std::is_integral<Ts>>...>::value, Digest>
|
||||
static auto GetDigestOf(Ts&&... pack) -> std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, Digest>
|
||||
{
|
||||
GenericHash hash;
|
||||
UpdateData_OLDCPP(hash, std::forward<Ts>(pack)...);
|
||||
(hash.UpdateData(std::forward<Ts>(pack)), ...);
|
||||
hash.Finalize();
|
||||
return hash.GetDigest();
|
||||
}
|
||||
@@ -105,11 +86,11 @@ namespace Impl
|
||||
int result = EVP_DigestUpdate(_ctx, data, len);
|
||||
ASSERT(result == 1);
|
||||
}
|
||||
// c++17 void UpdateData(std::string_view str) { UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
|
||||
void UpdateData(std::string const& str) { UpdateData(str.c_str()); } /* explicit overload to avoid using the container template */
|
||||
void UpdateData(char const* str) { UpdateData(reinterpret_cast<uint8 const*>(str), strlen(str)); } /* explicit overload to avoid using the container template */
|
||||
void UpdateData(std::string_view str) { UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
|
||||
void UpdateData(std::string const& str) { UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
|
||||
void UpdateData(char const* str) { UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
|
||||
template <typename Container>
|
||||
void UpdateData(Container const& c) { UpdateData(advstd::data(c), advstd::size(c)); }
|
||||
void UpdateData(Container const& c) { UpdateData(std::data(c), std::size(c)); }
|
||||
|
||||
void Finalize()
|
||||
{
|
||||
@@ -128,15 +109,11 @@ namespace Impl
|
||||
Digest _digest = { };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
namespace Crypto
|
||||
namespace Trinity::Crypto
|
||||
{
|
||||
using SHA1 = Trinity::Impl::GenericHash<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
|
||||
using SHA256 = Trinity::Impl::GenericHash<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,15 +23,12 @@
|
||||
#include "Errors.h"
|
||||
#include <array>
|
||||
#include <string>
|
||||
//#include <string_view>
|
||||
#include <string_view>
|
||||
#include <openssl/hmac.h>
|
||||
#include "advstd.h"
|
||||
|
||||
class BigNumber;
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
namespace Impl
|
||||
namespace Trinity::Impl
|
||||
{
|
||||
struct HMACImpl
|
||||
{
|
||||
@@ -72,26 +69,11 @@ namespace Impl
|
||||
return hash.GetDigest();
|
||||
}
|
||||
|
||||
private: // c++17
|
||||
template <typename T>
|
||||
static void UpdateData_OLDCPP(GenericHMAC& hash, T const& data)
|
||||
{
|
||||
hash.UpdateData(data);
|
||||
}
|
||||
|
||||
template <typename T, typename... TRest>
|
||||
static void UpdateData_OLDCPP(GenericHMAC& hash, T const& data, TRest&&... rest)
|
||||
{
|
||||
hash.UpdateData(data);
|
||||
UpdateData_OLDCPP(hash, std::forward<TRest>(rest)...);
|
||||
}
|
||||
|
||||
public:
|
||||
template <typename Container, typename... Ts>
|
||||
static auto GetDigestOf(Container const& seed, Ts&&... pack) -> std::enable_if_t<advstd::conjunction<advstd::negation<std::is_integral<Ts>>...>::value, Digest>
|
||||
static auto GetDigestOf(Container const& seed, Ts&&... pack) -> std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, Digest>
|
||||
{
|
||||
GenericHMAC hash(seed);
|
||||
UpdateData_OLDCPP(hash, std::forward<Ts>(pack)...);
|
||||
(hash.UpdateData(std::forward<Ts>(pack)), ...);
|
||||
hash.Finalize();
|
||||
return hash.GetDigest();
|
||||
}
|
||||
@@ -102,7 +84,7 @@ namespace Impl
|
||||
ASSERT(result == 1);
|
||||
}
|
||||
template <typename Container>
|
||||
GenericHMAC(Container const& container) : GenericHMAC(container.data(), container.size()) {}
|
||||
GenericHMAC(Container const& container) : GenericHMAC(std::data(container), std::size(container)) {}
|
||||
|
||||
~GenericHMAC()
|
||||
{
|
||||
@@ -117,11 +99,11 @@ namespace Impl
|
||||
int result = HMAC_Update(_ctx, data, len);
|
||||
ASSERT(result == 1);
|
||||
}
|
||||
// c++17 void UpdateData(std::string_view str) { UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
|
||||
void UpdateData(std::string const& str) { UpdateData(str.c_str()); } /* explicit overload to avoid using the container template */
|
||||
void UpdateData(char const* str) { UpdateData(reinterpret_cast<uint8 const*>(str), strlen(str)); } /* explicit overload to avoid using the container template */
|
||||
void UpdateData(std::string_view str) { UpdateData(reinterpret_cast<uint8 const*>(str.data()), str.size()); }
|
||||
void UpdateData(std::string const& str) { UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
|
||||
void UpdateData(char const* str) { UpdateData(std::string_view(str)); } /* explicit overload to avoid using the container template */
|
||||
template <typename Container>
|
||||
void UpdateData(Container const& c) { UpdateData(advstd::data(c), advstd::size(c)); }
|
||||
void UpdateData(Container const& c) { UpdateData(std::data(c), std::size(c)); }
|
||||
|
||||
void Finalize()
|
||||
{
|
||||
@@ -139,15 +121,10 @@ namespace Impl
|
||||
Digest _digest = { };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
namespace Crypto
|
||||
namespace Trinity::Crypto
|
||||
{
|
||||
using HMAC_SHA1 = Trinity::Impl::GenericHMAC<EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES>;
|
||||
using HMAC_SHA256 = Trinity::Impl::GenericHMAC<EVP_sha256, Constants::SHA256_DIGEST_LENGTH_BYTES>;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -133,35 +133,6 @@ namespace advstd
|
||||
// C++20 std::remove_cvref_t
|
||||
template <class T>
|
||||
using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
|
||||
template<typename B>
|
||||
struct negation : std::integral_constant<bool, !bool(B::value)> { };
|
||||
|
||||
template <typename...>
|
||||
struct conjunction : std::true_type { };
|
||||
template <typename B1>
|
||||
struct conjunction<B1> : B1 { };
|
||||
template <typename B1, class... Bn>
|
||||
struct conjunction<B1, Bn...> : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> { };
|
||||
|
||||
template <typename...>
|
||||
struct disjunction : std::false_type { };
|
||||
template <typename B1>
|
||||
struct disjunction<B1> : B1 { };
|
||||
template <typename B1, class... Bn>
|
||||
struct disjunction<B1, Bn...> : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> { };
|
||||
|
||||
template <class T>
|
||||
constexpr T const& clamp(T const& val, T const& lo, T const& hi)
|
||||
{
|
||||
if (hi < val)
|
||||
return hi;
|
||||
|
||||
if (val < lo)
|
||||
return lo;
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "Timer.h"
|
||||
#include "Util.h"
|
||||
#include "World.h"
|
||||
#include "advstd.h"
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <array>
|
||||
#include <bitset>
|
||||
@@ -1998,12 +1997,12 @@ Optional<ContentTuningLevels> DB2Manager::GetContentTuningData(uint32 contentTun
|
||||
ContentTuningLevels levels;
|
||||
levels.MinLevel = contentTuning->MinLevel + getLevelAdjustment(static_cast<ContentTuningCalcType>(contentTuning->MinLevelType));
|
||||
levels.MaxLevel = contentTuning->MaxLevel + getLevelAdjustment(static_cast<ContentTuningCalcType>(contentTuning->MaxLevelType));
|
||||
levels.MinLevelWithDelta = advstd::clamp<int32>(levels.MinLevel + contentTuning->TargetLevelDelta, 1, MAX_LEVEL);
|
||||
levels.MaxLevelWithDelta = advstd::clamp<int32>(levels.MaxLevel + contentTuning->TargetLevelMaxDelta, 1, MAX_LEVEL);
|
||||
levels.MinLevelWithDelta = std::clamp<int32>(levels.MinLevel + contentTuning->TargetLevelDelta, 1, MAX_LEVEL);
|
||||
levels.MaxLevelWithDelta = std::clamp<int32>(levels.MaxLevel + contentTuning->TargetLevelMaxDelta, 1, MAX_LEVEL);
|
||||
|
||||
// clamp after calculating levels with delta (delta can bring "overflown" level back into correct range)
|
||||
levels.MinLevel = advstd::clamp<int32>(levels.MinLevel, 1, MAX_LEVEL);
|
||||
levels.MaxLevel = advstd::clamp<int32>(levels.MaxLevel, 1, MAX_LEVEL);
|
||||
levels.MinLevel = std::clamp<int32>(levels.MinLevel, 1, MAX_LEVEL);
|
||||
levels.MaxLevel = std::clamp<int32>(levels.MaxLevel, 1, MAX_LEVEL);
|
||||
|
||||
if (contentTuning->TargetLevelMin)
|
||||
levels.TargetLevelMin = contentTuning->TargetLevelMin;
|
||||
|
||||
@@ -1449,7 +1449,7 @@ uint8 GameObject::GetLevelForTarget(WorldObject const* target) const
|
||||
{
|
||||
if (Player const* player = target->ToPlayer())
|
||||
if (Optional<ContentTuningLevels> userLevels = sDB2Manager.GetContentTuningData(GetGOInfo()->ContentTuningId, player->m_playerData->CtrOptions->ContentTuningConditionMask))
|
||||
return uint8(advstd::clamp<int16>(player->GetLevel(), userLevels->MinLevel, userLevels->MaxLevel));
|
||||
return uint8(std::clamp<int16>(player->GetLevel(), userLevels->MinLevel, userLevels->MaxLevel));
|
||||
|
||||
if (Unit const* targetUnit = target->ToUnit())
|
||||
return targetUnit->GetLevel();
|
||||
|
||||
@@ -17051,7 +17051,7 @@ void Player::UpdateQuestObjectiveProgress(QuestObjectiveType objectiveType, int3
|
||||
int32 currentProgress = GetQuestSlotObjectiveData(logSlot, objective);
|
||||
if (addCount > 0 ? (currentProgress < objective.Amount) : (currentProgress > 0))
|
||||
{
|
||||
int32 newProgress = advstd::clamp<int32>(currentProgress + addCount, 0, objective.Amount);
|
||||
int32 newProgress = std::clamp<int32>(currentProgress + addCount, 0, objective.Amount);
|
||||
SetQuestObjectiveData(objective, newProgress);
|
||||
if (addCount > 0 && !(objective.Flags & QUEST_OBJECTIVE_FLAG_HIDE_CREDIT_MSG))
|
||||
{
|
||||
|
||||
@@ -9749,10 +9749,9 @@ ObjectMgr::ScriptNameContainer::ScriptNameContainer()
|
||||
{
|
||||
// We insert an empty placeholder here so we can use the
|
||||
// script id 0 as dummy for "no script found".
|
||||
uint32 const id = insert("", false);
|
||||
[[maybe_unused]] uint32 const id = insert("", false);
|
||||
|
||||
ASSERT(id == 0);
|
||||
(void)id;
|
||||
}
|
||||
|
||||
void ObjectMgr::ScriptNameContainer::reserve(size_t capacity)
|
||||
@@ -9762,22 +9761,14 @@ void ObjectMgr::ScriptNameContainer::reserve(size_t capacity)
|
||||
|
||||
uint32 ObjectMgr::ScriptNameContainer::insert(std::string const& scriptName, bool isScriptNameBound)
|
||||
{
|
||||
// c++17 try_emplace
|
||||
auto const itr = NameToIndex.find(scriptName);
|
||||
if (itr != NameToIndex.end())
|
||||
auto result = NameToIndex.try_emplace(scriptName, static_cast<uint32>(NameToIndex.size()), isScriptNameBound);
|
||||
if (result.second)
|
||||
{
|
||||
return itr->second.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(NameToIndex.size() < std::numeric_limits<uint32>::max());
|
||||
uint32 const id = static_cast<uint32>(NameToIndex.size());
|
||||
|
||||
auto result = NameToIndex.insert({ scriptName, Entry{ id, isScriptNameBound } });
|
||||
ASSERT(NameToIndex.size() <= std::numeric_limits<uint32>::max());
|
||||
IndexToName.emplace_back(result.first);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
return result.first->second.Id;
|
||||
}
|
||||
|
||||
size_t ObjectMgr::ScriptNameContainer::size() const
|
||||
|
||||
@@ -1084,8 +1084,11 @@ class TC_GAME_API ObjectMgr
|
||||
public:
|
||||
struct Entry
|
||||
{
|
||||
uint32 Id;
|
||||
bool IsScriptDatabaseBound;
|
||||
Entry() = default;
|
||||
Entry(uint32 id, bool isScriptDatabaseBound) : Id(id), IsScriptDatabaseBound(isScriptDatabaseBound) { }
|
||||
|
||||
uint32 Id = 0;
|
||||
bool IsScriptDatabaseBound = false;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "MoveSpline.h"
|
||||
#include "MoveSplineInit.h"
|
||||
#include "Unit.h"
|
||||
#include "advstd.h"
|
||||
|
||||
IdleMovementGenerator::IdleMovementGenerator()
|
||||
{
|
||||
@@ -101,7 +100,7 @@ bool RotateMovementGenerator::Update(Unit* owner, uint32 diff)
|
||||
|
||||
float angle = owner->GetOrientation();
|
||||
angle += (float(diff) * static_cast<float>(M_PI * 2) / _maxDuration) * (_direction == ROTATE_DIRECTION_LEFT ? 1.0f : -1.0f);
|
||||
angle = advstd::clamp(angle, 0.0f, static_cast<float>(M_PI * 2));
|
||||
angle = std::clamp(angle, 0.0f, static_cast<float>(M_PI * 2));
|
||||
|
||||
Movement::MoveSplineInit init(owner);
|
||||
init.MoveTo(PositionToVector3(*owner), false);
|
||||
|
||||
Reference in New Issue
Block a user