xref: /haiku/headers/cpp/fstream.h (revision f2ced752a08ff5d2618826bcd3ae3976c9f3e92e)
1*f2ced752SOliver Tappe /* This is part of libio/iostream, providing -*- C++ -*- input/output.
2*f2ced752SOliver Tappe Copyright (C) 1993, 2000 Free Software Foundation
3*f2ced752SOliver Tappe 
4*f2ced752SOliver Tappe This file is part of the GNU IO Library.  This library is free
5*f2ced752SOliver Tappe software; you can redistribute it and/or modify it under the
6*f2ced752SOliver Tappe terms of the GNU General Public License as published by the
7*f2ced752SOliver Tappe Free Software Foundation; either version 2, or (at your option)
8*f2ced752SOliver Tappe any later version.
9*f2ced752SOliver Tappe 
10*f2ced752SOliver Tappe This library is distributed in the hope that it will be useful,
11*f2ced752SOliver Tappe but WITHOUT ANY WARRANTY; without even the implied warranty of
12*f2ced752SOliver Tappe MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*f2ced752SOliver Tappe GNU General Public License for more details.
14*f2ced752SOliver Tappe 
15*f2ced752SOliver Tappe You should have received a copy of the GNU General Public License
16*f2ced752SOliver Tappe along with this library; see the file COPYING.  If not, write to the Free
17*f2ced752SOliver Tappe Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18*f2ced752SOliver Tappe 
19*f2ced752SOliver Tappe As a special exception, if you link this library with files
20*f2ced752SOliver Tappe compiled with a GNU compiler to produce an executable, this does not cause
21*f2ced752SOliver Tappe the resulting executable to be covered by the GNU General Public License.
22*f2ced752SOliver Tappe This exception does not however invalidate any other reasons why
23*f2ced752SOliver Tappe the executable file might be covered by the GNU General Public License. */
24*f2ced752SOliver Tappe 
25*f2ced752SOliver Tappe #ifndef _FSTREAM_H
26*f2ced752SOliver Tappe #define _FSTREAM_H
27*f2ced752SOliver Tappe #ifdef __GNUG__
28*f2ced752SOliver Tappe #pragma interface
29*f2ced752SOliver Tappe #endif
30*f2ced752SOliver Tappe #include <iostream.h>
31*f2ced752SOliver Tappe 
32*f2ced752SOliver Tappe extern "C++" {
33*f2ced752SOliver Tappe class fstreambase : virtual public ios {
34*f2ced752SOliver Tappe #ifdef _IO_NEW_STREAMS
35*f2ced752SOliver Tappe     mutable filebuf __my_fb; // mutable so rdbuf() can be const
36*f2ced752SOliver Tappe #endif
37*f2ced752SOliver Tappe     void __fb_init ();
38*f2ced752SOliver Tappe   public:
39*f2ced752SOliver Tappe     fstreambase();
40*f2ced752SOliver Tappe     fstreambase(int fd);
41*f2ced752SOliver Tappe     fstreambase(int fd, char *p, int l); /* Deprecated */
42*f2ced752SOliver Tappe     fstreambase(const char *name, int mode, int prot=0664);
43*f2ced752SOliver Tappe     void close();
44*f2ced752SOliver Tappe #ifdef _IO_NEW_STREAMS
rdbuf()45*f2ced752SOliver Tappe     filebuf* rdbuf() const { return &__my_fb; }
46*f2ced752SOliver Tappe #else
rdbuf()47*f2ced752SOliver Tappe     filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
48*f2ced752SOliver Tappe #endif
49*f2ced752SOliver Tappe     void open(const char *name, int mode, int prot=0664);
is_open()50*f2ced752SOliver Tappe     int is_open() const { return rdbuf()->is_open(); }
setbuf(char * ptr,int len)51*f2ced752SOliver Tappe     void setbuf(char *ptr, int len) { rdbuf()->setbuf(ptr, len); }
52*f2ced752SOliver Tappe     void attach(int fd);
53*f2ced752SOliver Tappe #ifdef _STREAM_COMPAT
filedesc()54*f2ced752SOliver Tappe     int filedesc() { return rdbuf()->fd(); }
raw()55*f2ced752SOliver Tappe     fstreambase& raw() { rdbuf()->setbuf(NULL, 0); return *this; }
56*f2ced752SOliver Tappe #endif
57*f2ced752SOliver Tappe };
58*f2ced752SOliver Tappe 
59*f2ced752SOliver Tappe class ifstream : public fstreambase, public istream {
60*f2ced752SOliver Tappe   public:
ifstream()61*f2ced752SOliver Tappe     ifstream() : fstreambase() { }
ifstream(int fd)62*f2ced752SOliver Tappe     ifstream(int fd) : fstreambase(fd) { }
ifstream(int fd,char * p,int l)63*f2ced752SOliver Tappe     ifstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
64*f2ced752SOliver Tappe     ifstream(const char *name, int mode=ios::in, int prot=0664)
65*f2ced752SOliver Tappe 	: fstreambase(name, mode | ios::in, prot) { }
66*f2ced752SOliver Tappe     void open(const char *name, int mode=ios::in, int prot=0664)
67*f2ced752SOliver Tappe 	{ fstreambase::open(name, mode | ios::in, prot); }
68*f2ced752SOliver Tappe };
69*f2ced752SOliver Tappe 
70*f2ced752SOliver Tappe class ofstream : public fstreambase, public ostream {
71*f2ced752SOliver Tappe   public:
ofstream()72*f2ced752SOliver Tappe     ofstream() : fstreambase() { }
ofstream(int fd)73*f2ced752SOliver Tappe     ofstream(int fd) : fstreambase(fd) { }
ofstream(int fd,char * p,int l)74*f2ced752SOliver Tappe     ofstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
75*f2ced752SOliver Tappe     ofstream(const char *name, int mode=ios::out, int prot=0664)
76*f2ced752SOliver Tappe 	: fstreambase(name, mode | ios::out, prot) { }
77*f2ced752SOliver Tappe     void open(const char *name, int mode=ios::out, int prot=0664)
78*f2ced752SOliver Tappe 	{ fstreambase::open(name, mode | ios::out, prot); }
79*f2ced752SOliver Tappe };
80*f2ced752SOliver Tappe 
81*f2ced752SOliver Tappe class fstream : public fstreambase, public iostream {
82*f2ced752SOliver Tappe   public:
fstream()83*f2ced752SOliver Tappe     fstream() : fstreambase() { }
fstream(int fd)84*f2ced752SOliver Tappe     fstream(int fd) : fstreambase(fd) { }
85*f2ced752SOliver Tappe     fstream(const char *name, int mode, int prot=0664)
fstreambase(name,mode,prot)86*f2ced752SOliver Tappe 	: fstreambase(name, mode, prot) { }
fstream(int fd,char * p,int l)87*f2ced752SOliver Tappe     fstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/
88*f2ced752SOliver Tappe     void open(const char *name, int mode, int prot=0664)
89*f2ced752SOliver Tappe 	{ fstreambase::open(name, mode, prot); }
90*f2ced752SOliver Tappe };
91*f2ced752SOliver Tappe } // extern "C++"
92*f2ced752SOliver Tappe #endif /*!_FSTREAM_H*/
93