00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _fdiostream_h
00029 #define _fdiostream_h
00030
00031 #ifdef HAVE_UNISTD_H
00032 #include <unistd.h>
00033 #endif
00034
00035 #include <iostream>
00036 #include <streambuf>
00037 #include <algorithm>
00038 #include <cstdio>
00039
00040 namespace libdap {
00041
00050 class fdoutbuf : public std::streambuf {
00051 protected:
00052 int fd;
00053 bool close;
00054 static const int bufferSize = 4096;
00055 char buffer[bufferSize];
00056
00057 public:
00058 fdoutbuf(int _fd, bool _close);
00059 virtual ~fdoutbuf();
00060
00061 protected:
00062 int flushBuffer();
00063
00064 virtual int overflow(int c);
00065 virtual int sync();
00066 virtual std::streamsize xsputn(const char *s, std::streamsize num);
00067 };
00068
00077 class fdostream : public std::ostream {
00078 protected:
00079 fdoutbuf buf;
00080 public:
00087 fdostream (int _fd, bool _close = false)
00088 : std::ostream(&buf), buf(_fd, _close) { }
00089 };
00090
00099 class fdinbuf : public std::streambuf {
00100 protected:
00101 int fd;
00102 bool close;
00103 static const int bufferSize = 4096;
00104 static const int putBack = 128;
00105 char buffer[bufferSize];
00106
00107 public:
00108 fdinbuf(int _fd, bool close);
00109 virtual ~fdinbuf();
00110
00111 protected:
00112 virtual int underflow();
00113 };
00114
00124 class fdistream : public std::istream {
00125 protected:
00126 fdinbuf buf;
00127 public:
00128 fdistream (int fd, bool close = false)
00129 : std::istream(&buf), buf(fd, close) { }
00130 };
00131
00140 class fpinbuf : public std::streambuf {
00141 protected:
00142 FILE *fp;
00143 bool close;
00144 static const int bufferSize = 4096;
00145 static const int putBack = 128;
00146 char buffer[bufferSize];
00147
00148 public:
00149 fpinbuf(FILE *_fp, bool _close);
00150 virtual ~fpinbuf();
00151
00152 protected:
00153 virtual int underflow();
00154 };
00155
00166 class fpistream : public std::istream {
00167 protected:
00168 fpinbuf buf;
00169 public:
00170 fpistream (FILE *fp, bool close = false)
00171 : std::istream(&buf), buf(fp, close) { }
00172 };
00173
00174 }
00175
00176 #endif