libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
fdiostream.h
Go to the documentation of this file.
1// -*- mode: c++; c-basic-offset:4 -*-
2
3// This file is part of libdap, A C++ implementation of the OPeNDAP Data
4// Access Protocol.
5
6// Copyright (c) 2009 OPeNDAP, Inc.
7// Author: James Gallagher <jgallagher@opendap.org>
8//
9// This library is free software; you can redistribute it and/or
10// modify it under the terms of the GNU Lesser General Public
11// License as published by the Free Software Foundation; either
12// version 2.1 of the License, or (at your option) any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17// Lesser General Public License for more details.
18//
19// You should have received a copy of the GNU Lesser General Public
20// License along with this library; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22//
23// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
24//
25// Portions of this code were taken verbatim from Josuttis,
26// "The C++ Standard Library," p.672
27
28#ifndef _fdiostream_h
29#define _fdiostream_h
30
31#ifdef HAVE_UNISTD_H
32#include <unistd.h>
33#endif
34
35#include <algorithm>
36#include <cstdio>
37#include <iostream>
38#include <streambuf>
39
40namespace libdap {
41
50class fdoutbuf : public std::streambuf {
51protected:
52 int fd; // file descriptor
53 bool close;
54 static const int bufferSize = 4096; // Size of the data buffer
55 char buffer[bufferSize]; // data buffer
56
57public:
58 fdoutbuf(int _fd, bool _close);
59 virtual ~fdoutbuf();
60
61protected:
62 int flushBuffer();
63
64 virtual int overflow(int c);
65 virtual int sync();
66 virtual std::streamsize xsputn(const char *s, std::streamsize num);
67};
68
77class fdostream : public std::ostream {
78protected:
80
81public:
88 fdostream(int _fd, bool _close = false) : std::ostream(&buf), buf(_fd, _close) {}
89};
90
99class fdinbuf : public std::streambuf {
100protected:
101 int fd; // file descriptor
102 bool close;
103 static const int bufferSize = 4096; // Size of the data buffer
104 static const int putBack = 128;
105 char buffer[bufferSize]; // data buffer
106
107public:
108 fdinbuf(int _fd, bool close);
109 virtual ~fdinbuf();
110
111protected:
112 virtual int underflow();
113};
114
124class fdistream : public std::istream {
125protected:
127
128public:
129 fdistream(int fd, bool close = false) : std::istream(&buf), buf(fd, close) {}
130};
131
140class fpinbuf : public std::streambuf {
141protected:
142 FILE *fp; // FILE *
143 bool close;
144 static const int bufferSize = 4096; // Size of the data buffer
145 static const int putBack = 128;
146 char buffer[bufferSize]; // data buffer
147
148public:
149 fpinbuf(FILE *_fp, bool _close);
150 virtual ~fpinbuf();
151
152protected:
153 virtual int underflow();
154};
155
166class fpistream : public std::istream {
167protected:
169
170public:
171 fpistream(FILE *fp, bool close = false) : std::istream(&buf), buf(fp, close) {}
172};
173
174} // namespace libdap
175
176#endif
STL class.
static const int bufferSize
Definition fdiostream.h:103
static const int putBack
Definition fdiostream.h:104
fdinbuf(int _fd, bool close)
char buffer[bufferSize]
Definition fdiostream.h:105
virtual int underflow()
virtual ~fdinbuf()
fdistream(int fd, bool close=false)
Definition fdiostream.h:129
fdostream(int _fd, bool _close=false)
Definition fdiostream.h:88
virtual int sync()
Definition fdiostream.cc:79
virtual int overflow(int c)
Definition fdiostream.cc:64
virtual std::streamsize xsputn(const char *s, std::streamsize num)
Definition fdiostream.cc:88
char buffer[bufferSize]
Definition fdiostream.h:55
static const int bufferSize
Definition fdiostream.h:54
virtual ~fdoutbuf()
Definition fdiostream.cc:47
fdoutbuf(int _fd, bool _close)
Definition fdiostream.cc:43
static const int putBack
Definition fdiostream.h:145
char buffer[bufferSize]
Definition fdiostream.h:146
virtual ~fpinbuf()
static const int bufferSize
Definition fdiostream.h:144
virtual int underflow()
fpinbuf(FILE *_fp, bool _close)
fpistream(FILE *fp, bool close=false)
Definition fdiostream.h:171
STL class.
top level DAP object to house generic methods
Definition AISConnect.cc:30