Replace inet_aton() with inet_pton() to parse IPs correctly (#8825)
[libi2ncommon] / src / oftmpstream.hxx
... / ...
CommitLineData
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*/
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:
31 fdoutbuf ()
32 : fd(-1)
33 {
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
41/// This class is deprecated, use I2n::tmpofcopystream instead.
42class oftmpstream : public std::ostream {
43public:
44 oftmpstream ();
45 oftmpstream (const std::string &name);
46 ~oftmpstream ();
47 void open (const std::string &name);
48 void close();
49 std::string get_filename();
50 std::string get_tmp_filename();
51 void set_file_mode(int mode);
52private:
53 int fd;
54 fdoutbuf buf;
55 bool is_open;
56 int file_mode;
57
58 std::string tmpname;
59 std::string realname;
60};
61
62
63#endif