Merge branch 'daemon-ext'
[libi2ncommon] / src / oftmpstream.hxx
CommitLineData
0e23f538
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
e93545dd
GE
20#ifndef _OFTMPSTREAM_HXX
21#define _OFTMPSTREAM_HXX
22
23#include <iostream>
24#include <fstream>
25#include <string>
26
27class fdoutbuf : public std::streambuf {
28 protected:
29 int fd; // file descriptor
30 public:
8655e0f2
TJ
31 fdoutbuf ()
32 : fd(-1)
33 {
e93545dd
GE
34 }
35 void set_fd(int _fd);
36 protected:
37 virtual int_type overflow (int_type c);
38 virtual std::streamsize xsputn (const char* s, std::streamsize num);
39};
40
69d8da4a 41/// This class is deprecated, use I2n::tmpofcopystream instead.
e93545dd
GE
42class oftmpstream : public std::ostream {
43public:
44 oftmpstream ();
8ac198c4 45 oftmpstream (const std::string &name);
e93545dd 46 ~oftmpstream ();
8ac198c4 47 void open (const std::string &name);
e93545dd 48 void close();
dcdae446
GE
49 std::string get_filename();
50 std::string get_tmp_filename();
18235d3a 51 void set_file_mode(int mode);
e93545dd
GE
52private:
53 int fd;
54 fdoutbuf buf;
55 bool is_open;
18235d3a 56 int file_mode;
e93545dd
GE
57
58 std::string tmpname;
59 std::string realname;
60};
61
62
63#endif