-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadb.h
77 lines (59 loc) · 2.19 KB
/
adb.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* COPYRIGHT 2014 (C) Jason Volk
* COPYRIGHT 2014 (C) Svetlana Tkachenko
*
* DISTRIBUTED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) (see: LICENSE)
*/
class Adb
{
std::unique_ptr<stldb::ldb<std::string,std::string>> ldb;
public:
template<class... A> auto cbegin(A&&... a) const { return ldb->begin(std::forward<A>(a)...); }
template<class... A> auto begin(A&&... a) const { return ldb->begin(std::forward<A>(a)...); }
template<class... A> auto begin(A&&... a) { return ldb->begin(std::forward<A>(a)...); }
template<class... A> auto cend(A&&... a) const { return ldb->end(std::forward<A>(a)...); }
template<class... A> auto end(A&&... a) const { return ldb->end(std::forward<A>(a)...); }
template<class... A> auto end(A&&... a) { return ldb->end(std::forward<A>(a)...); }
bool exists(const std::string &name) const { return ldb->count(name); }
auto count() const { return ldb->size(); }
Adoc get(const std::nothrow_t, const std::string &name) const noexcept;
Adoc get(const std::nothrow_t, const std::string &name) noexcept;
Adoc get(const std::string &name) const;
Adoc get(const std::string &name);
void set(const std::string &name, const Adoc &data) { ldb->insert(name,data); }
Adb(const std::string &dir);
};
inline
Adb::Adb(const std::string &dir):
ldb(!dir.empty()? std::make_unique<decltype(ldb)::element_type>(dir) : nullptr)
{
}
inline
Adoc Adb::get(const std::string &name)
{
const auto it(ldb->find(name));
return it? Adoc{std::string{it->second}} : throw Exception("Account not found");
}
inline
Adoc Adb::get(const std::string &name)
const
{
const auto it(ldb->find(name));
return it? Adoc{std::string{it->second}} : throw Exception("Account not found");
}
inline
Adoc Adb::get(const std::nothrow_t,
const std::string &name)
noexcept
{
const auto it = ldb->find(name);
return it? Adoc{std::string{it->second}} : Adoc{};
}
inline
Adoc Adb::get(const std::nothrow_t,
const std::string &name)
const noexcept
{
const auto it = ldb->find(name);
return it? Adoc{std::string{it->second}} : Adoc{};
}