-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuffer.cc
More file actions
56 lines (39 loc) · 917 Bytes
/
Copy pathBuffer.cc
File metadata and controls
56 lines (39 loc) · 917 Bytes
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
/*
Buffer.cc
Copyright: Copyright (C) 2013 Mitsuru Nakada All Rights Reserved.
License: GNU GPL v2
*/
#include "Buffer.h"
Buffer::Buffer() {
Clean();
}
int Buffer::PutBuffer(const byte d) {
int nextp = (WritePoint + 1) & BufferMask;
if(nextp == ReadPoint) return -1;
Buf[WritePoint] = d;
WritePoint = nextp;
return 0;
}
int Buffer::AddBuffer(const byte *buf, int size) {
for(int i = 0; i < size; i++) {
if(PutBuffer(buf[i])) return -1;
}
return 0;
}
int Buffer::GetBuffer() {
if(ReadPoint == WritePoint) return -1;
int d = Buf[ReadPoint];
ReadPoint = (ReadPoint + 1) & BufferMask;
return d;
}
int Buffer::PeekBuffer(int offset) {
if(offset >= GetLen()) return -1;
return Buf[(ReadPoint + offset) & BufferMask];
}
int Buffer::GetLen() {
return (WritePoint + BufferSize - ReadPoint) & BufferMask;
}
void Buffer::Clean() {
ReadPoint = 0;
WritePoint = 0;
}