From: Fred Morcos Date: Wed, 16 Oct 2024 13:49:30 +0000 (+0200) Subject: Cleanup TypedDBI X-Git-Tag: rec-5.2.0-alpha1~26^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c84d5b50caf0324b2224d7c9124f6e1438fb9b5d;p=thirdparty%2Fpdns.git Cleanup TypedDBI --- diff --git a/ext/lmdb-safe/lmdb-typed.hh b/ext/lmdb-safe/lmdb-typed.hh index c6e95dbac7..be5608f718 100644 --- a/ext/lmdb-safe/lmdb-typed.hh +++ b/ext/lmdb-safe/lmdb-typed.hh @@ -224,30 +224,31 @@ struct nullindex_t }; /** The main class. Templatized only on the indexes and typename right now */ -template +template class TypedDBI { + // we get a lot of our smarts from this tuple, it enables get<0> etc + using tuple_t = std::tuple; + tuple_t d_tuple; + +private: + template + auto openDB(string_view& name) + { + std::get(d_tuple).openDB(d_env, std::string(name) + "_" + std::to_string(N), MDB_CREATE); + } + public: - TypedDBI(std::shared_ptr env, string_view name) - : d_env(std::move(env)), d_name(name) + TypedDBI(std::shared_ptr env, string_view name) : + d_env(std::move(env)), d_name(name) { d_main = d_env->openDB(name, MDB_CREATE); - - // now you might be tempted to go all MPL on this so we can get rid of the - // ugly macro. I'm not very receptive to that idea since it will make things - // EVEN uglier. -#define openMacro(N) std::get(d_tuple).openDB(d_env, std::string(name)+"_"#N, MDB_CREATE); - openMacro(0); - openMacro(1); - openMacro(2); - openMacro(3); -#undef openMacro + openDB<0>(name); + openDB<1>(name); + openDB<2>(name); + openDB<3>(name); } - // we get a lot of our smarts from this tuple, it enables get<0> etc - using tuple_t = std::tuple; - tuple_t d_tuple; - // We support readonly and rw transactions. Here we put the Readonly operations // which get sourced by both kinds of transactions template