Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

rtstreams.h

Go to the documentation of this file.
00001 /*
00002  * rtstreams.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013  * 
00014  */
00015 
00023 #ifndef __LRT_STREAMS__
00024 #define __LRT_STREAMS__
00025 
00026 #ifdef __SYMBIAN32__
00027   class RFs;
00028   class RFile;
00029   template<int S> class TBuf8;
00030 #else
00031 //#include <stdio.h>
00032 #endif
00033 
00034 #include "rtstring.h"
00035 
00036 namespace lrt {
00037 
00038 class File;
00039 template <class T>class Array;
00040 
00041 
00042 
00050 class InputStream {
00051 
00052 public:
00057         virtual bool markSupported();
00058 
00064         virtual void mark();
00065 
00071         virtual void reset();
00072 
00077         virtual int read() = 0;
00078 
00083         virtual int read(Array<char>& b, int off, int len);
00084 
00089         int read(Array<char>& b); // you need not override this one
00090 
00095         virtual bool eos() = 0;
00096 
00099         virtual bool fail(); // you need not override this one
00100 
00104         virtual void close();
00105 
00109         virtual ~InputStream();
00110 
00111 protected:
00116         InputStream();
00117 
00119         bool _fail;
00120 };
00121 
00125 class FileInputStream : public InputStream {
00126 
00127 public:
00131         FileInputStream(const File& file, bool textMode);
00132 
00137         FileInputStream(const String& fileName, bool textMode);
00138 
00140         virtual bool markSupported();
00141 
00143         virtual void mark();
00144 
00148         virtual void reset();
00149 
00153         virtual int read();
00154 
00158         virtual bool eos();
00159 
00161         virtual void close();
00162 
00163         virtual ~FileInputStream();
00164 
00165 private:
00166 #ifdef __SYMBIAN32__
00167         RFs* session;
00168         RFile* file;
00169         TBuf8<80>* buf;
00170         int pos;
00171         void init(const String&, bool);
00172 #else
00173         void* handle;
00174 #endif
00175         int markPos;
00176         bool open;
00177 };
00178 
00182 class FilterInputStream : public InputStream {
00183 
00184 public:
00187         FilterInputStream(InputStream* in);
00188 
00190         virtual bool markSupported();
00191 
00195         virtual void mark();
00196 
00200         virtual void reset();
00201 
00203         virtual int read();
00204 
00206         virtual int read(Array<char>& b, int off, int len);
00207 
00210         virtual bool fail();  // you needn't override this one
00211 
00215         virtual InputStream* detach();
00216 
00220         virtual bool eos();
00221 
00223         virtual void close();
00224 
00226         virtual ~FilterInputStream();
00227 
00228 protected:
00230         InputStream* in;
00232         bool _detach;
00233 };
00234 
00238 class ParseInputStream : public FilterInputStream {
00239 
00240 public:
00244         static const String whitespace;
00250         ParseInputStream(InputStream* in, const String& separators, const char commentStart = 0);
00251 
00257         void setIgnoreComments(bool);
00258 
00265         void setAutoTrim(bool);
00266 
00270         virtual void mark();
00271 
00275         virtual void reset();
00276 
00279         virtual int read();
00280 
00285         String getWord(const String& specialSeps = "");
00286 
00291         String getLine(bool skipEmpty = true);
00292 
00294         int getLineNumber();
00295 
00297         bool skipRestOfLine();
00298 
00300         bool eos();
00301 
00302 private:
00303         void unread(int c);
00304         int lineNum, markLineNum;
00305         String separators;
00306         char commentStart;
00307         int buf; // next char
00308         bool ignoreComments, autoTrim;
00309         bool eol; // we're at the end of the line
00310 };
00311 
00317 class OutputStream {
00318 
00319 public:
00324         virtual bool write(int b) = 0;
00325 
00329         virtual bool write(const Array<char>& b, int off, int len);
00330 
00336         virtual bool write(const Array<char>& b); // you need not override this one
00337 
00339         bool write(const char* c);
00340 
00344         virtual void flush();
00345 
00349         virtual void close();
00350 
00353         virtual bool fail(); // you need not override this one
00354 
00358         virtual ~OutputStream();
00359 
00360 protected:
00365         OutputStream();
00366 
00368         bool _fail;
00369 };
00370 
00374 class FileOutputStream : public OutputStream {
00375 
00376 public:
00383         FileOutputStream(const String& fileName, bool append = false);
00384 
00389     FileOutputStream(const File& file, bool append = false);
00390 
00392         virtual bool write(int b);
00393 
00395         virtual bool write(const Array<char>& b, int off, int len);
00396 
00397         virtual bool write(const Array<char>& b); // you need not override this one
00398 
00400         virtual void flush();
00401 
00403         virtual void close();
00404 
00405         virtual ~FileOutputStream();
00406 
00407 private:
00408 #ifdef __SYMBIAN32__
00409         RFs* session;
00410         RFile* file;
00411         void init(const String&, bool);
00412 #else
00413         void* handle;
00414 #endif
00415         bool open;
00416 };
00417 
00421 class FilterOutputStream : public OutputStream {
00422 
00423 public:
00426         FilterOutputStream(OutputStream* out);
00427 
00431         virtual bool write(int b);
00432 
00436         virtual bool write(const Array<char>& b, int off, int len);
00437 
00438         virtual bool write(const Array<char>& b); // you need not override this one
00439 
00442         virtual void flush();
00443 
00447         virtual void close();
00448 
00450         virtual ~FilterOutputStream();
00451 
00452 protected:
00454         OutputStream* out;
00455 };
00456 
00457 
00458 
00459 } // namespace
00460 
00461 #endif
00462 

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer