-
Notifications
You must be signed in to change notification settings - Fork 0
/
InBlock.h
executable file
·97 lines (90 loc) · 1.79 KB
/
InBlock.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
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
89
90
91
92
93
94
95
96
97
/*
* InBlock.h
*
* Created on: 16 Apr 2014
* Author: lester
*/
#ifndef INBLOCK_H_
#define INBLOCK_H_
/*
* input block
* Use to cache data read from device.
* For parsing proporse the parser will use mark to this buffer to avoid copy data to temporal location
*
* setOrigin(iterator) function will be use to
*/
class InBlock {
char* data = nullptr; // ioblock
char* origin;
char* last;
unsigned int size;
public:
InBlock() :
origin(data), last(data), size(0) {
}
~InBlock() {
}
class iterator {
friend class InBlock;
iterator(char* pos) :
pos(pos) {
}
//InBlock* block = nullptr;
char* pos;
public:
iterator & operator ++() {
++pos;
return *this;
}
char &operator *() {
return *pos;
}
// convert iterator to char *
operator const char*() const {
return pos;
}
bool operator ==(const iterator& it) const {
return (pos == it.pos);
}
bool operator !=(const iterator& it) const {
return (pos != it.pos);
}
bool operator >(const iterator& it) const {
return (pos > it.pos);
}
iterator operator+(int i) {
return {pos + i};
}
int operator-(const iterator& it) {
return pos - it.pos;
}
};
/*
* set origin will do nothing until more data is needed
* iterator will be updated on read operation on block
*
* read file to block
* start iterator until reach end, set origin, read more data, continue processing
*/
void setOrigin(const iterator& it) {
origin = it.pos;
}
const iterator end() const {
return last;
}
iterator begin() {
return {origin};
}
void updateRead(const iterator& it) {
origin = it.pos;
}
/*
* Compact data, moving origin to offset zero
* update iterator.
* request for new data.
*/
void read(iterator & it) {
// compact and read new data
}
};
#endif /* INBLOCK_H_ */