OpenTTD Source: src/saveload/saveload_filter.h Source File

OpenTTD Source 1.11.0-RC1

saveload_filter.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef SAVELOAD_FILTER_H
11 #define SAVELOAD_FILTER_H
12
14 struct LoadFilter {
16 LoadFilter *chain;
17
22 LoadFilter(LoadFilter *chain) : chain(chain)
23 {
24 }
25
27 virtual ~LoadFilter()
28 {
29 delete this->chain;
30 }
31
38 virtual size_t Read(byte *buf, size_t len) = 0;
39
43 virtual void Reset()
44 {
45 this->chain->Reset();
46 }
47 };
48
54 template <typename T> LoadFilter *CreateLoadFilter(LoadFilter *chain)
55 {
56 return new T(chain);
57 }
58
60 struct SaveFilter {
62 SaveFilter *chain;
63
68 SaveFilter(SaveFilter *chain) : chain(chain)
69 {
70 }
71
73 virtual ~SaveFilter()
74 {
75 delete this->chain;
76 }
77
83 virtual void Write(byte *buf, size_t len) = 0;
84
88 virtual void Finish()
89 {
90 if (this->chain != nullptr) this->chain->Finish();
91 }
92 };
93
100 template <typename T> SaveFilter *CreateSaveFilter(SaveFilter *chain, byte compression_level)
101 {
102 return new T(chain, compression_level);
103 }
104
105 #endif /* SAVELOAD_FILTER_H */
SaveFilter::SaveFilter
SaveFilter(SaveFilter *chain)
Initialise this filter.
Definition: saveload_filter.h:68
LoadFilter::Reset
virtual void Reset()
Reset this filter to read from the beginning of the file.
Definition: saveload_filter.h:43
LoadFilter::Read
virtual size_t Read(byte *buf, size_t len)=0
Read a given number of bytes from the savegame.
CreateSaveFilter
SaveFilter * CreateSaveFilter(SaveFilter *chain, byte compression_level)
Instantiator for a save filter.
Definition: saveload_filter.h:100
SaveFilter::Finish
virtual void Finish()
Prepare everything to finish writing the savegame.
Definition: saveload_filter.h:88
SaveFilter::Write
virtual void Write(byte *buf, size_t len)=0
Write a given number of bytes into the savegame.
CreateLoadFilter
LoadFilter * CreateLoadFilter(LoadFilter *chain)
Instantiator for a load filter.
Definition: saveload_filter.h:54
SaveFilter::~SaveFilter
virtual ~SaveFilter()
Make sure the writers are properly closed.
Definition: saveload_filter.h:73
SaveFilter
Interface for filtering a savegame till it is written.
Definition: saveload_filter.h:60
SaveFilter::chain
SaveFilter * chain
Chained to the (savegame) filters.
Definition: saveload_filter.h:62
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:14
LoadFilter::~LoadFilter
virtual ~LoadFilter()
Make sure the writers are properly closed.
Definition: saveload_filter.h:27
LoadFilter::chain
LoadFilter * chain
Chained to the (savegame) filters.
Definition: saveload_filter.h:16
LoadFilter::LoadFilter
LoadFilter(LoadFilter *chain)
Initialise this filter.
Definition: saveload_filter.h:22