libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
Response.h
Go to the documentation of this file.
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 <fstream>
31#include <string>
32
33#include "ObjectType.h"
34
35namespace libdap {
36
50class Response {
51private:
53 FILE *d_stream = nullptr;
54 std::fstream *d_cpp_stream = nullptr;
55
57 ObjectType d_type = unknown_type;
59 std::string d_version{"dods/0.0"};
61 std::string d_protocol{"2.0"};
63 int d_status = 0;
64
65protected:
66 // Hack for HTTPResponse which may allocate a fstream pointer in a setter. jhrg 2/5/25
68
69public:
70 Response() = default;
71
74 Response(const Response &) = delete;
75 Response &operator=(const Response &) = delete;
77
85 explicit Response(FILE *s, int status = 0) : d_stream(s), d_status(status) {}
86
87 explicit Response(std::fstream *s, int status = 0) : d_cpp_stream(s), d_status(status) {}
88
90 virtual ~Response() {
91 if (d_stream)
92 fclose(d_stream);
93 if (d_cpp_stream) {
94 d_cpp_stream->close();
96 delete d_cpp_stream;
97 }
98 }
99
102 virtual int get_status() const { return d_status; }
103 virtual FILE *get_stream() const { return d_stream; }
104 virtual std::istream *get_cpp_stream() const { return d_cpp_stream; }
105
106 virtual ObjectType get_type() const { return d_type; }
107 virtual std::string get_version() const { return d_version; }
108 virtual std::string get_protocol() const { return d_protocol; }
110
113 virtual void set_status(int s) { d_status = s; }
114
115 virtual void set_stream(FILE *s) { d_stream = s; }
116 virtual void set_cpp_stream(std::istream *s) { d_cpp_stream = dynamic_cast<std::fstream *>(s); }
117
118 virtual void set_type(ObjectType o) { d_type = o; }
119 virtual void set_version(const std::string &v) { d_version = v; }
120 virtual void set_protocol(const std::string &p) { d_protocol = p; }
122};
123
124} // namespace libdap
125
126#endif // response_h
Response(FILE *s, int status=0)
Definition Response.h:85
Response(std::fstream *s, int status=0)
Definition Response.h:87
virtual void set_version(const std::string &v)
Definition Response.h:119
bool d_delete_cpp_stream_ptr
Definition Response.h:67
virtual int get_status() const
Definition Response.h:102
virtual std::string get_protocol() const
Definition Response.h:108
virtual void set_status(int s)
Definition Response.h:113
virtual void set_cpp_stream(std::istream *s)
Definition Response.h:116
virtual void set_stream(FILE *s)
Definition Response.h:115
virtual void set_type(ObjectType o)
Definition Response.h:118
Response()=default
Response(const Response &)=delete
Response & operator=(const Response &)=delete
virtual ~Response()
Definition Response.h:90
virtual std::istream * get_cpp_stream() const
Definition Response.h:104
virtual ObjectType get_type() const
Definition Response.h:106
virtual void set_protocol(const std::string &p)
Definition Response.h:120
virtual FILE * get_stream() const
Definition Response.h:103
virtual std::string get_version() const
Definition Response.h:107
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
@ unknown_type
Definition ObjectType.h:58