aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2021-12-21 18:29:52 +0100
committerShauren <shauren.trinity@gmail.com>2021-12-21 18:29:52 +0100
commit2c78f4dd1f52200e7061b809bb472dbcd499962e (patch)
tree14a87d6d9eff90ea9e0e298eb532241da0fcc804
parent6229a6ddc11be7409646a8ac99a5ecaf1b8d37d9 (diff)
Core/Misc: Resolve c++17 TODOs left in code as comments
-rw-r--r--src/common/Cryptography/CryptoHash.h41
-rw-r--r--src/common/Cryptography/HMAC.h43
-rw-r--r--src/common/Utilities/advstd.h29
-rw-r--r--src/server/game/DataStores/DB2Stores.cpp9
-rw-r--r--src/server/game/Entities/GameObject/GameObject.cpp2
-rw-r--r--src/server/game/Entities/Player/Player.cpp2
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp21
-rw-r--r--src/server/game/Globals/ObjectMgr.h7
-rw-r--r--src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp3
9 files changed, 37 insertions, 120 deletions
diff --git a/src/common/Cryptography/CryptoHash.h b/src/common/Cryptography/CryptoHash.h
index 991bf15944e..8e6f2b32394 100644
--- a/src/common/Cryptography/CryptoHash.h
+++ b/src/common/Cryptography/CryptoHash.h
@@ -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
diff --git a/src/common/Cryptography/HMAC.h b/src/common/Cryptography/HMAC.h
index 6b9d2a081bd..7925fb23a61 100644
--- a/src/common/Cryptography/HMAC.h
+++ b/src/common/Cryptography/HMAC.h
@@ -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
diff --git a/src/common/Utilities/advstd.h b/src/common/Utilities/advstd.h
index 975fc2c85ad..a39e0baadc1 100644
--- a/src/common/Utilities/advstd.h
+++ b/src/common/Utilities/advstd.h
@@ -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
diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp
index 21780c9935c..5ab19d417db 100644
--- a/src/server/game/DataStores/DB2Stores.cpp
+++ b/src/server/game/DataStores/DB2Stores.cpp
@@ -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;
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp
index 2481de2880f..5ebae457a1d 100644
--- a/src/server/game/Entities/GameObject/GameObject.cpp
+++ b/src/server/game/Entities/GameObject/GameObject.cpp
@@ -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();
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 49a087f09aa..973cd882b9c 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -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))
{
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 289437620e1..1ad91d8f9c2 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -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
diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index 54a97fa6bbe..86d463337e8 100644
--- a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -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:
diff --git a/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp
index 48456ea0eb9..08d32016438 100644
--- a/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/IdleMovementGenerator.cpp
@@ -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);