1 /* $Id: saveload_filter.h 21395 2010-12-05 14:41:34Z rubidium $ */
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/>.
10 /** @file saveload_filter.h Declaration of filters used for saving and loading savegames. */
12 #ifndef SAVELOAD_FILTER_H
13 #define SAVELOAD_FILTER_H
15 /** Interface for filtering a savegame till it is loaded. */
17 /** Chained to the (savegame) filters. */
21 * Initialise this filter.
22 * @param chain The next filter in this chain.
24 LoadFilter(LoadFilter
*chain
) : chain(chain
)
28 /** Make sure the writers are properly closed. */
35 * Read a given number of bytes from the savegame.
36 * @param buf The bytes to read.
37 * @param len The number of bytes to read.
38 * @return The number of actually read bytes.
40 virtual size_t Read(byte
*buf
, size_t len
) = 0;
43 * Reset this filter to read from the beginning of the file.
52 * Instantiator for a load filter.
53 * @param chain The next filter in this chain.
54 * @tparam T The type of load filter to create.
56 template <typename T
> LoadFilter
*CreateLoadFilter(LoadFilter
*chain
)
61 /** Interface for filtering a savegame till it is written. */
63 /** Chained to the (savegame) filters. */
67 * Initialise this filter.
68 * @param chain The next filter in this chain.
70 SaveFilter(SaveFilter
*chain
) : chain(chain
)
74 /** Make sure the writers are properly closed. */
81 * Write a given number of bytes into the savegame.
82 * @param buf The bytes to write.
83 * @param len The number of bytes to write.
85 virtual void Write(byte
*buf
, size_t len
) = 0;
88 * Prepare everything to finish writing the savegame.
92 if (this->chain
!= nullptr) this->chain
->Finish();
97 * Instantiator for a save filter.
98 * @param chain The next filter in this chain.
99 * @param compression_level The requested level of compression.
100 * @tparam T The type of save filter to create.
102 template <typename T
> SaveFilter
*CreateSaveFilter(SaveFilter
*chain
, byte compression_level
)
104 return new T(chain
, compression_level
);
107 #endif /* SAVELOAD_FILTER_H */