diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-08 11:36:39 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-08 11:36:39 +0100 |
commit | bf177644dc5de58791eb80b11af9d6b4877b0a24 (patch) | |
tree | d85656633677397152dae729e7ec67069c13ec3e /src/crepe/facade | |
parent | 1c4156ee127b14760ed3b1a0cd16ad12180c7ac6 (diff) |
`make format`
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/DB.cpp | 20 | ||||
-rw-r--r-- | src/crepe/facade/DB.h | 7 |
2 files changed, 12 insertions, 15 deletions
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp index c885560..0a2f455 100644 --- a/src/crepe/facade/DB.cpp +++ b/src/crepe/facade/DB.cpp @@ -1,7 +1,7 @@ #include <cstring> -#include "util/log.h" #include "Exception.h" +#include "util/log.h" #include "DB.h" @@ -16,20 +16,21 @@ DB::DB(const string & path) { libdb::DB * db; if ((ret = libdb::db_create(&db, NULL, 0)) != 0) throw Exception("db_create: %s", libdb::db_strerror(ret)); - this->db = { db, [] (libdb::DB * db) { db->close(db, 0); } }; + this->db = {db, [](libdb::DB * db) { db->close(db, 0); }}; // load or create database file - if ((ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, libdb::DB_BTREE, DB_CREATE, 0)) != 0) + if ((ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL, + libdb::DB_BTREE, DB_CREATE, 0)) + != 0) throw Exception("db->open: %s", libdb::db_strerror(ret)); // create cursor libdb::DBC * cursor; if ((ret = this->db->cursor(this->db.get(), NULL, &cursor, 0)) != 0) throw Exception("db->cursor: %s", libdb::db_strerror(ret)); - this->cursor = { cursor, [] (libdb::DBC * cursor) { cursor->close(cursor); } }; + this->cursor = {cursor, [](libdb::DBC * cursor) { cursor->close(cursor); }}; } - libdb::DBT DB::to_thing(const string & thing) const noexcept { libdb::DBT thang; memset(&thang, 0, sizeof(libdb::DBT)); @@ -44,17 +45,15 @@ string DB::get(const string & key) { memset(&db_val, 0, sizeof(libdb::DBT)); int ret = this->cursor->get(this->cursor.get(), &db_key, &db_val, DB_FIRST); - if (ret != 0) - throw Exception("cursor->get: %s", libdb::db_strerror(ret)); - return { static_cast<char *>(db_val.data), db_val.size }; + if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret)); + return {static_cast<char *>(db_val.data), db_val.size}; } void DB::set(const string & key, const string & value) { libdb::DBT db_key = this->to_thing(key); libdb::DBT db_val = this->to_thing(value); int ret = this->db->put(this->db.get(), NULL, &db_key, &db_val, 0); - if (ret != 0) - throw Exception("cursor->get: %s", libdb::db_strerror(ret)); + if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret)); } bool DB::has(const std::string & key) noexcept { @@ -65,4 +64,3 @@ bool DB::has(const std::string & key) noexcept { } return true; } - diff --git a/src/crepe/facade/DB.h b/src/crepe/facade/DB.h index b62a974..7c757a2 100644 --- a/src/crepe/facade/DB.h +++ b/src/crepe/facade/DB.h @@ -1,14 +1,14 @@ #pragma once -#include <string> #include <functional> #include <memory> +#include <string> namespace libdb { extern "C" { #include <db.h> } -} +} // namespace libdb namespace crepe { @@ -71,5 +71,4 @@ private: libdb::DBT to_thing(const std::string & thing) const noexcept; }; -} - +} // namespace crepe |