1 // This file is part of the ustl library, an STL implementation.
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
9 #ifndef FDOSTREAM_H_5E27FC3D530BF3CA04D6C73F5700EECC
10 #define FDOSTREAM_H_5E27FC3D530BF3CA04D6C73F5700EECC
18 /// \class ofstream fdostream.h ustl.h
19 /// \ingroup DeviceStreams
20 /// \brief A string stream that writes to an fd. Implements cout and cerr.
21 class ofstream
: public ostringstream
{
24 explicit ofstream (int Fd
);
25 explicit ofstream (const char* filename
, openmode mode
= out
);
26 virtual ~ofstream (void);
27 inline void open (const char* filename
, openmode mode
= out
) { m_File
.open (filename
, mode
); clear (m_File
.rdstate()); }
29 inline bool is_open (void) const { return (m_File
.is_open()); }
30 inline iostate
exceptions (iostate v
) { ostringstream::exceptions(v
); return (m_File
.exceptions(v
)); }
31 inline void setstate (iostate v
) { ostringstream::setstate(v
); m_File
.setstate(v
); }
32 inline void clear (iostate v
= goodbit
) { ostringstream::clear(v
); m_File
.clear(v
); }
33 inline off_t
tellp (void) const { return (m_File
.tellp() + ostringstream::tellp()); }
34 inline int fd (void) const { return (m_File
.fd()); }
35 inline void stat (struct stat
& rs
) const { m_File
.stat (rs
); }
36 inline void set_nonblock (bool v
= true) { m_File
.set_nonblock (v
); }
37 inline int ioctl (const char* rname
, int request
, long argument
= 0) { return (m_File
.ioctl (rname
, request
, argument
)); }
38 inline int ioctl (const char* rname
, int request
, int argument
) { return (m_File
.ioctl (rname
, request
, argument
)); }
39 inline int ioctl (const char* rname
, int request
, void* argument
) { return (m_File
.ioctl (rname
, request
, argument
)); }
40 void seekp (off_t p
, seekdir d
= beg
);
42 virtual size_type
overflow (size_type n
= 1);
47 /// \class ifstream fdostream.h ustl.h
48 /// \ingroup DeviceStreams
49 /// \brief A string stream that reads from an fd. Implements cin.
50 class ifstream
: public istringstream
{
53 explicit ifstream (int Fd
);
54 explicit ifstream (const char* filename
, openmode mode
= in
);
55 inline void open (const char* filename
, openmode mode
= in
) { m_File
.open (filename
, mode
); clear (m_File
.rdstate()); }
56 inline void close (void) { m_File
.close(); clear (m_File
.rdstate()); }
57 inline bool is_open (void) const { return (m_File
.is_open()); }
58 inline iostate
exceptions (iostate v
) { istringstream::exceptions(v
); return (m_File
.exceptions(v
)); }
59 inline void setstate (iostate v
) { istringstream::setstate(v
); m_File
.setstate(v
); }
60 inline void clear (iostate v
= goodbit
) { istringstream::clear(v
); m_File
.clear(v
); }
61 inline off_t
tellg (void) const { return (m_File
.tellg() - remaining()); }
62 inline int fd (void) const { return (m_File
.fd()); }
63 inline void stat (struct stat
& rs
) const { m_File
.stat (rs
); }
64 inline void set_nonblock (bool v
= true) { m_File
.set_nonblock (v
); }
65 inline int ioctl (const char* rname
, int request
, long argument
= 0) { return (m_File
.ioctl (rname
, request
, argument
)); }
66 inline int ioctl (const char* rname
, int request
, int argument
) { return (m_File
.ioctl (rname
, request
, argument
)); }
67 inline int ioctl (const char* rname
, int request
, void* argument
) { return (m_File
.ioctl (rname
, request
, argument
)); }
68 void seekg (off_t p
, seekdir d
= beg
);
70 virtual size_type
underflow (size_type n
= 1);
76 extern ofstream cout
, cerr
;