COMMON: Include the not found key in the error message

This commit is contained in:
Henrik "Henke37" Andersson 2020-10-20 15:50:21 +02:00 committed by Eugene Sandulenko
parent 9b30f4a73d
commit 0caeac64aa
2 changed files with 71 additions and 2 deletions

View File

@ -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,

View File

@ -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 <class Key>
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<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) {
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
else
error("Unknown key");
unknownKeyError(key);
}
template<class Key, class Val, class HashFunc, class EqualFunc>
@ -613,7 +641,7 @@ const Val &HashMap<Key, Val, HashFunc, EqualFunc>::getVal(const Key &key) const
if (_storage[ctr] != nullptr)
return _storage[ctr]->_value;
else
error("Unknown key");
unknownKeyError(key);
}
template<class Key, class Val, class HashFunc, class EqualFunc>