-rw-r--r-- | include/konforka/pqxx_pile.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/include/konforka/pqxx_pile.h b/include/konforka/pqxx_pile.h new file mode 100644 index 0000000..fdfaed6 --- a/dev/null +++ b/include/konforka/pqxx_pile.h | |||
@@ -0,0 +1,59 @@ | |||
1 | #ifndef __KONFORKA_PQXX_PILE_H | ||
2 | #define __KONFORKA_PQXX_PILE_H | ||
3 | |||
4 | #include <pqxx/connection> | ||
5 | #include <konforka/resource_pile.h> | ||
6 | |||
7 | /** | ||
8 | * @file | ||
9 | * @brief libpqxx-based postgresql connections pile. | ||
10 | */ | ||
11 | |||
12 | namespace konforka { | ||
13 | |||
14 | /** | ||
15 | * @brief the base for pqxx-based connection classes. | ||
16 | * | ||
17 | * @param pqxxc_t the type of libpqxx connection (pqxx::connection, | ||
18 | * pqxx::lazyconnection or pqxx::asyncconnection). | ||
19 | */ | ||
20 | template<typename pqxxc_t> | ||
21 | class pqxx_piled_connection_base : public resource_pile_base<string,pqxxc_t*, resource_pile_generic_ptr_factory<string,pqxxc_t> > { | ||
22 | public: | ||
23 | /** | ||
24 | * @brief the constractor based on connection info. | ||
25 | * | ||
26 | * @param ci connection info string. | ||
27 | */ | ||
28 | pqxx_piled_connection_base(const string& ci) | ||
29 | : resource_pile_base<string,pqxxc_t*, resource_pile_generic_ptr_factory<string,pqxxc_t> >(ci) { } | ||
30 | ~pqxx_piled_connection_base() { this->drop(); } | ||
31 | |||
32 | /** | ||
33 | * @brief cast the object to the reference to the corresponding | ||
34 | * libpqxx type. | ||
35 | */ | ||
36 | operator pqxxc_t&(void) { return *this->get_content(); } | ||
37 | /** | ||
38 | * @brief cast the object to the const reference to the | ||
39 | * corresponding libpqxx type. | ||
40 | */ | ||
41 | operator const pqxxc_t&(void) const { return *this->get_content(); } | ||
42 | }; | ||
43 | |||
44 | /** | ||
45 | * @brief the implementation for piling pqxx::connection objects. | ||
46 | */ | ||
47 | typedef pqxx_piled_connection_base<pqxx::connection> pqxx_piled_connection; | ||
48 | /** | ||
49 | * @brief the implementation for piling pqxx::lazyconnection objects. | ||
50 | */ | ||
51 | typedef pqxx_piled_connection_base<pqxx::lazyconnection> pqxx_piled_lazy_connection; | ||
52 | /** | ||
53 | * @brief the implementation for piling pqxx::asyncconnection objects. | ||
54 | */ | ||
55 | typedef pqxx_piled_connection_base<pqxx::asyncconnection> pqxx_piled_async_connection; | ||
56 | } | ||
57 | |||
58 | #endif /* __KONFORKA_PQXX_PILE_H */ | ||
59 | /* vim:set ft=cpp: */ | ||