Advanced Strategic Command
basestreaminterface.h
Go to the documentation of this file.
1 /***************************************************************************
2  basestreaminterface.h - description
3  -------------------
4  begin : Sat Oct 14 2000
5  copyright : (C) 2000 by Martin Bickel
6  email : bickel@asc-hq.org
7  ***************************************************************************/
8 
15 /***************************************************************************
16  * *
17  * This program is free software; you can redistribute it and/or modify *
18  * it under the terms of the GNU General Public License as published by *
19  * the Free Software Foundation; either version 2 of the License, or *
20  * (at your option) any later version. *
21  * *
22  ***************************************************************************/
23 
24 #ifndef basestreaminterface_h_included
25  #define basestreaminterface_h_included
26 
27 #include <bitset>
28 #include <SDL_stdinc.h>
29  #include "global.h"
30 
31  #include "ascstring.h"
32 
35  class tnstream {
36  public:
37  tnstream ( );
38 
41 
46  virtual void writedata ( const void* buf, int size ) = 0 ;
47 
55  virtual int readdata ( void* buf, int size, bool excpt = true ) = 0 ;
56 
66  virtual void readpchar( char** pc, int maxlength = 0) ;
67 
77  virtual void readpnchar( char** pc, int maxlength = 0) ;
78 
86  virtual bool readTextString ( ASCString& s, bool includeCR = false );
87 
95  virtual ASCString readString ( bool includeCR = false );
96 
98  virtual void writepchar( const char* pc) ;
99 
105  virtual void writeString( const string& pc, bool binary = true ) ;
106 
108  virtual int readInt ( void );
109 
111  virtual int readWord ( void );
112 
114  virtual Uint8 readUint8 ( void );
115 
117  virtual char readCharacter ( void );
118 
119  template<size_t N>
120  void writeBitset( const std::bitset<N>& bs ) {
121  writeInt(1);
122  writeInt(N);
123  for( int i = 0; i < N;++i)
124  writeUint8( bs.test(i));
125  }
126 
127  template<size_t N>
128  void readBitset( std::bitset<N>& bs ) {
129  readInt(); // version
130  int n = readInt();
131  assert( n == N );
132  bs.reset();
133  for( int i = 0; i < N;++i)
134  if ( readUint8() )
135  bs.set( i );
136  }
137 
138 
140  virtual float readFloat ( void );
141 
143  virtual void writeInt ( int i );
144  virtual void writeInt ( unsigned int i );
145  void writeInt ( bool b );
146 
147  #ifdef SIZE_T_not_identical_to_INT
148  void writeInt ( size_t i );
150  #endif
151 
152 
154  virtual void writeWord ( int w );
155 
157  virtual void writeUint8 ( Uint8 c );
158 
160  virtual void writeCharacter ( char c );
161 
163  virtual void writeFloat ( float f );
164 
166  virtual void writerlepict ( const void* buf );
167 
169  virtual void writeImage ( const void* buf, bool compress = true );
170 
171 
178  virtual void readrlepict( void** pnter, bool allocated, int* size);
179 
181  virtual ASCString getDeviceName();
182 
185  virtual ASCString getLocation();
186 
188  virtual ASCString getArchive();
189 
191  virtual void seek ( int newpos );
192 
194  virtual int getSize ( void ) { return -1; };
195 
196  virtual ~tnstream() {};
197  protected:
199 };
200 
201 
202 
203 #endif // basestreaminterface_h_included
virtual void seek(int newpos)
Sets the stream pointer to a new location. An exception is thrown if the stream does not support seek...
Definition: basestrm.cpp:197
virtual void writeInt(int i)
Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is p...
Definition: basestrm.cpp:363
void writeBitset(const std::bitset< N > &bs)
virtual ASCString getLocation()
returns the location of the stream.
Definition: basestrm.cpp:274
virtual int readInt(void)
Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is pe...
Definition: basestrm.cpp:284
virtual ASCString getDeviceName()
returns the name of the stream.
Definition: basestrm.cpp:269
virtual void readrlepict(void **pnter, bool allocated, int *size)
Writes an RLE compressed or uncompressed image from the stream.
Definition: basestrm.cpp:202
virtual int readWord(void)
Reads a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is ...
Definition: basestrm.cpp:291
Global platform dependant definitions. This file just branches to the platform specific files in thei...
The interface for all kinds of IO stream.
virtual Uint8 readUint8(void)
Reads a 8 bit unsigned Integer.
Definition: basestrm.cpp:305
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
ASCString devicename
virtual void writerlepict(const void *buf)
Writes an image to the stream and compresses it using RLE.
Definition: basestrm.cpp:236
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
virtual float readFloat(void)
Reads a flaot variable.
Definition: basestrm.cpp:328
virtual void writeImage(const void *buf, bool compress=true)
Writes an image to the stream.
Definition: basestrm.cpp:241
virtual void writeUint8(Uint8 c)
Writes a 8 bit unsigned Integer.
Definition: basestrm.cpp:380
virtual int readdata(void *buf, int size, bool excpt=true)=0
Reads data from the stream.
virtual void writeCharacter(char c)
Writes a 8 bit character.
Definition: basestrm.cpp:375
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
void readBitset(std::bitset< N > &bs)
virtual void readpnchar(char **pc, int maxlength=0)
Reads a string.
Definition: basestrm.cpp:440
virtual ASCString getArchive()
returns the archive name if the stream is located inside an archive; or "" if not.
Definition: basestrm.cpp:279
virtual void writeFloat(float f)
Write a floating point variable.
Definition: basestrm.cpp:385
virtual void writeWord(int w)
Writes a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is...
Definition: basestrm.cpp:369
virtual void readpchar(char **pc, int maxlength=0)
Reads a string.
Definition: basestrm.cpp:390
virtual char readCharacter(void)
Read a 8 bit character.
Definition: basestrm.cpp:298
Definition: weatherarea.h:85
virtual void writepchar(const char *pc)
write the C-String pc to the stream
Definition: basestrm.cpp:554
virtual int getSize(void)
returns the size of the stream or -1 if the stream does not have a size
virtual bool readTextString(ASCString &s, bool includeCR=false)
Reads a string.
Definition: basestrm.cpp:511
IOMode
the modes in which a stream can operate
virtual void writedata(const void *buf, int size)=0
writes data to the stream
virtual ~tnstream()