diff --git a/common/hashmap.cpp b/common/hashmap.cpp index e9eac9fc94c..ce03c6bdb58 100644 --- a/common/hashmap.cpp +++ b/common/hashmap.cpp @@ -52,6 +52,47 @@ uint hashit_lower(const char *p) { return hash ^ size; } + +template<> void unknownKeyError(::Common::String key) { + error("Unknown key \"%s\"", key.c_str()); +} + +template<> void unknownKeyError(signed char key) { + error("Unknown key \"%hhi\"", key); +} + +template<> void unknownKeyError(unsigned char key) { + error("Unknown key \"%hhu\"", key); +} + +template<> void unknownKeyError(short signed key) { + error("Unknown key \"%hi\"", key); +} + +template<> void unknownKeyError(short unsigned key) { + error("Unknown key \"%hu\"", key); +} + +template<> void unknownKeyError(long signed key) { + error("Unknown key \"%li\"", key); +} + +template<> void unknownKeyError(long unsigned key) { + error("Unknown key \"%lu\"", key); +} + +template<> void unknownKeyError(long long signed key) { + error("Unknown key \"%lli\"", key); +} + +template<> void unknownKeyError(long long unsigned key) { + error("Unknown key \"%llu\"", key); +} + +template<> void unknownKeyError(void *key) { + error("Unknown key \"%p\"", key); +} + #ifdef DEBUG_HASH_COLLISIONS static double g_collisions = 0, diff --git a/common/hashmap.h b/common/hashmap.h index 8e96dcd7da2..7d94adc2d28 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -42,6 +42,8 @@ #include "common/func.h" +#include "common/str.h" + #ifdef DEBUG_HASH_COLLISIONS #include "common/debug.h" #endif @@ -304,6 +306,32 @@ public: } }; +template +void NORETURN_PRE unknownKeyError(Key k) NORETURN_POST { + error("Unknown key"); +} + +template<> +void NORETURN_PRE unknownKeyError(::Common::String key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(signed char key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(unsigned char key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(short signed key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(short unsigned key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(long signed key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(long unsigned key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(long long signed key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(long long unsigned key) NORETURN_POST; +template<> +void NORETURN_PRE unknownKeyError(void *key) NORETURN_POST; + //------------------------------------------------------- // HashMap functions @@ -604,7 +632,7 @@ Val &HashMap::getVal(const Key &key) { if (_storage[ctr] != nullptr) return _storage[ctr]->_value; else - error("Unknown key"); + unknownKeyError(key); } template @@ -613,7 +641,7 @@ const Val &HashMap::getVal(const Key &key) const if (_storage[ctr] != nullptr) return _storage[ctr]->_value; else - error("Unknown key"); + unknownKeyError(key); } template