aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-08 11:36:39 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-08 11:36:39 +0100
commitbf177644dc5de58791eb80b11af9d6b4877b0a24 (patch)
treed85656633677397152dae729e7ec67069c13ec3e /src
parent1c4156ee127b14760ed3b1a0cd16ad12180c7ac6 (diff)
`make format`
Diffstat (limited to 'src')
-rw-r--r--src/crepe/Exception.cpp5
-rw-r--r--src/crepe/Exception.h3
-rw-r--r--src/crepe/ValueBroker.h7
-rw-r--r--src/crepe/ValueBroker.hpp10
-rw-r--r--src/crepe/api/Config.cpp1
-rw-r--r--src/crepe/api/Config.h6
-rw-r--r--src/crepe/api/SaveManager.cpp53
-rw-r--r--src/crepe/api/SaveManager.h7
-rw-r--r--src/crepe/facade/DB.cpp20
-rw-r--r--src/crepe/facade/DB.h7
-rw-r--r--src/crepe/util/Proxy.h7
-rw-r--r--src/crepe/util/Proxy.hpp9
-rw-r--r--src/example/db.cpp4
-rw-r--r--src/example/proxy.cpp20
-rw-r--r--src/example/savemgr.cpp13
15 files changed, 87 insertions, 85 deletions
diff --git a/src/crepe/Exception.cpp b/src/crepe/Exception.cpp
index f27d5a8..dab8f2e 100644
--- a/src/crepe/Exception.cpp
+++ b/src/crepe/Exception.cpp
@@ -6,9 +6,7 @@
using namespace std;
using namespace crepe;
-const char * Exception::what() {
- return error.c_str();
-}
+const char * Exception::what() { return error.c_str(); }
Exception::Exception(const char * fmt, ...) {
va_list args;
@@ -16,4 +14,3 @@ Exception::Exception(const char * fmt, ...) {
this->error = va_stringf(args, fmt);
va_end(args);
}
-
diff --git a/src/crepe/Exception.h b/src/crepe/Exception.h
index e4a7bb8..6473043 100644
--- a/src/crepe/Exception.h
+++ b/src/crepe/Exception.h
@@ -17,7 +17,6 @@ protected:
Exception() = default;
//! Formatted error message
std::string error;
-
};
-}
+} // namespace crepe
diff --git a/src/crepe/ValueBroker.h b/src/crepe/ValueBroker.h
index 88988b4..d844d6a 100644
--- a/src/crepe/ValueBroker.h
+++ b/src/crepe/ValueBroker.h
@@ -23,10 +23,12 @@ public:
virtual const T & get();
typedef std::function<void(const T & target)> setter_t;
- typedef std::function<const T & ()> getter_t;
+ typedef std::function<const T &()> getter_t;
+
private:
setter_t setter;
getter_t getter;
+
public:
/**
* \param setter Function that sets the variable
@@ -35,7 +37,6 @@ public:
ValueBroker(const setter_t & setter, const getter_t & getter);
};
-}
+} // namespace crepe
#include "ValueBroker.hpp"
-
diff --git a/src/crepe/ValueBroker.hpp b/src/crepe/ValueBroker.hpp
index 0d08333..927142f 100644
--- a/src/crepe/ValueBroker.hpp
+++ b/src/crepe/ValueBroker.hpp
@@ -5,11 +5,8 @@
namespace crepe {
template <typename T>
-ValueBroker<T>::ValueBroker(const setter_t & setter, const getter_t & getter) :
- setter(setter),
- getter(getter)
- {
-}
+ValueBroker<T>::ValueBroker(const setter_t & setter, const getter_t & getter)
+ : setter(setter), getter(getter) {}
template <typename T>
const T & ValueBroker<T>::get() {
@@ -21,5 +18,4 @@ void ValueBroker<T>::set(const T & value) {
this->setter(value);
}
-}
-
+} // namespace crepe
diff --git a/src/crepe/api/Config.cpp b/src/crepe/api/Config.cpp
index d6206da..0100bcc 100644
--- a/src/crepe/api/Config.cpp
+++ b/src/crepe/api/Config.cpp
@@ -6,4 +6,3 @@ Config & Config::get_instance() {
static Config instance;
return instance;
}
-
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index 56e3af5..8c9e643 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -7,6 +7,7 @@ namespace crepe {
class Config {
private:
Config() = default;
+
public:
~Config() = default;
@@ -16,8 +17,8 @@ public:
// singleton
Config(const Config &) = delete;
Config(Config &&) = delete;
- Config & operator = (const Config &) = delete;
- Config & operator = (Config &&) = delete;
+ Config & operator=(const Config &) = delete;
+ Config & operator=(Config &&) = delete;
public:
//! Logging-related settings
@@ -60,4 +61,3 @@ public:
};
} // namespace crepe
-
diff --git a/src/crepe/api/SaveManager.cpp b/src/crepe/api/SaveManager.cpp
index 23587e4..43276c5 100644
--- a/src/crepe/api/SaveManager.cpp
+++ b/src/crepe/api/SaveManager.cpp
@@ -2,8 +2,8 @@
#include "../util/log.h"
#include "Config.h"
-#include "ValueBroker.h"
#include "SaveManager.h"
+#include "ValueBroker.h"
using namespace std;
using namespace crepe;
@@ -65,17 +65,33 @@ string SaveManager::deserialize(const string & value) const noexcept {
return value;
}
-template <> uint8_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<uint64_t>(value); }
-template <> int8_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<int64_t>(value); }
-template <> uint16_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<uint64_t>(value); }
-template <> int16_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<int64_t>(value); }
-template <> uint32_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<uint64_t>(value); }
-template <> int32_t SaveManager::deserialize(const string & value) const noexcept { return deserialize<int64_t>(value); }
-
-SaveManager::SaveManager() {
- dbg_trace();
+template <>
+uint8_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<uint64_t>(value);
+}
+template <>
+int8_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<int64_t>(value);
+}
+template <>
+uint16_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<uint64_t>(value);
+}
+template <>
+int16_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<int64_t>(value);
+}
+template <>
+uint32_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<uint64_t>(value);
+}
+template <>
+int32_t SaveManager::deserialize(const string & value) const noexcept {
+ return deserialize<int64_t>(value);
}
+SaveManager::SaveManager() { dbg_trace(); }
+
SaveManager & SaveManager::get_instance() {
dbg_trace();
static SaveManager instance;
@@ -118,17 +134,19 @@ template void SaveManager::set(const string &, const double &);
template <typename T>
ValueBroker<T> SaveManager::get(const string & key, const T & default_value) {
- if (!this->has(key))
- this->set<T>(key, default_value);
+ if (!this->has(key)) this->set<T>(key, default_value);
return this->get<T>(key);
}
template ValueBroker<uint8_t> SaveManager::get(const string &, const uint8_t &);
template ValueBroker<int8_t> SaveManager::get(const string &, const int8_t &);
-template ValueBroker<uint16_t> SaveManager::get(const string &, const uint16_t &);
+template ValueBroker<uint16_t> SaveManager::get(const string &,
+ const uint16_t &);
template ValueBroker<int16_t> SaveManager::get(const string &, const int16_t &);
-template ValueBroker<uint32_t> SaveManager::get(const string &, const uint32_t &);
+template ValueBroker<uint32_t> SaveManager::get(const string &,
+ const uint32_t &);
template ValueBroker<int32_t> SaveManager::get(const string &, const int32_t &);
-template ValueBroker<uint64_t> SaveManager::get(const string &, const uint64_t &);
+template ValueBroker<uint64_t> SaveManager::get(const string &,
+ const uint64_t &);
template ValueBroker<int64_t> SaveManager::get(const string &, const int64_t &);
template ValueBroker<float> SaveManager::get(const string &, const float &);
template ValueBroker<double> SaveManager::get(const string &, const double &);
@@ -138,8 +156,8 @@ template <typename T>
ValueBroker<T> SaveManager::get(const string & key) {
T value;
return {
- [this, key] (const T & target) { this->set<T>(key, target); },
- [this, key, value] () mutable -> const T & {
+ [this, key](const T & target) { this->set<T>(key, target); },
+ [this, key, value]() mutable -> const T & {
value = this->deserialize<T>(this->get_db().get(key));
return value;
},
@@ -156,4 +174,3 @@ template ValueBroker<int64_t> SaveManager::get(const string &);
template ValueBroker<float> SaveManager::get(const string &);
template ValueBroker<double> SaveManager::get(const string &);
template ValueBroker<string> SaveManager::get(const string &);
-
diff --git a/src/crepe/api/SaveManager.h b/src/crepe/api/SaveManager.h
index 3073656..4be85fb 100644
--- a/src/crepe/api/SaveManager.h
+++ b/src/crepe/api/SaveManager.h
@@ -93,8 +93,8 @@ public:
static SaveManager & get_instance();
SaveManager(const SaveManager &) = delete;
SaveManager(SaveManager &&) = delete;
- SaveManager & operator = (const SaveManager &) = delete;
- SaveManager & operator = (SaveManager &&) = delete;
+ SaveManager & operator=(const SaveManager &) = delete;
+ SaveManager & operator=(SaveManager &&) = delete;
private:
/**
@@ -110,5 +110,4 @@ private:
static DB & get_db();
};
-}
-
+} // namespace crepe
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
diff --git a/src/crepe/util/Proxy.h b/src/crepe/util/Proxy.h
index fbfed0c..f84e462 100644
--- a/src/crepe/util/Proxy.h
+++ b/src/crepe/util/Proxy.h
@@ -16,9 +16,9 @@ template <typename T>
class Proxy {
public:
//! Set operator
- Proxy & operator = (const T &);
+ Proxy & operator=(const T &);
//! Get operator
- operator const T & ();
+ operator const T &();
public:
Proxy(ValueBroker<T>);
@@ -27,7 +27,6 @@ private:
ValueBroker<T> broker;
};
-}
+} // namespace crepe
#include "Proxy.hpp"
-
diff --git a/src/crepe/util/Proxy.hpp b/src/crepe/util/Proxy.hpp
index 4aec9e9..b9923db 100644
--- a/src/crepe/util/Proxy.hpp
+++ b/src/crepe/util/Proxy.hpp
@@ -5,18 +5,17 @@
namespace crepe {
template <typename T>
-Proxy<T>::Proxy(ValueBroker<T> broker) : broker(broker) { }
+Proxy<T>::Proxy(ValueBroker<T> broker) : broker(broker) {}
template <typename T>
-Proxy<T> & Proxy<T>::operator = (const T & val) {
+Proxy<T> & Proxy<T>::operator=(const T & val) {
this->broker.set(val);
return *this;
}
template <typename T>
-Proxy<T>::operator const T & () {
+Proxy<T>::operator const T &() {
return this->broker.get();
}
-}
-
+} // namespace crepe
diff --git a/src/example/db.cpp b/src/example/db.cpp
index c046421..8c06a84 100644
--- a/src/example/db.cpp
+++ b/src/example/db.cpp
@@ -1,12 +1,12 @@
-#include <crepe/facade/DB.h>
#include <crepe/api/Config.h>
+#include <crepe/facade/DB.h>
#include <crepe/util/log.h>
using namespace crepe;
using namespace std;
// run before main
-static auto _ = [] () {
+static auto _ = []() {
auto & cfg = Config::get_instance();
cfg.log.level = LogLevel::TRACE;
return 0;
diff --git a/src/example/proxy.cpp b/src/example/proxy.cpp
index 9f54f96..0afff41 100644
--- a/src/example/proxy.cpp
+++ b/src/example/proxy.cpp
@@ -5,15 +5,15 @@
#include <crepe/ValueBroker.h>
#include <crepe/api/Config.h>
-#include <crepe/util/log.h>
#include <crepe/util/Proxy.h>
+#include <crepe/util/log.h>
using namespace std;
using namespace crepe;
-void test_ro_ref(const int & val) { }
-void test_rw_ref(int & val) { }
-void test_ro_val(int val) { }
+void test_ro_ref(const int & val) {}
+void test_rw_ref(int & val) {}
+void test_ro_val(int val) {}
int main() {
auto & cfg = Config::get_instance();
@@ -21,18 +21,19 @@ int main() {
int real_value = 0;
- ValueBroker<int> broker {
- [&real_value] (const int & target) {
- dbg_logf("set %s to %s", to_string(real_value).c_str(), to_string(target).c_str());
+ ValueBroker<int> broker{
+ [&real_value](const int & target) {
+ dbg_logf("set %s to %s", to_string(real_value).c_str(),
+ to_string(target).c_str());
real_value = target;
},
- [&real_value] () -> const int & {
+ [&real_value]() -> const int & {
dbg_logf("get %s", to_string(real_value).c_str());
return real_value;
},
};
- Proxy<int> proxy { broker };
+ Proxy<int> proxy{broker};
broker.set(54);
proxy = 84;
@@ -43,4 +44,3 @@ int main() {
return 0;
}
-
diff --git a/src/example/savemgr.cpp b/src/example/savemgr.cpp
index c8dd2bc..436fb5a 100644
--- a/src/example/savemgr.cpp
+++ b/src/example/savemgr.cpp
@@ -4,21 +4,21 @@
*/
#include <cassert>
-#include <crepe/util/log.h>
-#include <crepe/util/Proxy.h>
-#include <crepe/api/SaveManager.h>
#include <crepe/api/Config.h>
+#include <crepe/api/SaveManager.h>
+#include <crepe/util/Proxy.h>
+#include <crepe/util/log.h>
using namespace crepe;
// unrelated setup code
-int _ = [] () {
+int _ = []() {
// make sure all log messages get printed
auto & cfg = Config::get_instance();
cfg.log.level = LogLevel::TRACE;
return 0; // satisfy compiler
-} ();
+}();
int main() {
const char * key = "mygame.test";
@@ -27,7 +27,7 @@ int main() {
dbg_logf("has key = %s", mgr.has(key) ? "true" : "false");
ValueBroker<int> prop = mgr.get<int>(key, 0);
- Proxy<int> val = mgr.get<int>(key, 0);
+ Proxy<int> val = mgr.get<int>(key, 0);
dbg_logf("val = %d", mgr.get<int>(key).get());
prop.set(1);
@@ -42,4 +42,3 @@ int main() {
return 0;
}
-