libdap  Updated for version 3.20.6
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 
37 namespace libdap
38 {
39 
53 class Response
54 {
55 private:
57  FILE *d_stream;
58  std::fstream *d_cpp_stream;
59 
61  ObjectType d_type;
63  std::string d_version;
65  std::string d_protocol;
67  int d_status;
68 
69 protected:
72  Response(const Response &);
73  Response &operator=(const Response &);
75 
76 public:
77  Response() : d_stream(0), d_cpp_stream(0), d_type(unknown_type), d_version("dods/0.0"), d_protocol("2.0"),
78  d_status(0)
79  { }
80 
88  Response(FILE *s, int status = 0) : d_stream(s), d_cpp_stream(0), d_type(unknown_type),
89  d_version("dods/0.0"), d_protocol("2.0"), d_status(status) { }
90 
91  Response(std::fstream *s, int status = 0) : d_stream(0), d_cpp_stream(s), d_type(unknown_type),
92  d_version("dods/0.0"), d_protocol("2.0"), d_status(status) { }
93 
95  virtual ~Response()
96  {
97  if (d_stream)
98  fclose(d_stream);
99  if (d_cpp_stream)
100  d_cpp_stream->close();
101  }
102 
105  virtual int get_status() const { return d_status; }
106  virtual FILE *get_stream() const { return d_stream; }
107  virtual std::istream *get_cpp_stream() const { return d_cpp_stream; }
108 
109  virtual ObjectType get_type() const { return d_type; }
110  virtual std::string get_version() const { return d_version; }
111  virtual std::string get_protocol() const { return d_protocol; }
113 
116  virtual void set_status(int s) { d_status = s; }
117 
118  virtual void set_stream(FILE *s) { d_stream = s; }
119  virtual void set_cpp_stream(std::istream *s) { d_cpp_stream = dynamic_cast<std::fstream*>(s); }
120 
121  virtual void set_type(ObjectType o) { d_type = o; }
122  virtual void set_version(const std::string &v) { d_version = v; }
123  virtual void set_protocol(const std::string &p) { d_protocol = p; }
125 };
126 
127 } // namespace libdap
128 
129 #endif // response_h
Response(FILE *s, int status=0)
Definition: Response.h:88
ObjectType
The type of object in the stream coming from the data server.
Definition: ObjectType.h:58
virtual ~Response()
Definition: Response.h:95
top level DAP object to house generic methods
Definition: AISConnect.cc:30