home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gxxinc.lzh / GXXINC / XSFILE.H < prev    next >
C/C++ Source or Header  |  1991-07-06  |  2KB  |  89 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Doug Lea (dl@rocky.oswego.edu)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23.  
  24. #ifndef _SFile_h
  25. #ifdef __GNUG__
  26. #pragma once
  27. #pragma interface
  28. #endif
  29. #define _SFile_h 1
  30.  
  31. #include <xfile.h>
  32.  
  33. class SFile: public File
  34. {
  35. protected:
  36.   int       sz;                   // unit size for structured binary IO
  37.  
  38. public:
  39.             SFile();
  40.             SFile(const char* filename, int size, io_mode m, access_mode a);
  41.             SFile(const char* filename, int size, const char* m);
  42.             SFile(int filedesc, int size, io_mode m);
  43.             SFile(FILE* fileptr,  int size);
  44.  
  45.             ~SFile();
  46.  
  47.   int       size();
  48.   int       setsize(int s);
  49.  
  50.   SFile&    get(void* x);
  51.   SFile&    put(void* x);
  52.   SFile&    operator[](long i);
  53. };
  54.  
  55. #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
  56.  
  57.  
  58. inline  int SFile::size()
  59.   return sz; 
  60. }          
  61.  
  62. inline  int SFile::setsize(int s)
  63.   int old = sz; 
  64.   sz = s;  
  65.   return old; 
  66. }
  67.  
  68. inline  SFile& SFile::get(void* x)
  69.   read(x, sz, 1);  return *this; 
  70. }
  71.  
  72. inline  SFile& SFile::put(void* x)
  73.   write(x, sz, 1);  return *this; 
  74. }
  75.  
  76. inline SFile&  SFile::operator[](long i)
  77.   seek(i * sz, 0);  return *this; 
  78. }
  79.  
  80.  
  81. #endif
  82.  
  83. #endif
  84.