00001 /* $Id$ */ 00002 00003 /* 00004 * This file is part of OpenTTD. 00005 * 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. 00006 * 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. 00007 * 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/>. 00008 */ 00009 00012 #ifndef SAVELOAD_FILTER_H 00013 #define SAVELOAD_FILTER_H 00014 00016 struct LoadFilter { 00018 LoadFilter *chain; 00019 00024 LoadFilter(LoadFilter *chain) : chain(chain) 00025 { 00026 } 00027 00029 virtual ~LoadFilter() 00030 { 00031 delete this->chain; 00032 } 00033 00040 virtual size_t Read(byte *buf, size_t len) = 0; 00041 00045 virtual void Reset() 00046 { 00047 this->chain->Reset(); 00048 } 00049 }; 00050 00056 template <typename T> LoadFilter *CreateLoadFilter(LoadFilter *chain) 00057 { 00058 return new T(chain); 00059 } 00060 00062 struct SaveFilter { 00064 SaveFilter *chain; 00065 00070 SaveFilter(SaveFilter *chain) : chain(chain) 00071 { 00072 } 00073 00075 virtual ~SaveFilter() 00076 { 00077 delete this->chain; 00078 } 00079 00085 virtual void Write(byte *buf, size_t len) = 0; 00086 00090 virtual void Finish() 00091 { 00092 if (this->chain != NULL) this->chain->Finish(); 00093 } 00094 }; 00095 00102 template <typename T> SaveFilter *CreateSaveFilter(SaveFilter *chain, byte compression_level) 00103 { 00104 return new T(chain, compression_level); 00105 } 00106 00107 #endif /* SAVELOAD_FILTER_H */