lay it out a bit better
[ghsmtp.git] / CDB.hpp
blob7c814d05f391fafab57bcf33de7bfb71a408c765
1 #ifndef CDB_DOT_HPP
2 #define CDB_DOT_HPP
4 #include <memory>
5 #include <optional>
6 #include <string>
7 #include <string_view>
9 extern "C" {
10 #include <cdb.h>
13 #include "fs.hpp"
15 class CDB {
16 public:
17 CDB(CDB const&) = delete;
18 CDB& operator=(CDB const&) = delete;
20 CDB() = default;
21 explicit CDB(fs::path db) { open(db); }
22 ~CDB();
24 bool open(fs::path db);
25 std::optional<std::string> find(std::string_view key);
26 bool contains(std::string_view key);
27 constexpr bool is_open() const;
29 private:
30 int fd_{-1};
31 cdb cdb_{0};
34 constexpr bool CDB::is_open() const { return fd_ != -1; }
36 #endif // CDB_DOT_HPP