home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / 02 < prev    next >
Encoding:
Text File  |  1992-06-07  |  4.0 KB  |  126 lines

  1. #ifndef __RWFILE_H__
  2. #define __RWFILE_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * Class RWFile encapsulates ANSI-C binary file operations.   
  7.  *
  8.  * $Header:   E:/vcs/rw/rwfile.h_v   1.5   18 Feb 1992 09:54:38   KEFFER  $
  9.  *
  10.  ****************************************************************************
  11.  *
  12.  * Rogue Wave 
  13.  * P.O. Box 2328
  14.  * Corvallis, OR 97339
  15.  * Voice: (503) 754-3010    FAX: (503) 757-6650
  16.  *
  17.  * Copyright (C) 1991. This software is subject to copyright 
  18.  * protection under the laws of the United States and other countries.
  19.  *
  20.  ***************************************************************************
  21.  *
  22.  * $Log:   E:/vcs/rw/rwfile.h_v  $
  23.  * 
  24.  *    Rev 1.5   18 Feb 1992 09:54:38   KEFFER
  25.  * 
  26.  *    Rev 1.4   17 Oct 1991 09:12:56   keffer
  27.  * Changed include path to <rw/xxx.h>
  28.  * 
  29.  *    Rev 1.2   29 Jul 1991 11:03:38   keffer
  30.  * Made Exists(const char*) a static function.
  31.  * 
  32.  *    Rev 1.1   24 Jul 1991 13:06:48   keffer
  33.  * Added pvcs keywords
  34.  */
  35.  
  36. /*
  37.  * Under Unix, there there is no difference between text and binary 
  38.  * files.  However, under MS-DOS, and some other operating systems, 
  39.  * files opened for *text* output will use a CR/LF convention to end 
  40.  * text lines, but do nothing for binary files.  Because RWFile is 
  41.  * intended to model *binary* files, we must shut off this translation.
  42.  * This requires opening the file in an explicit "binary" mode.  
  43.  * This situation is detected by the macro "CRLF_CONVENTION".
  44.  */
  45.  
  46. #include "rw/defs.h"
  47. STARTWRAP
  48. #include <stdio.h>
  49. ENDWRAP
  50.  
  51. class RWExport RWFile {
  52. protected:
  53.   char*            filename;
  54.   FILE*            filep;
  55. public:
  56.   RWFile(const char* name);
  57.   ~RWFile();
  58.        
  59.   const char*        GetName()    {return filename;}
  60.   RWBoolean         Exists();
  61.   static RWBoolean     Exists(const char* name);
  62.        
  63.   RWBoolean         Read(char& c);    
  64.   RWBoolean         Read(short& i);
  65.   RWBoolean         Read(int& i);
  66.   RWBoolean         Read(long& i);
  67. #ifndef CHAR_MATCHES_UCHAR
  68.   RWBoolean         Read(unsigned char& c);
  69. #endif
  70.   RWBoolean         Read(unsigned short& i);
  71.   RWBoolean         Read(unsigned int& i);
  72.   RWBoolean         Read(unsigned long& i);
  73.   RWBoolean         Read(float& f);
  74.   RWBoolean         Read(double& d);
  75.   RWBoolean        Read(char* c, int N);
  76.   RWBoolean         Read(short* i, int N);
  77.   RWBoolean         Read(int* i, int N);
  78.   RWBoolean        Read(long* i, int N);
  79. #ifndef CHAR_MATCHES_UCHAR
  80.   RWBoolean        Read(unsigned char* c, int N){return Read((char*)c, N);}
  81. #endif
  82.   RWBoolean        Read(unsigned int* i, int N) {return Read(( int*)i, N);}
  83.   RWBoolean        Read(float* f, int N);
  84.   RWBoolean        Read(double* d, int N);
  85.  
  86.   // Read to null terminator or EOF; no CR/LF translation will be done. Beware of overflow.
  87.   RWBoolean        Read(char* string);    
  88.   
  89.   RWBoolean        Write(char c);
  90.   RWBoolean        Write(short s);
  91.   RWBoolean        Write(int i);
  92.   RWBoolean        Write(long l);
  93. #ifndef CHAR_MATCHES_UCHAR
  94.   RWBoolean        Write(unsigned char c);
  95. #endif
  96.   RWBoolean        Write(unsigned short s);
  97.   RWBoolean        Write(unsigned int i);
  98.   RWBoolean        Write(unsigned long l);
  99.   RWBoolean        Write(float f);
  100.   RWBoolean        Write(double d);
  101.   RWBoolean        Write(const char* string);
  102.   RWBoolean        Write(const short* i, int N);
  103.   RWBoolean        Write(const int* i, int N);
  104.   RWBoolean        Write(const long* i, int N);
  105. #ifndef CHAR_MATCHES_UCHAR
  106.   RWBoolean        Write(const unsigned char* c, int N){return Write((const char*)c, N);}
  107. #endif
  108.   RWBoolean        Write(const unsigned int*  i, int N){return Write((const  int*)i, N);}
  109.   RWBoolean        Write(const float* f, int N);
  110.   RWBoolean        Write(const double* d, int N);
  111.   RWBoolean        Write(const char* string, int N);
  112.   
  113.   long            CurOffset(); // Returns current offset of file
  114.   RWBoolean        Eof();         // TRUE if file at EOF
  115.   RWBoolean        Erase();
  116.   RWBoolean        Error();     // TRUE if the file has had an error.
  117.   RWBoolean        Flush();     // Writes all pending output
  118.   RWBoolean        IsEmpty();   // TRUE if the file is empty
  119.   RWBoolean        SeekTo(long offset); /* offset bytes from beginning of file */
  120.   RWBoolean        SeekToBegin()    {return SeekTo(0);}
  121.   RWBoolean        SeekToEnd();
  122. };
  123.  
  124. pragma pop_align_members();
  125. #endif  /* __RWFILE_H__ */
  126.