aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/DB.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-07 18:57:04 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-07 18:57:04 +0100
commit9df087ede0b539ecbd2778236c7d1143362b384d (patch)
tree01a1c0c46da3a09137fcb9ca6e613fd1148f4df1 /src/crepe/facade/DB.h
parente36ea050972fcaaf3d85d672755bad4ebb2dcd80 (diff)
check code standard
Diffstat (limited to 'src/crepe/facade/DB.h')
-rw-r--r--src/crepe/facade/DB.h43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/crepe/facade/DB.h b/src/crepe/facade/DB.h
index 06442ad..b62a974 100644
--- a/src/crepe/facade/DB.h
+++ b/src/crepe/facade/DB.h
@@ -12,22 +12,63 @@ extern "C" {
namespace crepe {
+/**
+ * \brief Berkeley DB facade
+ *
+ * Berkeley DB is a simple key-value database that stores arbitrary data as
+ * both key and value. This facade uses STL strings as keys/values.
+ */
class DB {
public:
+ /**
+ * \param path The path of the database (created if nonexistant)
+ */
DB(const std::string & path);
virtual ~DB() = default;
public:
+ /**
+ * \brief Get a value from the database, or throw an exception
+ *
+ * \param key The value key
+ *
+ * \return The value
+ *
+ * \throws Exception if value is not found in DB or other error occurs
+ */
std::string get(const std::string & key);
+ /**
+ * \brief Set (create or overwrite) a value in the database
+ *
+ * \param key The value key
+ * \param value The value to store
+ *
+ * \throws Exception if an error occurs
+ */
void set(const std::string & key, const std::string & value);
+ /**
+ * \brief Check if a key exists in the database
+ *
+ * \param key The value key
+ *
+ * \returns True if the key exists, or false if it does not
+ */
bool has(const std::string & key) noexcept;
private:
+ //! RAII wrapper around \c DB struct
std::unique_ptr<libdb::DB, std::function<void(libdb::DB *)>> db;
+ //! RAII wrapper around \c DBC struct
std::unique_ptr<libdb::DBC, std::function<void(libdb::DBC *)>> cursor;
private:
- libdb::DBT to_thing(const std::string & thing) const;
+ /**
+ * \brief Convert an STL string to DBT (data base thang)
+ *
+ * \param thing Input data
+ * \return \c DBT with the same data as input \c thing
+ */
+ libdb::DBT to_thing(const std::string & thing) const noexcept;
};
}