1 /******************************************************************************** 2 * * 3 * G Z F i l e S t r e a m C l a s s e s * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 2002,2020 by Sander Jansen. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifdef HAVE_ZLIB_H 22 #ifndef FXGZFILESTREAM_H 23 #define FXGZFILESTREAM_H 24 25 #ifndef FXFILESTREAM_H 26 #include "FXFileStream.h" 27 #endif 28 29 namespace FX { 30 31 32 struct ZBlock; 33 34 35 /// GZIP compressed stream 36 class FXAPI FXGZFileStream : public FXFileStream { 37 private: 38 ZBlock *gz; 39 int ac; 40 protected: 41 virtual FXuval writeBuffer(FXuval count); 42 virtual FXuval readBuffer(FXuval count); 43 public: 44 45 /// Create GZIP compressed file stream 46 FXGZFileStream(const FXObject* cont=NULL); 47 48 /// Create and open GZIP compressed file stream 49 FXGZFileStream(const FXString& filename,FXStreamDirection save_or_load=FXStreamLoad,FXuval size=8192UL); 50 51 /// Open file stream 52 FXbool open(const FXString& filename,FXStreamDirection save_or_load=FXStreamLoad,FXuval size=8192UL); 53 54 /// Flush buffer 55 virtual FXbool flush(); 56 57 /// Close file stream 58 virtual FXbool close(); 59 60 /// Get position position()61 FXlong position() const { return FXStream::position(); } 62 63 /// Move to position position(FXlong,FXWhence)64 virtual FXbool position(FXlong,FXWhence){ return false; } 65 66 /// Save single items to stream 67 FXGZFileStream& operator<<(const FXuchar& v){ FXStream::operator<<(v); return *this; } 68 FXGZFileStream& operator<<(const FXchar& v){ FXStream::operator<<(v); return *this; } 69 FXGZFileStream& operator<<(const FXbool& v){ FXStream::operator<<(v); return *this; } 70 FXGZFileStream& operator<<(const FXushort& v){ FXStream::operator<<(v); return *this; } 71 FXGZFileStream& operator<<(const FXshort& v){ FXStream::operator<<(v); return *this; } 72 FXGZFileStream& operator<<(const FXuint& v){ FXStream::operator<<(v); return *this; } 73 FXGZFileStream& operator<<(const FXint& v){ FXStream::operator<<(v); return *this; } 74 FXGZFileStream& operator<<(const FXfloat& v){ FXStream::operator<<(v); return *this; } 75 FXGZFileStream& operator<<(const FXdouble& v){ FXStream::operator<<(v); return *this; } 76 FXGZFileStream& operator<<(const FXlong& v){ FXStream::operator<<(v); return *this; } 77 FXGZFileStream& operator<<(const FXulong& v){ FXStream::operator<<(v); return *this; } 78 79 /// Save arrays of items to stream save(const FXuchar * p,FXuval n)80 FXGZFileStream& save(const FXuchar* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXchar * p,FXuval n)81 FXGZFileStream& save(const FXchar* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXbool * p,FXuval n)82 FXGZFileStream& save(const FXbool* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXushort * p,FXuval n)83 FXGZFileStream& save(const FXushort* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXshort * p,FXuval n)84 FXGZFileStream& save(const FXshort* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXuint * p,FXuval n)85 FXGZFileStream& save(const FXuint* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXint * p,FXuval n)86 FXGZFileStream& save(const FXint* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXfloat * p,FXuval n)87 FXGZFileStream& save(const FXfloat* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXdouble * p,FXuval n)88 FXGZFileStream& save(const FXdouble* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXlong * p,FXuval n)89 FXGZFileStream& save(const FXlong* p,FXuval n){ FXStream::save(p,n); return *this; } save(const FXulong * p,FXuval n)90 FXGZFileStream& save(const FXulong* p,FXuval n){ FXStream::save(p,n); return *this; } 91 92 /// Load single items from stream 93 FXGZFileStream& operator>>(FXuchar& v){ FXStream::operator>>(v); return *this; } 94 FXGZFileStream& operator>>(FXchar& v){ FXStream::operator>>(v); return *this; } 95 FXGZFileStream& operator>>(FXbool& v){ FXStream::operator>>(v); return *this; } 96 FXGZFileStream& operator>>(FXushort& v){ FXStream::operator>>(v); return *this; } 97 FXGZFileStream& operator>>(FXshort& v){ FXStream::operator>>(v); return *this; } 98 FXGZFileStream& operator>>(FXuint& v){ FXStream::operator>>(v); return *this; } 99 FXGZFileStream& operator>>(FXint& v){ FXStream::operator>>(v); return *this; } 100 FXGZFileStream& operator>>(FXfloat& v){ FXStream::operator>>(v); return *this; } 101 FXGZFileStream& operator>>(FXdouble& v){ FXStream::operator>>(v); return *this; } 102 FXGZFileStream& operator>>(FXlong& v){ FXStream::operator>>(v); return *this; } 103 FXGZFileStream& operator>>(FXulong& v){ FXStream::operator>>(v); return *this; } 104 105 /// Load arrays of items from stream load(FXuchar * p,FXuval n)106 FXGZFileStream& load(FXuchar* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXchar * p,FXuval n)107 FXGZFileStream& load(FXchar* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXbool * p,FXuval n)108 FXGZFileStream& load(FXbool* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXushort * p,FXuval n)109 FXGZFileStream& load(FXushort* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXshort * p,FXuval n)110 FXGZFileStream& load(FXshort* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXuint * p,FXuval n)111 FXGZFileStream& load(FXuint* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXint * p,FXuval n)112 FXGZFileStream& load(FXint* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXfloat * p,FXuval n)113 FXGZFileStream& load(FXfloat* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXdouble * p,FXuval n)114 FXGZFileStream& load(FXdouble* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXlong * p,FXuval n)115 FXGZFileStream& load(FXlong* p,FXuval n){ FXStream::load(p,n); return *this; } load(FXulong * p,FXuval n)116 FXGZFileStream& load(FXulong* p,FXuval n){ FXStream::load(p,n); return *this; } 117 118 /// Save object saveObject(const FXObject * v)119 FXGZFileStream& saveObject(const FXObject* v){ FXStream::saveObject(v); return *this; } 120 121 /// Load object loadObject(FXObject * & v)122 FXGZFileStream& loadObject(FXObject*& v){ FXStream::loadObject(v); return *this; } 123 124 /// Load object 125 template<class TYPE> 126 FXGZFileStream& operator>>(TYPE*& obj){ return loadObject(reinterpret_cast<FXObject*&>(obj)); } 127 128 /// Save object 129 template<class TYPE> 130 FXGZFileStream& operator<<(const TYPE* obj){ return saveObject(static_cast<const FXObject*>(obj)); } 131 132 /// Clean up 133 virtual ~FXGZFileStream(); 134 }; 135 136 } 137 138 139 #endif 140 #endif 141