Gel2D - The free/open source game creation suite

gelDataStream.h
Go to the documentation of this file.
00001 /*
00002 Gel2D Game Engine - Cross-platform 2D gaming middleware
00003 Copyright (C) 2011 Mark D. Procarione
00004 
00005 Gel2D is free software: you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation, either version 3 of the License, or
00008 (at your option) any later version.
00009 
00010 Gel2D is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 GNU General Public License for more details.
00014 */
00015 
00016 #ifndef __GELDATASTREAM_H__
00017 #define __GELDATASTREAM_H__
00018 
00019 #include "gelNamespace.h"
00020 #include "gelString.h"
00021 
00022 #include <cstdio>
00023 #include <cstdlib>
00024 
00025 namespace gel
00026 {
00028         class GelFileStream
00029         {
00030                 public:
00032                         GelFileStream() : file(NULL), size(0) {}
00033 
00035 
00037                         GelFileStream( const GelString &filename, FileMode mode );
00038 
00040 
00042                         ~GelFileStream();
00043 
00045 
00048                         bool open( const GelString &filename, FileMode mode );
00049 
00051 
00052                         bool close();
00053 
00055 
00059                         long read( void *data, long size, long count );
00060 
00062 
00066             long write( const void *data, long size, long count );
00067 
00069 
00072             bool flush();
00073 
00075 
00076             long getSize() const { return size; }
00077 
00079 
00081                         long tell() const;
00082 
00084 
00087                         bool seek( long offset, DataSeek origin );
00088 
00090 
00091                         bool atEnd() const;
00092 
00093         private:
00094                         FILE *file;
00095                         long size;
00096         };
00097 
00099         class GelMemoryStream
00100         {
00101                 public:
00103                         GelMemoryStream() { data = NULL; size = 0; position = 0; delOnClose = false; }
00104 
00106 
00109                         GelMemoryStream( void *bdata, long bsize );
00110 
00112                         ~GelMemoryStream();
00113 
00115 
00117             void deleteOnClose( bool del ) { delOnClose = del; }
00118 
00120 
00123                         bool open( void *bdata, long bsize );
00124 
00126 
00129                         long read( void *bdata, long bcount );
00130 
00132 
00135                         long write( void *bdata, long bcount );
00136 
00138 
00139             long getSize() const { return size; }
00140 
00142 
00143                         long tell() const { return position; }
00144 
00146 
00149                         bool seek( long offset, DataSeek origin );
00150 
00152 
00153                         bool atEnd() const;
00154 
00155         private:
00156                         void *data;
00157                         long size;
00158                         long position;
00159                         bool delOnClose;
00160         };
00161 
00163         class GelTextStream
00164         {
00165                 public:
00167                         GelTextStream() { file = NULL; size = 0; }
00168 
00170 
00172                         GelTextStream( const GelString &filename, FileMode mode );
00173 
00175 
00177                         ~GelTextStream();
00178 
00180 
00183                         bool open( const GelString &filename, FileMode mode );
00184 
00186 
00187                         bool close();
00188 
00190 
00192             GelString read( int maxlen );
00193 
00195 
00198             GelString readAll();
00199 
00201 
00203             GelString readLine( int maxlen );
00204 
00206 
00207             GelChar readChar();
00208 
00210 
00211             bool writeString( const GelString &str );
00212 
00214 
00215             bool writeChar( GelChar chr );
00216 
00218 
00221             bool flush();
00222 
00224 
00225             long getSize() const { return size; }
00226 
00228 
00230                         long tell() const;
00231 
00233 
00236                         bool seek( long offset, DataSeek origin );
00237 
00239 
00240                         bool atEnd() const;
00241 
00242         private:
00243                         FILE *file;
00244                         long size;
00245         };
00246 }
00247 
00248 #endif // __GELDATASTREAM_H__