-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer.h
46 lines (32 loc) · 882 Bytes
/
buffer.h
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
//
// Created by jackson on 11.04.16.
//
#ifndef KIMBERLY_BUFFER_H
#define KIMBERLY_BUFFER_H
#include <string>
#include <string.h>
class buffer {
public:
// !caution! don't call trim() (and clear() and put() everything changing data) immediately after this method
const char *get(int amount);
// stashing put or get. otherwise throwing logic_error
void stash();
void set(const char *const data);
void put(const char *const data, size_t length);
void clear();
bool empty();
//minus "offset"
int length();
const std::string &string_data();
private:
std::string data;
size_t offset = 0;
enum {PUT, SET, GET, CLEAR, TRIM, STASH, NOT_MODIFIED} last_method = NOT_MODIFIED;
union{
size_t prev_offset;
size_t prev_data_size;
};
// trim an offset
void trim();
};
#endif //KIMBERLY_BUFFER_H