-
Notifications
You must be signed in to change notification settings - Fork 3
/
MessageStore.hpp
59 lines (42 loc) · 1.21 KB
/
MessageStore.hpp
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
59
#ifndef MESSAGESTORE_DOT_HPP
#define MESSAGESTORE_DOT_HPP
#include <fstream>
#include <string_view>
#include <boost/iostreams/device/mapped_file.hpp>
#include "Now.hpp"
#include "Pill.hpp"
#include "fs.hpp"
class MessageStore {
public:
void open(std::string_view fqdn,
std::streamsize max_size,
std::string_view folder);
Pill const& id() const { return s_; }
Now const& when() const { return then_; }
std::ostream& write(char const* s, std::streamsize count);
std::ostream& write(std::string_view s)
{
return write(s.data(), s.length());
}
void deliver();
void close();
void trash() { close(); }
std::string_view freeze();
bool size_error() const { return size_error_; }
std::streamsize size() const { return size_; }
std::streamsize max_size() const { return max_size_; }
std::streamsize size_left() const { return max_size() - size(); }
private:
Pill s_;
Now then_;
std::ofstream ofs_;
std::streamsize size_{0};
std::streamsize max_size_{0};
fs::path newfn_;
fs::path tmpfn_;
fs::path tmp2fn_;
bool size_error_{false};
boost::iostreams::mapped_file_source mapping_;
void try_close_();
};
#endif // MESSAGESTORE_DOT_HPP