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#include <cstdint>
8#include <memory>
9#include <span>
10#include <vector>
11#ifdef DEBUG
12#include "sha1.hh"
13#endif
14
15namespace openmsx {
16
18{
19public:
20#if STATISTICS
21 virtual ~DeltaBlock();
22#else
23 virtual ~DeltaBlock() = default;
24#endif
25 virtual void apply(std::span<uint8_t> dst) const = 0;
26
27protected:
28 DeltaBlock() = default;
29
30#ifdef DEBUG
31public:
32 Sha1Sum sha1;
33#endif
34
35#if STATISTICS
36protected:
37 static inline size_t globalAllocSize = 0;
38 size_t allocSize;
39#endif
40};
41
42
43class DeltaBlockCopy final : public DeltaBlock
44{
45public:
46 explicit DeltaBlockCopy(std::span<const uint8_t> data);
47 void apply(std::span<uint8_t> dst) const override;
48 void compress(size_t size);
49 [[nodiscard]] const uint8_t* getData();
50
51private:
52 [[nodiscard]] bool compressed() const { return compressedSize != 0; }
53
55 size_t compressedSize = 0;
56};
57
58
59class DeltaBlockDiff final : public DeltaBlock
60{
61public:
62 DeltaBlockDiff(std::shared_ptr<DeltaBlockCopy> prev_,
63 std::span<const uint8_t> data);
64 void apply(std::span<uint8_t> dst) const override;
65 [[nodiscard]] size_t getDeltaSize() const;
66
67private:
68 const std::shared_ptr<DeltaBlockCopy> prev;
69 const std::vector<uint8_t> delta; // TODO could be tweaked to use OutputBuffer
70};
71
72
74{
75public:
76 [[nodiscard]] std::shared_ptr<DeltaBlock> createNew(
77 const void* id, std::span<const uint8_t> data);
78 [[nodiscard]] std::shared_ptr<DeltaBlock> createNullDiff(
79 const void* id, std::span<const uint8_t> data);
80 void clear();
81
82private:
83 struct Info {
84 Info(const void* id_, size_t size_)
85 : id(id_), size(size_) {}
86
87 const void* id;
88 size_t size;
89 std::weak_ptr<DeltaBlockCopy> ref;
90 std::weak_ptr<DeltaBlock> last;
91 size_t accSize = 0;
92 };
93
94 std::vector<Info> infos;
95};
96
97} // namespace openmsx
98
99#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:29
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