| 1 | /* |
| 2 | The software in this package is distributed under the GNU General |
| 3 | Public License version 2 (with a special exception described below). |
| 4 | |
| 5 | A copy of GNU General Public License (GPL) is included in this distribution, |
| 6 | in the file COPYING.GPL. |
| 7 | |
| 8 | As a special exception, if other files instantiate templates or use macros |
| 9 | or inline functions from this file, or you compile this file and link it |
| 10 | with other works to produce a work based on this file, this file |
| 11 | does not by itself cause the resulting work to be covered |
| 12 | by the GNU General Public License. |
| 13 | |
| 14 | However the source code for this file must still be made available |
| 15 | in accordance with section (3) of the GNU General Public License. |
| 16 | |
| 17 | This exception does not invalidate any other reasons why a work based |
| 18 | on 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 | |
| 27 | class 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. |
| 42 | class oftmpstream : public std::ostream { |
| 43 | public: |
| 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); |
| 52 | private: |
| 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 |