-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuffer.cpp
More file actions
53 lines (44 loc) · 1.09 KB
/
Buffer.cpp
File metadata and controls
53 lines (44 loc) · 1.09 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
#include "Buffer.h"
Buffer::Buffer() : data(nullptr), size(0) {}
Buffer::Buffer(const std::string& content) {
size = content.length();
data = new char[size + 1];
std::memcpy(data, content.c_str(), size + 1);
}
Buffer::~Buffer() {
delete[] data;
}
Buffer::Buffer(const Buffer& other) {
size = other.size;
data = new char[size + 1];
std::memcpy(data, other.data, size + 1);
}
Buffer& Buffer::operator=(const Buffer& other) {
if (this != &other) {
delete[] data;
size = other.size;
data = new char[size + 1];
std::memcpy(data, other.data, size + 1);
}
return *this;
}
Buffer::Buffer(Buffer&& other) noexcept : data(other.data), size(other.size) {
other.data = nullptr;
other.size = 0;
}
Buffer& Buffer::operator=(Buffer&& other) noexcept {
if (this != &other) {
delete[] data;
data = other.data;
size = other.size;
other.data = nullptr;
other.size = 0;
}
return *this;
}
const char* Buffer::getData() const {
return data;
}
size_t Buffer::getSize() const {
return size;
}