home *** CD-ROM | disk | FTP | other *** search
- /*-- Rev Header - do NOT edit!
- *
- * Filename : couta.h
- * Purpose : (Erst einmal) Ersatz von ostream, e.g. cout
- *
- * Program : -
- * Author : Gerhard Müller
- * Copyright: (c) by Gerhard Müller
- * Creation :
- *
- * compile : make
- *
- * Compile version : 0.1
- * Ext. Version : 0.1
- *
- * REVISION HISTORY
- *
- * Date Comment
- * ------------------------ -------------------------------------------------
- * Fri Sep 17 00:44:16 1993 Seems to work, some part of ios is supported
- *
- *-- REV_END --
- */
-
- #ifndef ADD_COUTA_H
- #define ADD_COUTA_H
-
- /*
- * C-Includes, C-Definitionen
- *
- */
-
- #define class _class
- #define template _template
-
- extern "C" {
- #include <exec/types.h>
- #include <dos/dos.h>
- #include <clib/alib_protos.h>
- #include <clib/alib_stdio_protos.h>
- #include <inline/stubs.h>
- #ifdef __OPTIMIZE__
- #include <inline/exec.h>
- #include <inline/dos.h>
- #else
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #endif
- }
-
- #undef template
- #undef class
-
- #include "ios.h"
-
- #ifndef EOF
- #define EOF -1
- #endif
-
- class couta;
-
- typedef couta& (*__omanip)(couta&);
-
- #ifndef ADD_CINA_H
- enum seek_dir { beg=OFFSET_BEGINNING, cur=OFFSET_CURRENT, end=OFFSET_END};
- #endif
-
- class couta : public ios {
- public:
- couta() : ios(Output())
- {
- _flags |= ios::dont_close;
- }
-
- couta(BPTR own_fh) : ios(own_fh)
- {
- _flags |= ios::dont_close;
- }
-
- ~couta() { flush();}
- couta& operator<<(int x);
- couta& operator<<(char *c);
- couta& operator<<(char c);
- couta& operator<<(long x);
-
- inline couta& operator<<(__omanip func) { return (*func)(*this); }
- // inline couta& operator<<(couta& os, __manip func) {(*func)(os); return os;}
-
- inline couta& flush();
-
-
- couta& put(char c)
- {
- if(FPutC(_fh,c) == EOF) set(ios::eofbit|ios::failbit);
- return *this;
- }
-
- couta& write(const char *s, int n)
- {
- ULONG x;
- SetIoErr(0L);
- x=FWrite(_fh,STRPTR(s),n,1);
- if(x != 1) set(ios::failbit);
- return *this;
- }
-
- couta& write(const unsigned char *s, int n)
- {
- return(write((const char *)s,n));
- }
-
- couta& write(const void *s, int n)
- {
- return(write((const char *)s,n));
- }
-
- LONG tellp()
- {
- LONG x = Seek(_fh, 0, OFFSET_CURRENT);
-
- if (x == -1)
- set(ios::failbit);
-
- return x;
- }
-
- couta& seekp(ULONG pos)
- {
- if(Seek(_fh, pos, OFFSET_BEGINNING)==-1) set(ios::failbit);
- return *this;
- }
-
- couta& seekp(ULONG off, seek_dir dir)
- {
- if(Seek(_fh, off, dir)==-1) set(ios::failbit);
- return *this;
- }
-
- BPTR attach(BPTR fh)
- {
- BPTR save=_fh;
- flush();
- _fh=fh;
- if(!fh) set(ios::failbit);
- return save;
- }
- };
-
-
- inline couta& couta::operator<<(int x)
- {
- if(VFPrintf(_fh,(unsigned char *)"%ld",(long int *)&x)==EOF)
- set(ios::failbit);
-
- return *this;
-
- }
- inline couta& couta::operator<<(char *c)
- {
- if(c) // no harm if NULL-String
- if(FPuts(_fh,(STRPTR)c)==EOF) set(ios::failbit);
-
- return *this;
- }
- inline couta& couta::operator<<(char c)
- {
- return put(c);
- }
-
- inline couta& couta::operator<<(long x)
- {
- if(VFPrintf(_fh,(unsigned char *)"%ld",(long int *)&x)==EOF) set(ios::failbit);
- return *this;
- }
-
- inline couta& couta::flush()
- {
- if(_fh) Flush(_fh);
- return *this;
- }
-
- inline couta& flush(couta& a)
- {
- return a.flush();
- }
-
- inline couta& endl(couta& outs)
- {
- return outs << "\n" << flush;
- }
-
- inline couta& ends(couta& outs)
- {
- return outs << (char *)0 << flush;
- }
-
- extern couta cout;
-
- #endif
-