CorsixTH engine (the C++ part)
Open source implementation of Theme Hospital
Loading...
Searching...
No Matches
run_length_encoder.h
Go to the documentation of this file.
1/*
2Copyright (c) 2010 Peter "Corsix" Cawley
3
4Permission is hereby granted, free of charge, to any person obtaining a copy of
5this software and associated documentation files (the "Software"), to deal in
6the Software without restriction, including without limitation the rights to
7use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8of the Software, and to permit persons to whom the Software is furnished to do
9so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22
23#ifndef CORSIX_TH_RLE_H_
24#define CORSIX_TH_RLE_H_
25#include "config.h"
26
27#include <vector>
28
31
33
45 public:
47
52 explicit integer_run_length_encoder(size_t iRecordSize);
53
55 void write(uint32_t iValue);
56
58
62 void finish();
63
64 const uint32_t* get_output(size_t* pCount) const;
65 void pump_output(lua_persist_writer* pWriter) const;
66
67 private:
69
73 void flush(bool bAll);
74
75 bool are_ranges_equal(size_t iObjIdx1, size_t iObjIdx2, size_t iOffset,
76 size_t iObjSize) const;
77 bool move_object_to_output(size_t iObjSize, size_t iObjCount);
78
80 std::vector<uint32_t> buffer;
82 std::vector<uint32_t> output;
84 size_t record_size;
86 size_t buffer_size{};
88 size_t buffer_offset{};
90 size_t output_size{};
92 size_t object_size{};
95 size_t object_copies{};
96};
97
101 public:
102 integer_run_length_decoder(size_t iRecordSize, lua_persist_reader* pReader);
103
104 uint32_t read();
105 bool is_finished() const;
106
107 private:
108 std::vector<uint32_t> buffer;
109
110 // Not owned by the decoder, the reader to read from.
111 lua_persist_reader* reader;
112
113 size_t reads_remaining{};
114 size_t record_size;
115 size_t object_copies{};
116 size_t object_index{};
117 size_t object_size{};
118};
119
120#endif // CORSIX_TH_RLE_H_
Definition run_length_encoder.h:100
uint32_t read()
Definition run_length_encoder.cpp:157
bool is_finished() const
Definition run_length_encoder.cpp:178
Encoder for reducing the amount of space to store a sequence of integers.
Definition run_length_encoder.h:44
const uint32_t * get_output(size_t *pCount) const
Definition run_length_encoder.cpp:138
void write(uint32_t iValue)
Supply the next integer in the input sequence to the encoder.
Definition run_length_encoder.cpp:36
void pump_output(lua_persist_writer *pWriter) const
Definition run_length_encoder.cpp:143
void finish()
Inform the encoder that the input sequence has finished.
Definition run_length_encoder.cpp:41
Interface used for depersisting Lua objects.
Definition persist_lua.h:107
Interface used for persisting Lua objects.
Definition persist_lua.h:44