blob: 863c5d98f271c22bd5dda5174fb6d00a484a64b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#pragma once
#include "Key.hpp"
#include "DataView.hpp"
#include "Signature.hpp"
#include <vector>
#include <stdexcept>
namespace odhtdb
{
class Group;
struct DatabaseStorageObject
{
DataView data;
u64 timestamp; // In microseconds
Signature::PublicKey creatorPublicKey;
DatabaseStorageObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey) :
data(_data), timestamp(_timestamp), creatorPublicKey(_creatorPublicKey)
{
}
};
struct DatabaseStorageObjectList
{
u64 timestamp; // In microseconds
std::vector<Group*> groups;
std::vector<DatabaseStorageObject> objects;
};
class DatabaseStorageAlreadyExists : public std::runtime_error
{
public:
DatabaseStorageAlreadyExists(const std::string &errMsg) : std::runtime_error(errMsg) {}
};
class DatabaseStorageNotFound : public std::runtime_error
{
public:
DatabaseStorageNotFound(const std::string &errMsg) : std::runtime_error(errMsg) {}
};
using DatabaseStorageMap = KeyMap<DatabaseStorageObjectList*>;
class DatabaseStorage
{
public:
// Throws DatabaseStorageAlreadyExists if data with key already exists
void createStorage(const Key &key, std::vector<Group*> &&groups, u64 timestamp);
// Throws DatabaseStorageNotFound if data with key does not exist
void appendStorage(const Key &key, DataView &data, u64 timestamp, const Signature::PublicKey &creatorPublicKey);
private:
DatabaseStorageMap storageMap;
};
}
|