libdap Updated for version 3.21.0
libdap4 is an implementation of OPeNDAP's DAP protocol.
Response.h
1
2// -*- mode: c++; c-basic-offset:4 -*-
3
4// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5// Access Protocol.
6
7// Copyright (c) 2002,2003 OPeNDAP, Inc.
8// Author: James Gallagher <jgallagher@opendap.org>
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13// version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23//
24// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26#ifndef response_h
27#define response_h
28
29#include <cstdio>
30#include <string>
31// #include <iostream>
32#include <fstream>
33
34#include "ObjectType.h"
35#include "debug.h"
36
37namespace libdap {
38
52class Response {
53private:
55 FILE *d_stream;
56 std::fstream *d_cpp_stream;
57
59 ObjectType d_type;
61 std::string d_version;
63 std::string d_protocol;
65 int d_status;
66
67protected:
70 Response(const Response &);
71 Response &operator=(const Response &);
73
74public:
75 Response()
76 : d_stream(0), d_cpp_stream(0), d_type(unknown_type), d_version("dods/0.0"), d_protocol("2.0"), d_status(0) {}
77
85 Response(FILE *s, int status = 0)
86 : d_stream(s), d_cpp_stream(0), d_type(unknown_type), d_version("dods/0.0"), d_protocol("2.0"),
87 d_status(status) {}
88
89 Response(std::fstream *s, int status = 0)
90 : d_stream(0), d_cpp_stream(s), d_type(unknown_type), d_version("dods/0.0"), d_protocol("2.0"),
91 d_status(status) {}
92
94 virtual ~Response() {
95 if (d_stream)
96 fclose(d_stream);
97 if (d_cpp_stream)
98 d_cpp_stream->close();
99 }
100
103 virtual int get_status() const { return d_status; }
104 virtual FILE *get_stream() const { return d_stream; }
105 virtual std::istream *get_cpp_stream() const { return d_cpp_stream; }
106
107 virtual ObjectType get_type() const { return d_type; }
108 virtual std::string get_version() const { return d_version; }
109 virtual std::string get_protocol() const { return d_protocol; }
111
114 virtual void set_status(int s) { d_status = s; }
115
116 virtual void set_stream(FILE *s) { d_stream = s; }
117 virtual void set_cpp_stream(std::istream *s) { d_cpp_stream = dynamic_cast<std::fstream *>(s); }
118
119 virtual void set_type(ObjectType o) { d_type = o; }
120 virtual void set_version(const std::string &v) { d_version = v; }
121 virtual void set_protocol(const std::string &p) { d_protocol = p; }
123};
124
125} // namespace libdap
126
127#endif // response_h
Response(FILE *s, int status=0)
Definition Response.h:85
virtual ~Response()
Definition Response.h:94
top level DAP object to house generic methods
Definition AISConnect.cc:30
ObjectType
The type of object in the stream coming from the data server.
Definition ObjectType.h:57