Advanced Strategic Command
basestrm.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of Advanced Strategic Command; http://www.asc-hq.de
8  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; see the file COPYING. If not, write to the
22  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  Boston, MA 02111-1307 USA
24 */
25 
26 #ifndef basestrmH
27 #define basestrmH
28 
29 
30 #include <string>
31 #include <stdio.h>
32 #include <time.h>
33 #include <vector>
34 #include <list>
35 #include <queue>
36 
37 #include <SDL.h>
38 
39 #include "global.h"
40 #include "basestreaminterface.h"
41 #include "lzw.h"
42 #include "errors.h"
43 
44 #include "simplestream.h"
45 
46 
47 
48 extern SDL_RWops *SDL_RWFromStream( tnstream* stream );
49 
51  SDL_RWops *rwo;
52  public:
53  RWOPS_Handler( SDL_RWops *rw ) : rwo (rw) {};
54  SDL_RWops* Get() { return rwo; };
55  void Close() { if ( rwo ) { SDL_RWclose(rwo); rwo = NULL; } };
57 };
58 
59 
60 
61 
62 const int maxFileStringSize = 10000; // is used for some character arrays
63 
64 
65 class CharBuf {
66  public:
67  int size;
68  char* buf;
69  CharBuf ( void );
70  CharBuf ( int _size );
71  void resize ( int newsize );
72  ~CharBuf();
73  };
74 
78 
79 
80 
81 
82 
83 
85  public:
86  StreamCompressionError ( const ASCString& msg, int returncode ) : ASCmsgException ( msg )
87  {
88  message += "\n the returncode is ";
89  message += strrr ( returncode );
90  };
91 };
92 
94  public:
95  int required;
96  OutOfMemoryError ( int m ) ;
97 };
98 
99 class tbufferoverflow : public ASCexception {
100 };
101 
102 
103 class tinvalidversion : public tfileerror {
104  public:
105  tinvalidversion ( const ASCString& fileName, int ex, int fnd );
106  const int expected;
107  const int found;
108  ASCString getMessage() const;
109 };
110 
111 
115 
120 template<class T>
122  protected:
123  int blksize;
124  int size;
125  T* buf;
126  virtual void resize ( int newsize );
128 
129  public:
130  dynamic_array ( void );
131  dynamic_array ( int sze );
132  virtual ~dynamic_array();
133  T& operator[]( int a );
134  int getlength( void );
135  void reset ( void );
136 };
137 
138 
142 
148 class MemoryStreamCopy : public tnstream {
149  void* buf;
150  int size;
151  int pos;
152 
153 
154  public:
155  MemoryStreamCopy ( tnstream* stream );
156  ~MemoryStreamCopy ( );
157  void writedata ( const void* buf, int size );
158  int readdata ( void* buf, int size, bool excpt = true );
159  void seek ( int newpos );
160  int getPosition ( void ) { return pos; };
161  int getSize ( void ) { return size; };
163  };
164 
165 
167 
173  friend class MemoryStream;
174 
175  bool initialized;
176 
177  int used;
178  int allocated;
179  int dummy[10];
180  Uint8* buf;
181  public:
183 
185  void writetostream ( tnstream* stream );
186 
188  void readfromstream ( tnstream* stream );
189 
190  void clear() { used= 0; };
191 
192  int getMemoryFootprint() const { return allocated; };
193 
194  const Uint8* getBuffer() const { return buf; };
195  int getSize() const { return used; };
196 
198  };
199 
204 class MemoryStream : public tnstream {
205  protected:
207  Uint8* pointer;
211 
212  public:
213  MemoryStream ( MemoryStreamStorage* lbuf, IOMode mode );
214  virtual void writedata ( const void* nbuf, int size );
215  virtual int readdata ( void* nbuf, int size, bool excpt = true );
216  int dataavail ( void );
217  };
218 
220 
221 
222 
224 
225  // ********** For writing
226  CountType LZWTotBytesIn; /* no. data bytes in input file */
227  CountType LZWTotBytesOut; /* no. data bytes in output file */
228  CountType LZWCurrBytesIn; /* no. data bytes in current frame */
229  CountType LZWCurrBytesOut; /* no. data bytes in current frame */
230  unsigned LZWBestRatio; /* best ratio we've had */
231  unsigned LZWLastRatio; /* last ratio we saw */
232 
233 
234 
235  /* structure for the data dictionary */
236  struct Wdictionary {
237  unsigned char c;
238  CodeType code;
239  CodeType parent;
240  };
241  struct Wdictionary *wdictionary;
242 
243  void LZWOut ( CodeType code );
244  IndexType LZWFind ( CodeType currcode, int in );
245 
246  // deklarationen, die in LZWencode drinwaren
247  int in;
248  CountType i;
249  CodeType currcode;
250  IndexType idx;
251 
252  int currcodeloaded;
253 
254 
255  //*********** for reading
256 
257  /* structure for data dictionary */
258  struct Rdictionary {
259  unsigned char c;
260  CodeType parent;
261  };
262 
263 
264  /* decode buffer */
265  unsigned char *decodeBuffer;
266  unsigned DecodeBufferSize ;
267 
268  unsigned int inchar;
269  unsigned count;
270  CodeType oldcode;
271 
272  /* data rdictionary */
273  struct Rdictionary *rdictionary;
274 
275  CodeType incode;
276 
277  void LZWIn ( void );
278  unsigned LZWLoadBuffer ( unsigned count, CodeType code );
279  int readcnt;
280 
281  // ******* rle uncompression
282  Uint8 rlestartbyte;
283  Uint8 rlenum;
284  Uint8 rledata;
285 
286  // ******* general
287  IndexType freecode;
288 
289  int initread;
290  int initwrite;
291  void initreading( void );
292  void initwriting( void );
293 
294  protected:
295 
296  typedef deque<Uint8> CDQ;
297  queue<Uint8,CDQ> tempbuf;
298 
301 
302  public:
303 
304  void writedata ( const void* buf, int size );
305  int readdata ( void* buf, int size, bool excpt = true );
306  virtual int readlzwdata ( void* buf, int size, bool excpt = true ) = 0;
307  virtual void writelzwdata ( const void* buf, int size ) = 0;
308  tlzwstreamcompression ( void );
309  virtual ~tlzwstreamcompression ( void );
310  protected:
311  void close( void );
312 
313 };
314 
315 
317  public:
318  virtual void writecmpdata ( const void* buf, int size ) = 0;
319  virtual int readcmpdata ( void* buf, int size, bool excpt = true ) = 0;
321  };
322 
323 
325  private:
326  tnstream* stream;
327  public:
328  CompressionStreamAdapter( tnstream* compressedStream );
329  virtual void writecmpdata ( const void* buf, int size );
330  virtual int readcmpdata ( void* buf, int size, bool excpt = true );
331 };
332 
334 
338  public:
339  void close_compression ( void );
340  void writedata ( const void* buf, int size );
342  virtual ~libbzip_compression ( );
343 
344 };
345 
347 
351  public:
352  int readdata ( void* buf, int size, bool excpt = true );
354  virtual ~libbzip_decompression ( );
355 
356 };
357 
358 
360 
361 
362 
364 
365  typedef deque<Uint8> CDQ;
366  queue<Uint8, CDQ> _queue;
367 
368  libbzip_compression* bzip_compress;
369  libbzip_decompression* bzip_decompress;
370  int mmd;
371  int status;
372 
373  protected:
374  virtual int readlzwdata ( void* buf, int size, bool excpt = true );
375  virtual void writelzwdata ( const void* buf, int size );
376  void close_compression ( void );
377 
378  public:
379  tanycompression ( int md );
380  void init ( void );
381 
382  void writedata ( const void* buf, int size );
383  int readdata ( void* buf, int size, bool excpt = true );
384  ~tanycompression ( );
385 };
386 
387 
389 
391  public:
392  tn_lzw_file_buf_stream ( const char* name, IOMode mode ) : tn_file_buf_stream ( name, mode ) , tanycompression ( mode )
393  {
395  } ;
396 
397  void writedata ( const void* buf, int size );
398  int readdata ( void* buf, int size, bool excpt = true );
399  int readcmpdata ( void* buf, int size, bool excpt = true );
400  void writecmpdata ( const void* buf, int size );
402  };
403 
404 
407 
408 
409 class tn_c_lzw_filestream : public tnstream, protected tanycompression {
410  tn_file_buf_stream *strm;
411  pncontainerstream containerstream;
412  int inp;
413  ASCString fname;
414  ASCString location;
415  protected:
416  int readcmpdata ( void* buf, int size, bool excpt = true );
417  void writecmpdata ( const void* buf, int size );
418  public:
419  tn_c_lzw_filestream ( const ASCString& name, IOMode mode );
420  void writedata ( const void* buf, int size );
421  int readdata ( void* buf, int size, bool excpt = true );
422  virtual ~tn_c_lzw_filestream ( );
423  virtual time_t get_time ( void );
424  virtual int getSize( void );
427  };
428 
431 
432 
433 
434 
436 
437 
439  char* name;
440  int start; // das erste Byte
441  int end; // das letzte Byte
442  };
443 
444 
446  public:
447  virtual void addfile ( const char* filename, const pncontainerstream stream, int directoryLevel ) = 0;
448  virtual ~ContainerIndexer() {};
449  };
450 
451 
453  tcontainerindex* index;
454  tcontainerindex* actfile;
455  int containerfilepos;
456  int num;
457 
458  int actname;
459 
460  public:
461  tncontainerstream ( const char* containerfilename, ContainerIndexer* indexer, int directoryLevel );
462  void opencontainerfile ( const char* name );
463  int getcontainerfilesize ( const char* name );
464  int readcontainerdata ( void* buf, int size, bool excpt = true );
465  void closecontainerfile ( void );
466  char* getfirstname ( void );
467  char* getnextname ( void );
468  virtual ~tncontainerstream ();
469  };
470 
472 
473 
474 
475 extern ASCString listContainer();
476 
477 
478 
479 
480 
482 
484 class tfindfile {
485 
486 
487  public:
488  struct FileInfo {
493  int size;
494  int date;
495 
496  void read ( tnstream& stream ) {
497  int version = stream.readInt();
498  if ( version != 1 )
499  throw tinvalidversion( stream.getDeviceName(), 1, version );
500 
501  name = stream.readString();
502  directoryLevel = stream.readInt();
503  isInContainer = stream.readInt() != 0;
504  location = stream.readString();
505  size = stream.readInt();
506  date = stream.readInt();
507  };
508 
509  void write ( tnstream& stream ) const {
510  stream.writeInt(1 ); // version
511  stream.writeString ( name );
512  stream.writeInt( directoryLevel );
513  stream.writeInt ( isInContainer );
514  stream.writeString ( location );
515  stream.writeInt ( size );
516  stream.writeInt ( date );
517  };
518 
519  };
520 
521  private:
522  vector<FileInfo> fileInfo;
523  int found;
524  int act;
525 
526  public:
529 
536  tfindfile ( ASCString name, SearchPosition searchPosition = DefaultDir, SearchTypes searchTypes = All);
537 
543  ASCString getnextname ( int* loc = NULL, bool* inContainer = NULL, ASCString* location = NULL );
544  bool getnextname ( FileInfo& fi );
545 
547  return found;
548  };
549 
550  };
551 
553 
558  private:
559  int shift;
560  int buf;
561 
562  ASCString result;
563  public:
565 
566  virtual void writedata ( const void* buf, int size );
567  virtual int readdata ( void* buf, int size, bool excpt = true );
568 
569  void put( Uint8 c );
570  void flush();
572 };
573 
578  private:
579  int shift;
580  int buf;
581 
582  int length;
583  ASCString data;
584 
585  int reverse[256];
586 
587  void generateTable();
588 
589  int get();
590  public:
591  ASCIIDecodingStream( const ASCString& data);
592  virtual void writedata ( const void* buf, int size );
593  virtual int readdata ( void* buffer, int size, bool excpt = true );
594 };
595 
601  CompressionStreamAdapter adapter;
602  libbzip_compression compressor;
603  bool closed;
604  public:
605  StreamCompressionFilter( tnstream* outputstream );
606  virtual void writedata ( const void* buf, int size );
607  virtual int readdata ( void* buf, int size, bool excpt = true );
608  void close();
610 };
611 
617  CompressionStreamAdapter adapter;
618  libbzip_decompression decompressor;
619 
620  public:
621  StreamDecompressionFilter( tnstream* inputstream );
622  virtual void writedata ( const void* buf, int size ) ;
623  virtual int readdata ( void* buf, int size, bool excpt = true );
624 };
625 
626 
628 
629 #include "basetemp.h"
630 
631 extern const char* asc_configurationfile;
632 extern const int maxfilenamelength;
633 
634 
635 extern int compressrle ( const void* p, void* q);
636 
640 // extern bool patimat (const char *pat, const char *str);
641 extern bool patimat (const ASCString& pat, const ASCString& str, bool forceCaseInsensitivity = false) ;
642 
643 extern int checkforvaliddirectory ( char* dir );
644 
645 extern ASCString getnextfilenumname ( const ASCString& first, const ASCString& suffix, int num = -1 );
646 
647 
648 #define writedata2(a) writedata ( &(a), sizeof(a) )
649 #define readdata2(a) readdata ( &(a), sizeof(a) )
650 
652 extern bool exist ( const ASCString& s );
653 extern time_t get_filetime ( const char* devicename );
654 
655 extern void opencontainer ( const char* wildcard );
656 
657 extern const char* containermagic;
658 
659 
660 extern const char* filereadmode;
661 extern const char* filewritemode;
662 extern const char* filereadmodetext;
663 extern const char* filewritemodetext;
664 
665 
667 class FileName : public ASCString {
668  public:
671  ASCString suffix();
672  FileName& operator= ( const ASCString& s ) { ASCString::operator=(s); return *this;};
673  FileName() {};
674  FileName( const ASCString& s ) : ASCString ( s ) {};
675 };
676 
677 
678 extern const char pathdelimitter;
679 extern const char* pathdelimitterstring;
680 extern int filesize( const char *name);
681 
682 extern void addSearchPath ( const ASCString& path );
683 extern void appendbackslash ( char* String );
684 extern void appendbackslash ( ASCString& String );
685 extern char* constructFileName( char* buf, int directoryLevel, const char* path, const char* filename );
686 extern ASCString constructFileName( int directoryLevel, const ASCString& path, ASCString filename );
687 extern bool directoryExist ( const ASCString& path );
688 extern char* extractPath ( char* buf, const char* filename );
689 extern char* extractFileName ( char* buf, const char* filename );
690 extern ASCString extractFileName ( const ASCString& filename );
691 extern ASCString extractFileName_withoutSuffix ( const ASCString& filename );
692 extern int createDirectory ( const char* name );
693 extern int getSearchPathNum();
694 extern ASCString getSearchPath ( int i );
695 extern bool isPathRelative( const ASCString& path );
696 
698 extern void convertPathDelimitters ( ASCString& path );
699 
700 
701 
702 
703 template<typename C>
704  void writePointerContainer ( const C& c, tnstream& stream )
705 {
706  stream.writeInt ( 1 );
707  stream.writeInt ( c.size() );
708  typedef typename C::const_iterator IT;
709  for ( IT i = c.begin(); i != c.end(); ++i )
710  (*i)->write ( stream );
711 }
712 
713 template<typename BaseType>
714  void readPointerContainer ( vector<BaseType*>& v, tnstream& stream )
715 {
716  stream.readInt(); // version
717  int num = stream.readInt();
718  v.clear();
719  for ( int i = 0; i < num; ++i ) {
720  BaseType* bt = new BaseType;
721  bt->read( stream );
722  v.push_back( bt );
723  }
724 }
725 
726 template<typename BaseType>
727  void readPointerContainer ( list<BaseType*>& v, tnstream& stream )
728 {
729  stream.readInt(); // version
730  int num = stream.readInt();
731  v.clear();
732  for ( int i = 0; i < num; ++i ) {
733  BaseType* bt = new BaseType;
734  bt->read( stream );
735  v.push_back( bt );
736  }
737 }
738 
739 
740 
741 template<typename C>
742  void writeClassContainer ( const C& c, tnstream& stream )
743 {
744  stream.writeInt ( 1 );
745  stream.writeInt ( c.size() );
746  typedef typename C::const_iterator IT;
747  for ( IT i = c.begin(); i != c.end(); ++i )
748  i->write ( stream );
749 }
750 
751 template<typename C>
752  void readClassContainer ( C& c, tnstream& stream )
753 {
754  int version = stream.readInt();
755  if ( version != 1 )
756  throw tinvalidversion( stream.getLocation(), 1, version );
757 
758  int num = stream.readInt();
759  c.clear();
760  for ( int i = 0; i < num; ++i ) {
761  typedef typename C::value_type VT;
762  VT vt;
763  vt.read( stream );
764  c.push_back( vt );
765  }
766 }
767 
768 template<typename C>
770 {
771  int version = stream.readInt();
772  if ( version != 1 )
773  throw tinvalidversion( stream.getLocation(), 1, version );
774 
775  int num = stream.readInt();
776  c.clear();
777  for ( int i = 0; i < num; ++i ) {
778  typedef typename C::value_type VT;
779  c.push_back( VT::newFromStream( stream ) );
780  }
781 }
782 
783 
784 template<>
785  inline void writeClassContainer<> ( const vector<ASCString>& c, tnstream& stream )
786 {
787  stream.writeInt ( 1 );
788  stream.writeInt ( c.size() );
789  typedef vector<ASCString>::const_iterator IT;
790  for ( IT i = c.begin(); i != c.end(); ++i )
791  stream.writeString(*i);
792 }
793 
794 
795 template<>
796  inline void readClassContainer<> ( vector<ASCString>& c, tnstream& stream )
797 {
798  stream.readInt(); // version
799  int num = stream.readInt();
800  c.clear();
801  for ( int i = 0; i < num; ++i )
802  c.push_back( stream.readString() );
803 }
804 
805 template<>
806  inline void writeClassContainer<> ( const vector<int>& c, tnstream& stream )
807 {
808  stream.writeInt ( 1 );
809  stream.writeInt ( c.size() );
810  typedef vector<int>::const_iterator IT;
811  for ( IT i = c.begin(); i != c.end(); ++i )
812  stream.writeInt(*i);
813 }
814 
815 
816 template<>
817  inline void readClassContainer<> ( vector<int>& c, tnstream& stream )
818 {
819  stream.readInt(); // version
820  int num = stream.readInt();
821  c.clear();
822  for ( int i = 0; i < num; ++i )
823  c.push_back ( stream.readInt() );
824 }
825 
826 template<>
827  inline void writeClassContainer<> ( const vector<pair<int,int> >& c, tnstream& stream )
828 {
829  stream.writeInt ( 1 );
830  stream.writeInt ( c.size() );
831  typedef vector<pair<int,int> >::const_iterator IT;
832  for ( IT i = c.begin(); i != c.end(); ++i ) {
833  stream.writeInt(i->first);
834  stream.writeInt(i->second );
835  }
836 }
837 
838 
839 template<>
840  inline void readClassContainer<> ( vector<pair<int,int> >& c, tnstream& stream )
841 {
842  stream.readInt(); // version
843  int num = stream.readInt();
844  c.clear();
845  for ( int i = 0; i < num; ++i ) {
846  int first = stream.readInt();
847  int second = stream.readInt();
848  c.push_back ( make_pair(first,second) );
849  }
850 }
851 
852 
853 
854 #endif
855 
int maxaccessed
Definition: basestrm.h:127
Buffers the complete contents of a stream in memory.
Definition: basestrm.h:148
int getSearchPathNum()
Definition: basestrm.cpp:2534
virtual int readcmpdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:1177
unsigned long IndexType
Definition: lzw.h:47
ASCString message
Definition: errors.h:39
dynamic_array(void)
Definition: basetemp.h:124
virtual ~tn_c_lzw_filestream()
Definition: basestrm.cpp:1718
char * extractPath(char *buf, const char *filename)
Definition: basestrm.cpp:2548
The (base-) classes which are thrown as exceptions.
An in-memory storage of streamed data.
Definition: basestrm.h:172
void convertPathDelimitters(ASCString &path)
converts path delimitters from foreign operating systems to the ones used by the current operating sy...
Definition: basestrm.cpp:2646
void readClassContainerStaticConstructor(C &c, tnstream &stream)
Definition: basestrm.h:769
void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:619
ASCString getResult()
Definition: basestrm.cpp:1786
int readcontainerdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:788
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
Compresses data transparently into another stream (using bzip2 compression)
Definition: basestrm.h:600
const char * containermagic
Definition: basestrm.cpp:86
const char * filereadmodetext
Definition: unix/fileio.cpp:21
tanycompression(int md)
Definition: basestrm.cpp:1416
tn_lzw_file_buf_stream(const char *name, IOMode mode)
Definition: basestrm.h:392
void close_compression(void)
Definition: basestrm.cpp:1519
int getSize() const
Definition: basestrm.h:195
virtual ~tncontainerstream()
Definition: basestrm.cpp:828
StreamCompressionError(const ASCString &msg, int returncode)
Definition: basestrm.h:86
void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:1575
virtual void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:1753
virtual ~libbzip_compression()
Definition: basestrm.cpp:1264
int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:1698
~RWOPS_Handler()
Definition: basestrm.h:56
const Uint8 * getBuffer() const
Definition: basestrm.h:194
int readdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:1464
virtual ASCString getLocation()
returns the location of the stream.
Definition: basestrm.cpp:274
virtual void writecmpdata(const void *buf, int size)
Definition: basestrm.cpp:1172
int dataavail(void)
Definition: basestrm.cpp:2408
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 int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:1869
virtual void resize(int newsize)
Definition: basetemp.h:147
virtual ASCString getDeviceName()
returns the name of the stream.
Definition: basestrm.cpp:269
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
char * getfirstname(void)
Definition: basestrm.cpp:811
int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:1580
void Close()
Definition: basestrm.h:55
Reading data from an ASCII encoded String.
Definition: basestrm.h:577
tn_c_lzw_filestream(const ASCString &name, IOMode mode)
Definition: basestrm.cpp:1605
tncontainerstream(const char *containerfilename, ContainerIndexer *indexer, int directoryLevel)
Definition: basestrm.cpp:715
FileName & operator=(const ASCString &s)
Definition: basestrm.h:672
MemoryStream(MemoryStreamStorage *lbuf, IOMode mode)
Definition: basestrm.cpp:2338
T & operator[](int a)
Definition: basetemp.h:165
virtual int readlzwdata(void *buf, int size, bool excpt=true)=0
void writedata(const void *buf, int size)
Definition: oldlzw.cpp:201
int getMemoryFootprint() const
Definition: basestrm.h:192
virtual ~tlzwstreamcompression(void)
Definition: oldlzw.cpp:468
void write(tnstream &stream) const
Definition: basestrm.h:509
FileName(const ASCString &s)
Definition: basestrm.h:674
unsigned long CountType
Definition: lzw.h:48
int checkforvaliddirectory(char *dir)
Definition: basestrm.cpp:2255
bool directoryExist(const ASCString &path)
Definition: basestrm.cpp:2500
virtual ~CompressionStreamInterface()
Definition: basestrm.h:320
virtual void addfile(const char *filename, const pncontainerstream stream, int directoryLevel)=0
const int maxFileStringSize
Definition: basestrm.h:62
This class handles filenames. All operations that work on filenames will be added here...
Definition: basestrm.h:667
int getlength(void)
Definition: basetemp.h:183
Global platform dependant definitions. This file just branches to the platform specific files in thei...
time_t get_filetime(const char *devicename)
Definition: basestrm.cpp:2468
The interface for all kinds of IO stream.
void close(void)
Definition: oldlzw.cpp:458
FileName()
Definition: basestrm.h:673
ASCString listContainer()
Definition: basestrm.cpp:1052
IOMode _mode
Definition: basestrm.h:208
int readdata(void *buf, int size, bool excpt=true)
Definition: oldlzw.cpp:314
tnfilestream * pnfilestream
Definition: basestrm.h:430
bool isPathRelative(const ASCString &path)
Definition: basestrm.cpp:934
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void writetostream(tnstream *stream)
persist the contents in another stream
Definition: basestrm.cpp:2303
bool exist(const ASCString &s)
does a file s exist (wildcards allowed)
Definition: basestrm.cpp:2444
SearchPosition
Definition: basestrm.h:527
CharBuf(void)
Definition: basestrm.cpp:100
tlzwstreamcompression(void)
Definition: oldlzw.cpp:34
virtual int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:1758
ASCString & operator=(const ASCAdaptatorString &s)
Definition: ascstring.h:256
ASCString getArchive()
returns the archive name if the stream is located inside an archive; or "" if not.
Definition: basestrm.cpp:1654
Deompresses data from a compressed stream (using bzip2 compression)
Definition: basestrm.h:616
SDL_RWops * SDL_RWFromStream(tnstream *stream)
Definition: basestrm.cpp:693
virtual void writecmpdata(const void *buf, int size)=0
int getPosition(void)
Definition: basestrm.h:160
void writedata(const void *buf, int size)
Definition: basestrm.cpp:1483
virtual void writeString(const string &pc, bool binary=true)
writes the C++ String pc to the stream.
Definition: basestrm.cpp:545
virtual ~dynamic_array()
Definition: basetemp.h:177
OutOfMemoryError(int m)
Definition: basestrm.cpp:136
int readdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:1303
CompressionStreamAdapter(tnstream *compressedStream)
Definition: basestrm.cpp:1168
Uint8 * pointer
Definition: basestrm.h:207
~CharBuf()
Definition: basestrm.cpp:123
tinvalidversion(const ASCString &fileName, int ex, int fnd)
Definition: basestrm.cpp:171
void resize(int newsize)
Definition: basestrm.cpp:113
char * strrr(int a)
converts a to a string.
Definition: misc.cpp:66
virtual int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:1898
virtual int readlzwdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:1490
char * buf
Definition: basestrm.h:68
int getcontainerfilesize(const char *name)
Definition: basestrm.cpp:753
void put(Uint8 c)
Definition: basestrm.cpp:1762
void close_compression(void)
Definition: basestrm.cpp:1238
const char * filereadmode
Definition: unix/fileio.cpp:19
Reads data from or writes data to a MemoryStreamStorage This allows a completely volatile storage of ...
Definition: basestrm.h:204
int actmempos
Definition: basestrm.h:209
int getSize(void)
returns the size of the stream or -1 if the stream does not have a size
Definition: basestrm.h:161
libbzip_compression(CompressionStreamInterface *strm)
Definition: basestrm.cpp:1200
void readPointerContainer(vector< BaseType * > &v, tnstream &stream)
Definition: basestrm.h:714
Searching for files.
Definition: basestrm.h:484
ASCString name
Definition: basestrm.h:489
char * constructFileName(char *buf, int directoryLevel, const char *path, const char *filename)
Definition: basestrm.cpp:873
tfindfile(ASCString name, SearchPosition searchPosition=DefaultDir, SearchTypes searchTypes=All)
Searches for files matching the wildcard name in all search paths specified for ASC and inside the AS...
Definition: basestrm.cpp:2030
void init(void)
Definition: basestrm.cpp:1423
ASCString location
Definition: basestrm.h:492
unsigned short CodeType
Definition: lzw.h:46
ASCString extractFileName_withoutSuffix(const ASCString &filename)
Definition: basestrm.cpp:2585
ASCString getLocation()
returns the location of the stream.
Definition: basestrm.cpp:1663
void read(tnstream &stream)
Definition: basestrm.h:496
libbzip_decompression(CompressionStreamInterface *strm)
Definition: basestrm.cpp:1295
SDL_RWops * Get()
Definition: basestrm.h:54
const char pathdelimitter
Definition: unix/fileio.cpp:23
ASCString suffix()
return the suffix of the file or an empty string if the file doesn't have a suffix.
Definition: basestrm.cpp:2631
int createDirectory(const char *name)
Definition: basestrm.cpp:2609
virtual int readcmpdata(void *buf, int size, bool excpt=true)=0
virtual int readdata(void *buffer, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:1827
virtual int getSize(void)
returns the size of the stream or -1 if the stream does not have a size
Definition: basestrm.cpp:1668
void readClassContainer(C &c, tnstream &stream)
Definition: basestrm.h:752
deque< Uint8 > CDQ
Definition: basestrm.h:296
virtual int readdata(void *nbuf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:2391
virtual void writelzwdata(const void *buf, int size)=0
int blocksize
Definition: basestrm.h:206
const char * pathdelimitterstring
Definition: unix/fileio.cpp:24
const char * asc_configurationfile
Definition: unix/fileio.cpp:29
DEPRECATED Use containers of the C++ Standard Template Library instead! Container for managing object...
Definition: basestrm.h:121
ASCString getSearchPath(int i)
Definition: basestrm.cpp:2539
void opencontainer(const char *wildcard)
Definition: basestrm.cpp:2457
char * getnextname(void)
Definition: basestrm.cpp:817
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
class tncontainerstream * pncontainerstream
Definition: basestrm.h:406
virtual void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:1893
MemoryStreamStorage * buf
Definition: basestrm.h:210
int compressrle(const void *p, void *q)
Definition: basestrm.cpp:1904
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:644
int readdata(void *buf, int size, bool excpt=true)
Reads data from the stream.
Definition: basestrm.cpp:624
virtual ~libbzip_decompression()
Definition: basestrm.cpp:1364
const char * filewritemode
Definition: unix/fileio.cpp:20
ASCIIDecodingStream(const ASCString &data)
Definition: basestrm.cpp:1816
tn_c_lzw_filestream tnfilestream
Definition: basestrm.h:429
void readfromstream(tnstream *stream)
read persisted contents from another stream
Definition: basestrm.cpp:2316
virtual void writedata(const void *nbuf, int size)
writes data to the stream
Definition: basestrm.cpp:2371
int readcmpdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:1684
virtual time_t get_time(void)
Definition: basestrm.cpp:1710
ASCString getMessage() const
Definition: basestrm.cpp:176
int size
Definition: basestrm.h:67
queue< Uint8, CDQ > tempbuf
Definition: basestrm.h:297
void writeClassContainer(const C &c, tnstream &stream)
Definition: basestrm.h:742
RWOPS_Handler(SDL_RWops *rw)
Definition: basestrm.h:53
Data written to this stream will be encoded similar to base64 and can be retrieved as a string...
Definition: basestrm.h:557
const char * filewritemodetext
Definition: unix/fileio.cpp:22
virtual ~ContainerIndexer()
Definition: basestrm.h:448
int getFoundFileNum()
Definition: basestrm.h:546
void closecontainerfile(void)
Definition: basestrm.cpp:806
StreamCompressionFilter(tnstream *outputstream)
Definition: basestrm.cpp:1859
int readcmpdata(void *buf, int size, bool excpt=true)
Definition: basestrm.cpp:1585
void writedata(const void *buf, int size)
Definition: basestrm.cpp:1209
int filesize(const char *name)
Definition: basestrm.cpp:2489
void appendbackslash(char *String)
Definition: basestrm.cpp:2596
void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:1693
MemoryStreamCopy(tnstream *stream)
Definition: basestrm.cpp:578
void reset(void)
Definition: basetemp.h:141
bool patimat(const ASCString &pat, const ASCString &str, bool forceCaseInsensitivity=false)
checks whether the regular expression pat matches the string str .
Definition: basestrm.cpp:2024
ASCString getnextfilenumname(const ASCString &first, const ASCString &suffix, int num=-1)
Definition: basestrm.cpp:2418
const int maxfilenamelength
Definition: unix/fileio.cpp:28
void writecmpdata(const void *buf, int size)
Definition: basestrm.cpp:1590
virtual void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:1864
ASCString getLocation()
returns the location of the stream.
Definition: basestrm.cpp:607
void writecmpdata(const void *buf, int size)
Definition: basestrm.cpp:1676
void addSearchPath(const ASCString &path)
Definition: basestrm.cpp:2517
IOMode
the modes in which a stream can operate
char * extractFileName(char *buf, const char *filename)
Definition: basestrm.cpp:2564
The standard interface for ASC streams. This is the parent class for all kinds of streams: normal fil...
const int found
Definition: basestrm.h:107
void writePointerContainer(const C &c, tnstream &stream)
Definition: basestrm.h:704
StreamDecompressionFilter(tnstream *inputstream)
Definition: basestrm.cpp:1889
void opencontainerfile(const char *name)
Definition: basestrm.cpp:767
const int expected
Definition: basestrm.h:106
virtual void writelzwdata(const void *buf, int size)
Definition: basestrm.cpp:1513
virtual void writedata(const void *buf, int size)
writes data to the stream
Definition: basestrm.cpp:1822