Add concurrency handling implementation with ticket management and file locking

This commit is contained in:
ImBenji
2025-12-02 14:11:45 +00:00
parent e6ccad87b4
commit eae4d0e24e
16 changed files with 1405 additions and 1551 deletions

View File

@@ -0,0 +1,49 @@
#pragma once
#include <fstream>
#include <string>
#include <memory>
class SweepstoreFileHandle {
private:
std::string path;
std::unique_ptr<std::fstream> stream;
public:
SweepstoreFileHandle(const std::string& p, std::ios::openmode mode = std::ios::in | std::ios::out | std::ios::binary)
: path(p), stream(std::make_unique<std::fstream>(p, mode)) {
if (!stream->is_open()) {
throw std::runtime_error("Failed to open file: " + path);
}
}
const std::string& getPath() const { return path; }
std::fstream& getStream() { return *stream; }
const std::fstream& getStream() const { return *stream; }
// Smart pointer-like interface
std::fstream* operator->() { return stream.get(); }
const std::fstream* operator->() const { return stream.get(); }
std::fstream& operator*() { return *stream; }
const std::fstream& operator*() const { return *stream; }
bool isOpen() const { return stream && stream->is_open(); }
void close() {
if (stream) {
stream->close();
}
}
SweepstoreFileHandle(SweepstoreFileHandle&&) noexcept = default;
SweepstoreFileHandle& operator=(SweepstoreFileHandle&&) noexcept = default;
SweepstoreFileHandle(const SweepstoreFileHandle&) = delete;
SweepstoreFileHandle& operator=(const SweepstoreFileHandle&) = delete;
~SweepstoreFileHandle() {
close();
}
};