-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInBuffer.h
More file actions
executable file
·66 lines (61 loc) · 1.2 KB
/
InBuffer.h
File metadata and controls
executable file
·66 lines (61 loc) · 1.2 KB
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
/*
* InBuffer.h
*
* Created on: 18 Apr 2014
* Author: lester
*/
#ifndef INBUFFER_H_
#define INBUFFER_H_
#include "iobase.h"
#include "Buffer.h"
#include "os.h"
/*
* Input buffer
* Expanding a buffer, to read data from source when end of read iterator is reached
* also allow to adjust read pointer after data has been compacted
*/
class InBuffer: protected io::Buffer
{
//Data source
io::io_base& source;
public:
template<int N>
explicit InBuffer(io::io_base& dev, io::Block<N> &b) :
Buffer(b), source(dev)
{
}
// get more data from device
void readData()
{
compact();
if (!getWSize())
{
throw error_api(ERROR_INFO(),api_error::get_not_enough_memory());
}
source >> *this;
}
/*
* Get iterator for this buffer
*/
Buffer::iterator begin()
{
return Buffer::read_begin();
}
Buffer::iterator end()
{
return Buffer::read_end();
}
/*
* All iterator must be adjust before execute a read data operation
*/
void adjust(Buffer::iterator& it)
{
it -= rd_idx; //(Buffer::read_begin() - Buffer::begin());
}
// Set which data must be remain on the buffer after a read operation.
void setOrigin(const Buffer::iterator& it)
{
updateR(it);
}
};
#endif /* INBUFFER_H_ */