-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuf.cpp
66 lines (54 loc) · 1.18 KB
/
Buf.cpp
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
#include "Common.h"
#include "Buf.h"
#include <iostream>
using namespace std;
Buf::Buf() {
this->b_flags = b_flags_init;
this->b_wcount = b_wcount_init;
this->b_addr = new unsigned char[buffer_size];
if (!this->b_addr) {
cerr << "buffer申请空间失败!" << endl;
exit(ERROR_NEW);
}
this->b_blkno = b_blkno_init;
this->b_prev = NULL;
this->b_next = NULL;
memset(this->b_paddings, 0, sizeof(b_paddings));
}
Buf::Buf(const Buf& b) {
this->b_flags = b.b_flags;
this->b_wcount = b.b_wcount;
this->b_addr = new unsigned char[buffer_size];
if (!this->b_addr) {
cerr << "buffer申请空间失败!" << endl;
exit(ERROR_NEW);
}
memcpy(b_addr, b.b_addr, buffer_size);
this->b_blkno = b.b_blkno;
this->b_prev = b.b_prev;
this->b_next = b.b_next;
memset(this->b_paddings, 0, sizeof(b_paddings));
}
Buf::~Buf() {
if (b_addr) {
delete[] b_addr;
}
}
bool Buf::checkDELWRI() {
return this->b_flags & B_DELWRI;
}
bool Buf::checkDONE() {
return this->b_flags & B_DONE;
}
void Buf::clearDELWRI() {
this->b_flags &= (~B_DELWRI);
}
void Buf::clearDONE() {
this->b_flags &= (~B_DONE);
}
void Buf::setDELWRI() {
this->b_flags |= B_DELWRI;
}
void Buf::setDONE() {
this->b_flags |= B_DONE;
}