summaryrefslogtreecommitdiffhomepage
path: root/statistics.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-07 14:07:13 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-07 14:07:13 +0100
commit63fc8e14be5e450df8ccc18fe76e02c5f0827660 (patch)
treed1e37837b277b75e0eb9289b41a47f5dc86b4360 /statistics.cpp
parent7feaf1a9d7fb09985b9b17cd48fd1aa8eb15d8b3 (diff)
Test statistics
Diffstat (limited to 'statistics.cpp')
-rw-r--r--statistics.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/statistics.cpp b/statistics.cpp
index 1d67bfd..fb7148b 100644
--- a/statistics.cpp
+++ b/statistics.cpp
@@ -8,14 +8,14 @@ namespace fs = std::filesystem;
using namespace std::string_literals;
namespace {
- const fs::path statsfilepath{ "/var/lib/webserver/stats.db" };
+ const fs::path default_statsfilepath{ "stats.db" };
} // anonymous namespace
void Statistics::load()
{
std::lock_guard<std::mutex> lock(mMutex);
std::cout << "Loading statistics..." << std::endl;
- std::ifstream file{statsfilepath, std::ios::in | std::ios::binary};
+ std::ifstream file{mPath, std::ios::in | std::ios::binary};
if (file.is_open()) {
Reichwein::Serialization::IArchive archive{file};
@@ -32,7 +32,7 @@ void Statistics::save()
if (mChanged) {
std::lock_guard<std::mutex> lock(mMutex);
std::cout << "Saving statistics..." << std::endl;
- std::ofstream file{statsfilepath, std::ios::out | std::ios::binary | std::ios::trunc};
+ std::ofstream file{mPath, std::ios::out | std::ios::binary | std::ios::trunc};
if (file.is_open()) {
Reichwein::Serialization::OArchive archive{file};
@@ -45,7 +45,12 @@ void Statistics::save()
}
}
-Statistics::Statistics()
+Statistics::Statistics(): mPath{default_statsfilepath}
+{
+ load();
+}
+
+Statistics::Statistics(const fs::path& path): mPath{path.empty() ? default_statsfilepath : path}
{
load();
}