45 lines
778 B
C++
45 lines
778 B
C++
//
|
|
// Created by Kirill Zhukov on 20.04.2025.
|
|
//
|
|
|
|
#ifndef VERSIONMANAGER_H
|
|
#define VERSIONMANAGER_H
|
|
|
|
#include <atomic>
|
|
#include <fstream>
|
|
#include <filesystem>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
namespace usub::utils
|
|
{
|
|
class VersionManager
|
|
{
|
|
public:
|
|
explicit VersionManager(const std::string& dbname);
|
|
|
|
~VersionManager()
|
|
{
|
|
save_version();
|
|
}
|
|
|
|
uint64_t next_version();
|
|
|
|
private:
|
|
void ensure_metadata_dir();
|
|
|
|
void load_version();
|
|
|
|
void save_version();
|
|
|
|
private:
|
|
std::atomic<uint64_t> version{1};
|
|
std::string db_name;
|
|
std::string metadata_dir;
|
|
std::string version_file;
|
|
};
|
|
} // namespace usub::utils
|
|
|
|
#endif //VERSIONMANAGER_H
|