Use Arbutils exception Macros, instead of own ones.
All checks were successful
continuous-integration/drone/push Build is passing

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
2020-08-17 12:18:01 +02:00
parent 9d5316edff
commit 98dacbccde
20 changed files with 44 additions and 60 deletions

View File

@@ -27,7 +27,7 @@ namespace CreatureLib::Library {
inline bool HasAttacksForLevel(uint8_t level) const noexcept { return _learnedByLevel.Has(level); }
inline const ArbUt::List<ArbUt::BorrowedPtr<const AttackData>>& GetAttacksForLevel(uint8_t level) const {
if (!_learnedByLevel.Has(level)) {
THROW_CREATURE("No attacks found for level " << (uint32_t)level << ".");
THROW("No attacks found for level " << (uint32_t)level << ".");
}
return _learnedByLevel.Get(level);
}

View File

@@ -13,5 +13,5 @@ CreatureLib::Library::SpeciesVariant::GetTalentIndex(const ArbUt::StringView& ta
return TalentIndex(true, i);
}
}
THROW_CREATURE("The given talent is not a valid talent for this creature.");
THROW("The given talent is not a valid talent for this creature.");
}

View File

@@ -25,7 +25,7 @@ namespace CreatureLib::Library {
inline EffectParameterType GetType() const noexcept { return _type; }
bool AsBool() const {
if (_type != EffectParameterType::Bool) {
THROW_CREATURE("Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type));
THROW("Cast effect parameter to bool, but was " << EffectParameterTypeHelper::ToString(_type));
}
return std::get<bool>(_value);
}
@@ -34,7 +34,7 @@ namespace CreatureLib::Library {
if (_type == EffectParameterType::Float) {
return static_cast<int64_t>(std::get<float>(_value));
}
THROW_CREATURE("Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type));
THROW("Cast effect parameter to int, but was " << EffectParameterTypeHelper::ToString(_type));
}
return std::get<int64_t>(_value);
}
@@ -43,15 +43,13 @@ namespace CreatureLib::Library {
if (_type == EffectParameterType::Int) {
return static_cast<float>(std::get<int64_t>(_value));
}
THROW_CREATURE("Cast effect parameter to float, but was "
<< EffectParameterTypeHelper::ToString(_type));
THROW("Cast effect parameter to float, but was " << EffectParameterTypeHelper::ToString(_type));
}
return std::get<float>(_value);
}
const ArbUt::StringView& AsString() const {
if (_type != EffectParameterType::String) {
THROW_CREATURE("Cast effect parameter to string, but was "
<< EffectParameterTypeHelper::ToString(_type));
THROW("Cast effect parameter to string, but was " << EffectParameterTypeHelper::ToString(_type));
}
return std::get<ArbUt::StringView>(_value);
}

View File

@@ -2,18 +2,6 @@
#define CREATURELIB_CREATUREEXCEPTION_HPP
#include <Arbutils/Exception.hpp>
#include <cstring>
#include <sstream>
#include <stdexcept>
#include <string>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define THROW_CREATURE(message) \
std::stringstream ___ss; \
___ss << "[" << __FILENAME__ << ":" << __LINE__ << "] " << message; \
throw ArbUt::Exception(___ss.str());
#define NOT_REACHABLE THROW_CREATURE("Not reachable");
#define NOT_IMPLEMENTED THROW_CREATURE("Not implemented");
#define try_creature(data, msg) \
try { \
@@ -21,6 +9,6 @@
} catch (const ArbUt::Exception& e) { \
throw e; \
} catch (const std::exception& e) { \
THROW_CREATURE(msg << ": '" << e.what() << "'."); \
THROW(msg << ": '" << e.what() << "'."); \
}
#endif // CREATURELIB_CREATUREEXCEPTION_HPP

View File

@@ -5,7 +5,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::Bas
uint32_t experience) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
THROW_CREATURE("Invalid growth rate was requested.");
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateLevel(experience);
}
@@ -13,7 +13,7 @@ uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const ArbUt::Bas
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(uint32_t hash, uint32_t experience) const {
auto find = _growthRates.find(hash);
if (find == _growthRates.end()) {
THROW_CREATURE("Invalid growth rate was requested.");
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateLevel(experience);
}
@@ -22,7 +22,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU
uint8_t level) const {
auto find = _growthRates.find(growthRate);
if (find == _growthRates.end()) {
THROW_CREATURE("Invalid growth rate was requested.");
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateExperience(level);
}
@@ -30,7 +30,7 @@ uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const ArbU
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(uint32_t hash, uint8_t level) const {
auto find = _growthRates.find(hash);
if (find == _growthRates.end()) {
THROW_CREATURE("Invalid growth rate was requested.");
THROW("Invalid growth rate was requested.");
}
return find->second->CalculateExperience(level);
}

View File

@@ -21,5 +21,5 @@ const ArbUt::StringView& TypeLibrary::GetTypeName(uint8_t type) const {
return kv.first;
}
}
THROW_CREATURE("Name requested for unknown type: " << (uint32_t)type);
THROW("Name requested for unknown type: " << (uint32_t)type);
}

View File

@@ -23,8 +23,8 @@ namespace CreatureLib::Library {
try {
return _effectiveness[attacking][defensive];
} catch (const std::exception& e) {
THROW_CREATURE("Unknown type indices were requested for effectiveness: "
<< (uint32_t)attacking << " and " << (uint32_t)defensive);
THROW("Unknown type indices were requested for effectiveness: " << (uint32_t)attacking << " and "
<< (uint32_t)defensive);
}
}
[[nodiscard]] inline float GetEffectiveness(uint8_t attacking,