Advanced Strategic Command
simplestream.h
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 #ifndef simplestreamH
22 #define simplestreamH
23 
24 #include <time.h>
25 #include "ascstring.h"
26 #include "errors.h"
27 #include "basestreaminterface.h"
28 
29 class tnbufstream : public tnstream {
30  int datalen;
31 
32  protected:
33  Uint8* zeiger;
35  int actmempos;
36  int memsize;
37  int datasize;
38 
39  virtual void readbuffer( void ) = 0;
40  virtual void writebuffer( void ) = 0;
41  virtual void close( void ) {};
42  public:
43  tnbufstream ( );
44  virtual void writedata ( const void* buf, int size );
45  virtual int readdata ( void* buf, int size, bool excpt = true );
46 
47  virtual ~tnbufstream ( );
48 
49  };
50 
52  FILE* fp;
53  int actfilepos;
54 
55  bool sizeCached;
56  int sizeValue;
57  bool timeCached;
58  int timeValue;
59 
60 
61  protected:
62  void readbuffer( void );
63  void writebuffer( void );
64 
65 
66  public:
67  tn_file_buf_stream ( const ASCString& _fileName, IOMode mode );
68  virtual void seek ( int newpos );
69  virtual int getstreamsize ( void );
70  virtual int getSize ( void ) { return getstreamsize(); };
71  virtual time_t get_time ( void );
72  virtual ~tn_file_buf_stream( );
73  };
74 
75 
76 class tfileerror : public ASCexception {
77  ASCString _filename;
78  public:
79  tfileerror ( const ASCString& fileName ) ;
80  const ASCString& getFileName() const { return _filename; };
81  tfileerror ( void ) {};
82 };
83 
84 class tinvalidmode : public tfileerror {
85  public:
87  tinvalidmode ( const ASCString& fileName, tnstream::IOMode org_mode, tnstream::IOMode requested_mode ) ;
88 };
89 
90 class treadafterend : public tfileerror {
91  public:
92  treadafterend ( const ASCString& fileName );
93 };
94 
96  int linenum;
97  const char* sourcefilename;
98  public:
99  tinternalerror ( const char* filename, int l );
100 };
101 
102 
103 #endif
The (base-) classes which are thrown as exceptions.
tinternalerror(const char *filename, int l)
Definition: basestrm.cpp:163
tn_file_buf_stream(const ASCString &_fileName, IOMode mode)
const ASCString & getFileName() const
Definition: simplestream.h:80
IOMode _mode
Definition: simplestream.h:34
virtual void writedata(const void *buf, int size)
writes data to the stream
void writebuffer(void)
virtual int getSize(void)
returns the size of the stream or -1 if the stream does not have a size
Definition: simplestream.h:70
The interface for all kinds of IO stream.
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
virtual time_t get_time(void)
treadafterend(const ASCString &fileName)
Definition: basestrm.cpp:156
Uint8 * zeiger
Definition: simplestream.h:33
tinvalidmode(const ASCString &fileName, tnstream::IOMode org_mode, tnstream::IOMode requested_mode)
Definition: basestrm.cpp:147
virtual void readbuffer(void)=0
virtual void writebuffer(void)=0
Definition: basestrm.cpp:2454
virtual void seek(int newpos)
Sets the stream pointer to a new location. An exception is thrown if the stream does not support seek...
virtual void close(void)
Definition: simplestream.h:41
virtual ~tnbufstream()
tfileerror(void)
Definition: simplestream.h:81
virtual int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
virtual int getstreamsize(void)
IOMode
the modes in which a stream can operate
The standard interface for ASC streams. This is the parent class for all kinds of streams: normal fil...
virtual ~tn_file_buf_stream()