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 {
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 {
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 */