openMSX
DeltaBlock.hh
Go to the documentation of this file.
1#ifndef DELTA_BLOCK_HH
2#define DELTA_BLOCK_HH
3
4#define STATISTICS 0
5
6#include "MemBuffer.hh"
7
8#include <cstdint>
9#include <memory>
10#include <span>
11#include <vector>
12#ifdef DEBUG
13#include "sha1.hh"
14#endif
15
16namespace openmsx {
17
19{
20public:
21#if STATISTICS
22 virtual ~DeltaBlock();
23#else
24 virtual ~DeltaBlock() = default;
25#endif
26 virtual void apply(std::span<uint8_t> dst) const = 0;
27
28protected:
29 DeltaBlock() = default;
30
31#ifdef DEBUG
32public:
33 Sha1Sum sha1;
34#endif
35
36#if STATISTICS
37protected:
38 static inline size_t globalAllocSize = 0;
39 size_t allocSize;
40#endif
41};
42
43
44class DeltaBlockCopy final : public DeltaBlock
45{
46public:
47 explicit DeltaBlockCopy(std::span<const uint8_t> data);
48 void apply(std::span<uint8_t> dst) const override;
49 void compress(size_t size);
50 [[nodiscard]] const uint8_t* getData();
51
52private:
53 [[nodiscard]] bool compressed() const { return compressedSize != 0; }
54
56 size_t compressedSize = 0;
57};
58
59
60class DeltaBlockDiff final : public DeltaBlock
61{
62public:
63 DeltaBlockDiff(std::shared_ptr<DeltaBlockCopy> prev_,
64 std::span<const uint8_t> data);
65 void apply(std::span<uint8_t> dst) const override;
66 [[nodiscard]] size_t getDeltaSize() const;
67
68private:
69 const std::shared_ptr<DeltaBlockCopy> prev;
70 const std::vector<uint8_t> delta; // TODO could be tweaked to use OutputBuffer
71};
72
73
75{
76public:
77 [[nodiscard]] std::shared_ptr<DeltaBlock> createNew(
78 const void* id, std::span<const uint8_t> data);
79 [[nodiscard]] std::shared_ptr<DeltaBlock> createNullDiff(
80 const void* id, std::span<const uint8_t> data);
81 void clear();
82
83private:
84 struct Info {
85 Info(const void* id_, size_t size_)
86 : id(id_), size(size_) {}
87
88 const void* id;
89 size_t size;
90 std::weak_ptr<DeltaBlockCopy> ref;
91 std::weak_ptr<DeltaBlock> last;
92 size_t accSize = 0;
93 };
94
95 std::vector<Info> infos;
96};
97
98} // namespace openmsx
99
100#endif
uintptr_t id
const uint8_t * getData()
void apply(std::span< uint8_t > dst) const override
void compress(size_t size)
void apply(std::span< uint8_t > dst) const override
size_t getDeltaSize() const
virtual void apply(std::span< uint8_t > dst) const =0
virtual ~DeltaBlock()=default
std::shared_ptr< DeltaBlock > createNew(const void *id, std::span< const uint8_t > data)
std::shared_ptr< DeltaBlock > createNullDiff(const void *id, std::span< const uint8_t > data)
This class manages the lifetime of a block of memory.
Definition MemBuffer.hh:32
This class represents the result of a sha1 calculation (a 160-bit value).
Definition sha1.hh:24
This file implemented 3 utility functions:
Definition Autofire.cc:11