OpenTTD

saveload_filter.h
Go to the documentation of this file.
1 /* $Id: saveload_filter.h 21395 2010-12-05 14:41:34Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef SAVELOAD_FILTER_H
13 #define SAVELOAD_FILTER_H
14
16 struct LoadFilter {
18 LoadFilter *chain;
19
24 LoadFilter(LoadFilter *chain) : chain(chain)
25 {
26 }
27
29 virtual ~LoadFilter()
30 {
31 delete this->chain;
32 }
33
40 virtual size_t Read(byte *buf, size_t len) = 0;
41
45 virtual void Reset()
46 {
47 this->chain->Reset();
48 }
49 };
50
56 template <typename T> LoadFilter *CreateLoadFilter(LoadFilter *chain)
57 {
58 return new T(chain);
59 }
60
62 struct SaveFilter {
64 SaveFilter *chain;
65
70 SaveFilter(SaveFilter *chain) : chain(chain)
71 {
72 }
73
75 virtual ~SaveFilter()
76 {
77 delete this->chain;
78 }
79
85 virtual void Write(byte *buf, size_t len) = 0;
86
90 virtual void Finish()
91 {
92 if (this->chain != NULL) this->chain->Finish();
93 }
94 };
95
102 template <typename T> SaveFilter *CreateSaveFilter(SaveFilter *chain, byte compression_level)
103 {
104 return new T(chain, compression_level);
105 }
106
107 #endif /* SAVELOAD_FILTER_H */
CreateLoadFilter
LoadFilter * CreateLoadFilter(LoadFilter *chain)
Instantiator for a load filter.
Definition: saveload_filter.h:56
SaveFilter::SaveFilter
SaveFilter(SaveFilter *chain)
Initialise this filter.
Definition: saveload_filter.h:70
LoadFilter::chain
LoadFilter * chain
Chained to the (savegame) filters.
Definition: saveload_filter.h:18
CreateSaveFilter
SaveFilter * CreateSaveFilter(SaveFilter *chain, byte compression_level)
Instantiator for a save filter.
Definition: saveload_filter.h:102
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:16
SaveFilter::Finish
virtual void Finish()
Prepare everything to finish writing the savegame.
Definition: saveload_filter.h:90
LoadFilter::Reset
virtual void Reset()
Reset this filter to read from the beginning of the file.
Definition: saveload_filter.h:45
LoadFilter::Read
virtual size_t Read(byte *buf, size_t len)=0
Read a given number of bytes from the savegame.
LoadFilter::~LoadFilter
virtual ~LoadFilter()
Make sure the writers are properly closed.
Definition: saveload_filter.h:29
LoadFilter::LoadFilter
LoadFilter(LoadFilter *chain)
Initialise this filter.
Definition: saveload_filter.h:24
SaveFilter::~SaveFilter
virtual ~SaveFilter()
Make sure the writers are properly closed.
Definition: saveload_filter.h:75
SaveFilter::chain
SaveFilter * chain
Chained to the (savegame) filters.
Definition: saveload_filter.h:64
SaveFilter
Interface for filtering a savegame till it is written.
Definition: saveload_filter.h:62