home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / examples / add / baserel / ios.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  6.4 KB  |  263 lines

  1. /*-- Rev Header - do NOT edit!
  2.  *
  3.  *  Filename : ios.h
  4.  *  Purpose  : (Erst einmal) Ersatz von ios, e.g. used in cin/cout
  5.  *
  6.  *  Program  : -
  7.  *  Author   : Gerhard Müller
  8.  *  Copyright: (c) by Gerhard Müller
  9.  *  Creation :
  10.  *
  11.  *  compile  : make
  12.  *
  13.  *  Compile version  : 0.1
  14.  *  Ext. Version     : 0.1
  15.  *
  16.  *  REVISION HISTORY
  17.  *
  18.  *  Date                     Comment
  19.  *  ------------------------ -------------------------------------------------
  20.  *  Fri Sep 17 00:49:09 1993 Took from libg++, notice copyrights there
  21.  *                           Only raw implementation, but works
  22.  *                           (nearly nothing is supported, tough)
  23.  *
  24.  *-- REV_END --
  25.  */
  26.  
  27. #ifndef ADD_IOS_H
  28. #define ADD_IOS_H
  29.  
  30.     /*
  31.      * C-Includes, C-Definitionen
  32.      *
  33.      */
  34.  
  35. #define class _class
  36. #define template _template
  37.  
  38. extern "C" {
  39. #include <exec/types.h>
  40. #include <dos/dos.h>
  41. #include <dos/dosextens.h>
  42. #include <clib/alib_protos.h>
  43. #include <clib/alib_stdio_protos.h>
  44. #include <inline/stubs.h>
  45. #ifdef __OPTIMIZE__
  46. #include <inline/exec.h>
  47. #include <inline/dos.h>
  48. #else
  49. #include <clib/exec_protos.h>
  50. #include <clib/dos_protos.h>
  51. #endif
  52.  
  53. /* #include <ctype.h> */
  54. }
  55.  
  56. #undef template
  57. #undef class
  58.  
  59.  
  60. typedef unsigned long __fmtflags;
  61. typedef unsigned char __iostate;
  62.  
  63.  
  64. struct _ios_fields { // The data members of an ios.
  65.  
  66. //  streambuf *_strbuf;
  67. //  ostream* _tie;
  68.  
  69.     BPTR _fh;
  70.     BPTR _tie;
  71.  
  72. //  int _width;
  73.     __fmtflags _flags;
  74. //  _G_wchar_t _fill;
  75.     __iostate _state;
  76. //  __iostate _exceptions;
  77. //  int _precision;
  78. };
  79.  
  80.  
  81.  
  82. #define _IOS_GOOD    0
  83. #define _IOS_EOF    1
  84. #define _IOS_FAIL    2
  85. #define _IOS_BAD    4
  86.  
  87. //#define _IOS_INPUT    1
  88. //#define _IOS_OUTPUT    2
  89. //#define _IOS_ATEND    4
  90. //#define _IOS_APPEND    8
  91. //#define _IOS_TRUNC    16
  92. //#define _IOS_NOCREATE    32
  93. //#define _IOS_NOREPLACE    64
  94. //#define _IOS_BIN    128
  95.  
  96.  
  97. class ios : public _ios_fields {
  98.   public:
  99.  
  100.     typedef __fmtflags fmtflags;
  101.     typedef int iostate;
  102. //  typedef int openmode;
  103. //  typedef int streamsize;
  104.  
  105.     enum io_state {
  106.     goodbit = _IOS_GOOD,
  107.     eofbit = _IOS_EOF,
  108.     failbit = _IOS_FAIL,
  109.     badbit = _IOS_BAD };
  110.  
  111. //  enum open_mode {
  112. //    in = _IOS_INPUT,
  113. //    out = _IOS_OUTPUT,
  114. //    ate = _IOS_ATEND,
  115. //    app = _IOS_APPEND,
  116. //    trunc = _IOS_TRUNC,
  117. //    nocreate = _IOS_NOCREATE,
  118. //    noreplace = _IOS_NOREPLACE,
  119. //    bin = _IOS_BIN };
  120.  
  121.     enum seek_dir { beg, cur, end};
  122.     // ANSI: typedef enum seek_dir seekdir; etc
  123.  
  124.     enum {
  125.        skipws=01, left=02, right=04, internal=010,
  126. //       dec=020, oct=040, hex=0100,
  127. //       showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
  128. //       scientific=04000, fixed=010000, unitbuf=020000, stdio=040000,
  129.        dont_close=0100000 //Don't delete streambuf on stream destruction
  130.        };
  131.  
  132. //  enum { // Masks.
  133. //    basefield=dec+oct+hex,
  134. //    floatfield = scientific+fixed,
  135. //    adjustfield = left+right+internal
  136. //  };
  137.  
  138.     BPTR tie() const { return _tie; }
  139.     BPTR tie(BPTR fh) { BPTR save=_tie; _tie=fh; return save; }
  140.  
  141.     // Methods to change the format state.
  142.  
  143. //  _G_wchar_t fill() const { return (_G_wchar_t)_fill; }
  144. //  _G_wchar_t fill(_G_wchar_t newf)
  145. //    {_G_wchar_t oldf = (_G_wchar_t)_fill; _fill = (char)newf; return oldf;}
  146.  
  147.     fmtflags flags() const { return _flags; }
  148.  
  149.     fmtflags flags(fmtflags new_val) {
  150.     fmtflags old_val = _flags; _flags = new_val; return old_val; }
  151.  
  152. //  int precision() const { return _precision; }
  153.  
  154. //  int precision(int newp) {
  155. //    unsigned short oldp = _precision; _precision = (unsigned short)newp;
  156. //    return oldp; }
  157.  
  158.     fmtflags setf(fmtflags val) {
  159.     fmtflags oldbits = _flags;
  160.     _flags |= val; return oldbits; }
  161.  
  162.     fmtflags setf(fmtflags val, fmtflags mask) {
  163.     fmtflags oldbits = _flags;
  164.     _flags = (_flags & ~mask) | (val & mask); return oldbits; }
  165.  
  166.     fmtflags unsetf(fmtflags mask) {
  167.     fmtflags oldbits = _flags & mask;
  168.     _flags &= ~mask; return oldbits; }
  169.  
  170. //  int width() const { return _width; }
  171. //  int width(int val) { int save = _width; _width = val; return save; }
  172.  
  173. //  streambuf* rdbuf() const { return _strbuf; }
  174.  
  175.     void clear(iostate state = 0) {
  176.     _state = _fh ? state : state|badbit;
  177. //    if (_state & _exceptions) _throw_failure();
  178.      }
  179.  
  180.     void set(iostate flag) { _state |= flag;
  181. //    if (_state & _exceptions) _throw_failure();
  182.     }
  183.  
  184.     void setstate(iostate flag) { _state |= flag; // ANSI
  185. //    if (_state & _exceptions) _throw_failure();
  186.     }
  187.  
  188.     int good() const { return _state == 0; }
  189.  
  190.     int eof() const { return _state & ios::eofbit; }
  191.  
  192.     int fail() const { return _state & (ios::badbit|ios::failbit); }
  193.  
  194.     int bad() const { return _state & ios::badbit; }
  195.  
  196.     iostate rdstate() const { return _state; }
  197.  
  198.     operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
  199.     int operator!() const { return fail(); }
  200. //  iostate exceptions() const { return _exceptions; }
  201. //  void exceptions(iostate enable) {
  202. //    _exceptions = enable;
  203. //    if (_state & _exceptions) _throw_failure(); }
  204.  
  205. //  static int sync_with_stdio(int on);
  206. //  static void sync_with_stdio() { sync_with_stdio(1); }
  207.  
  208.  
  209. //  // Used to initialize standard streams. Not needed in this implementation.
  210. //  class Init {
  211. //  public:
  212. //  Init () { }
  213. //  };
  214.  
  215. protected:
  216.     ios(BPTR fh = 0, BPTR tie = 0);
  217.     ~ios();
  218. //  virtual ~ios();
  219. //  void init(streambuf* sb) { _state=0; _strbuf=sb; }
  220. };
  221.  
  222. typedef int _seek_dir;
  223.  
  224. // Magic numbers and bits for the _flags field.
  225. // The magic numbers use the high-order bits of _flags;
  226. // the remaining bits are abailable for variable flags.
  227. // Note: The magic numbers must all be negative if stdio
  228. // emulation is desired.
  229.  
  230. //#define _IO_MAGIC 0xFBAD0000 /* Magic number */
  231. //#define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
  232. //#define _IO_MAGIC_MASK 0xFFFF0000
  233. //#define _S_USER_BUF 1 /* User owns buffer; don't delete it on close. */
  234. //#define _S_UNBUFFERED 2
  235. #define _S_NO_READS 4 /* Reading not allowed */
  236. #define _S_NO_WRITES 8 /* Writing not allowd */
  237. #define _S_EOF_SEEN 0x10
  238. #define _S_ERR_SEEN 0x20
  239. #define _S_DELETE_DONT_CLOSE 0x40
  240. //#define _S_LINKED 0x80 // Set if linked (using _chain) to streambuf::_list_all.
  241. //#define _S_IN_BACKUP 0x100
  242. //#define _S_LINE_BUF 0x200
  243. //#define _S_TIED_PUT_GET 0x400 // Set if put and get pointer logicly tied.
  244. //#define _S_CURRENTLY_PUTTING 0x800
  245. //#define _S_IS_APPENDING 0x1000
  246. //#define _S_IS_BACKUPBUF 0x4000
  247. //#define _S_IS_FILEBUF 0x8000
  248.  
  249. inline ios::ios(BPTR fh=0, BPTR tie_to = 0 ) {
  250.         _state = fh ? ios::goodbit : ios::badbit; // _exceptions=0;
  251.         _fh = fh; _tie = tie_to; // _width=0; _fill=' ';
  252.         //_flags=ios::skipws|ios::dec; // _precision=6;
  253.         _flags=0;
  254.          }
  255.  
  256. inline ios::~ios()
  257. {
  258.     if (! (_flags & (unsigned int)ios::dont_close) )
  259.         if(_fh) Close(_fh);
  260. }
  261.  
  262. #endif    /* ADD_IOS_H */
  263.