Files
SweepStore/cpp/src/Public/sweepstore/sweepstore.h

68 lines
1.7 KiB
C++

#pragma once
#include <iosfwd>
#include "concurrency.h"
#include "header.h"
#include "utils/helpers.h"
#include "utils/file_handle.h"
class Sweepstore {
private:
std::string filePath;
SweepstoreFileHandle file;
SweepstoreHeader* header;
SweepstoreConcurrencyHeader* concurrencyHeader;
public:
Sweepstore(const std::string& filePath) : filePath(filePath), file(filePath, std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc) {
header = new SweepstoreHeader(file);
concurrencyHeader = new SweepstoreConcurrencyHeader(file);
}
~Sweepstore() {
delete header;
delete concurrencyHeader;
file.close();
}
void initialise(int concurrentWorkers = 4);
SweepstoreConcurrencyHeader* getConcurrencyHeader() {
return concurrencyHeader;
}
class Proxy {
Sweepstore* sweepstore;
std::string key;
public:
Proxy(Sweepstore* sweepstoreIn, const std::string& keyIn)
: sweepstore(sweepstoreIn), key(keyIn) {}
template <typename T>
operator T() {
// Get value from sweepstore
throw std::runtime_error("Not implemented: Reading values from Sweepstore by key is not implemented.");
}
template <typename T>
void operator=(const T& value) {
SweepstoreConcurrency::spawnTicket(sweepstore->filePath,
SweepstoreTicketOperation::WRITE,
bt_hash(key),
sizeof(T),
[this, key = this->key, &value]() {
}
);
};
};
Proxy operator[](const std::string& key) {
return Proxy(this, key);
}
};