-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.cpp
33 lines (26 loc) · 947 Bytes
/
error.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "error.hpp"
#include <atomic>
#include <sstream>
namespace sid = Poonam::string_id;
namespace {
std::string format(sid::hash_type hash, const char* a, const char* b) {
std::ostringstream str;
str << "Poonam::string_id::collision_error: strings "
<< a << "and " << b << "are both producing same value " << hash;
return str.str();
}
void default_collision_handler(sid::hash_type hash, const char* a, const char* b) {
throw sid::collision_error(hash,a,b);
}
//register our default handler as an atomic operation
std::atomic<sid::collision_handler> handler(default_collision_handler);
}
sid::collision_error::collision_error(sid::hash_type hash, const char* a, const char* b)
: logic_error(format(hash,a,b)), a_(a), b_(b), hash_(hash)
{}
sid::collision_handler sid::set_collision_handler(collision_handler h) {
return handler.exchange(h);
}
sid::collision_handler sid::get_collision_handler() {
return handler;
}