~ubuntu-branches/ubuntu/gutsy/grhino/gutsy

« back to all changes in this revision

Viewing changes to fdstream.h

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2007-04-02 20:38:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070402203809-fxyqqtkhj9ou03dy
Tags: upstream-0.16.0
ImportĀ upstreamĀ versionĀ 0.16.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        fdstream.h      C++ Stream From File Descripter
 
3
        Copyright (c) 2005 Kriang Lerdsuwanakij
 
4
        email:          lerdsuwa@users.sourceforge.net
 
5
        
 
6
        Adapt from The C++ Standard Library: A Tutorial and Reference
 
7
 
 
8
        This program is free software; you can redistribute it and/or modify
 
9
        it under the terms of the GNU General Public License as published by
 
10
        the Free Software Foundation; either version 2 of the License, or
 
11
        (at your option) any later version.
 
12
 
 
13
        This program is distributed in the hope that it will be useful,
 
14
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
        GNU General Public License for more details.
 
17
 
 
18
        You should have received a copy of the GNU General Public License
 
19
        along with this program; if not, write to the Free Software
 
20
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
21
*/
 
22
 
 
23
#ifndef __K_FDSTREAM_H
 
24
#define __K_FDSTREAM_H
 
25
 
 
26
#include "config.h"
 
27
 
 
28
#include <iostream>
 
29
#include <streambuf>
 
30
#include <stdio.h>
 
31
 
 
32
#if 0
 
33
class fdoutbuf : public std::streambuf {
 
34
                int fd;
 
35
        public:
 
36
                fdoutbuf(int _fd) : fd(_fd) {}
 
37
        protected:
 
38
                virtual int_type overflow(int_type c = std::char_traits<char>::eof()) {
 
39
                        if (c != EOF) {
 
40
                                char z = c;
 
41
                                if (write(fd, &z, 1) != 1)
 
42
                                        return EOF;
 
43
                        }
 
44
                        return c;
 
45
                }
 
46
                virtual std::streamsize xsputn(const char *s, std::streamsize n) {
 
47
                        return write(fd, s, n);
 
48
                }
 
49
};
 
50
 
 
51
class fdostream : private fdoutbuf, public std::ostream {
 
52
        public:
 
53
                fdostream(int fd) : fdoutbuf(fd), std::ostream(this) {}
 
54
};
 
55
#endif /* 0 */
 
56
 
 
57
#endif /* __K_FDSTREAM_H */