-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommon.hh
61 lines (53 loc) · 1.44 KB
/
Common.hh
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef _COMMON_HH_
#define _COMMON_HH_
#include <stdexcept>
#include <memory>
#include <string>
#include <sstream>
#include <map>
#include <list>
namespace Common
{
// @ todo rename to NamedVal
typedef std::multimap<std::string, std::string> KeyVals;
class Error
{
public:
static void err(const char* func,
const std::string& message,
const char* name = 0) {
std::stringstream ss;
ss << func << ": " << message << ": " << (name == 0 ? "" : name);
throw std::runtime_error(ss.str());
}
};
class Qname
{
public:
Qname(const std::string* prefix, const std::string* suffix) :
_prefix(prefix),
_suffix(suffix) {}
const std::string* getPrefix() const {
return _prefix.get();
}
const std::string& getSuffix() const {
return *(_suffix.get());
}
const std::string getString() const {
std::string result;
if (_prefix.get() != 0) {
result += *_prefix;
result += ":";
}
result += *_suffix;
return result;
}
private:
std::unique_ptr<const std::string> _prefix;
std::unique_ptr<const std::string> _suffix;
};
typedef std::list<const Common::Qname*> Qnames;
}
#define YDB_ERROR(e) Common::Error::err(__PRETTY_FUNCTION__, e)
#define YDB_N_ERROR(e, n) Common::Error::err(__PRETTY_FUNCTION__, e, n)
#endif