-
Notifications
You must be signed in to change notification settings - Fork 82
/
buffer.hpp
88 lines (67 loc) · 1.84 KB
/
buffer.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef __CERBERUS_BUFFER_HPP__
#define __CERBERUS_BUFFER_HPP__
#include <vector>
#include <string>
#include "common.hpp"
#include "utils/mempage.hpp"
struct iovec;
namespace cerb {
class Buffer {
util::MemoryPages _buffer;
public:
typedef util::SharedMemPage::msize_t size_type;
typedef util::MemPage::byte value_type;
typedef util::MemoryPages::const_iterator const_iterator;
typedef const_iterator iterator;
Buffer() {}
static Buffer from_string(std::string const& s);
Buffer(Buffer const&) = delete;
Buffer(Buffer&& rhs)
: _buffer(std::move(rhs._buffer))
{}
Buffer(const_iterator first, const_iterator last)
: _buffer(first, last)
{}
Buffer& operator=(Buffer&& rhs)
{
_buffer = std::move(rhs._buffer);
return *this;
}
iterator begin() const
{
return _buffer.begin();
}
iterator end() const
{
return _buffer.end();
}
const_iterator cbegin() const
{
return _buffer.begin();
}
const_iterator cend() const
{
return _buffer.end();
}
size_type size() const
{
return _buffer.size();
}
bool empty() const
{
return _buffer.empty();
}
void clear()
{
_buffer.clear();
}
int read(int fd);
void write(int fd);
void truncate_from_begin(iterator i);
void buffer_ready(std::vector<struct iovec>& iov);
void append_from(const_iterator first, const_iterator last);
std::string to_string() const;
bool same_as_string(std::string const& s) const;
};
}
#endif /* __CERBERUS_BUFFER_HPP__ */