blob: 6229114f0b0695f221d690c78a90137b2ad93464 (
plain) (
blame)
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
|
#pragma once
#include <limits>
class TConstBuffer;
class TMutableBuffer;
class TBufferBase {
public:
size_t GetSize() const noexcept;
void SetSize(size_t newSize) noexcept;
protected:
TBufferBase(size_t size = 0) noexcept;
size_t Size;
};
template <typename PointerType>
class TBufferBaseT: public TBufferBase {
public:
PointerType GetPointer() const noexcept;
void Cut(size_t offset) noexcept;
void Assign(PointerType data = nullptr, size_t size = 0U) noexcept;
protected:
TBufferBaseT(PointerType data, size_t size) noexcept;
PointerType Data;
};
/// Represents constant memory buffer, but do not owns it.
class TConstBuffer: public TBufferBaseT<const void*> {
friend class TMutableBuffer;
public:
TConstBuffer(const TMutableBuffer& buffer) noexcept;
TConstBuffer(const void* data = nullptr, size_t size = 0U) noexcept;
TConstBuffer Offset(ptrdiff_t offset, size_t size = std::numeric_limits<size_t>::max()) const noexcept;
};
/// Represents mutable memory buffer, but do not owns it.
class TMutableBuffer: public TBufferBaseT<void*> {
friend class TConstBuffer;
public:
TMutableBuffer(void* data = nullptr, size_t size = 0U) noexcept;
TMutableBuffer(const TMutableBuffer& value) noexcept
: TBufferBaseT<void*>(value)
{
}
TMutableBuffer Offset(ptrdiff_t offset, size_t size = std::numeric_limits<size_t>::max()) const noexcept;
size_t CopyFrom(const TConstBuffer& buffer) const noexcept;
};
|