libdap
Updated for version 3.17.0
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 #ifndef response_h 00027 #define response_h 00028 00029 #include <cstdio> 00030 #include <string> 00031 //#include <iostream> 00032 #include <fstream> 00033 00034 #include "ObjectType.h" 00035 #include "debug.h" 00036 00037 namespace libdap 00038 { 00039 00053 class Response 00054 { 00055 private: 00057 FILE *d_stream; 00058 std::fstream *d_cpp_stream; 00059 00061 ObjectType d_type; 00063 std::string d_version; 00065 std::string d_protocol; 00067 int d_status; 00068 00069 protected: 00072 Response(const Response &); 00073 Response &operator=(const Response &); 00075 00076 public: 00077 Response() : d_stream(0), d_cpp_stream(0), d_type(unknown_type), d_version("dods/0.0"), d_protocol("2.0"), 00078 d_status(0) 00079 { } 00080 00088 Response(FILE *s, int status = 0) : d_stream(s), d_cpp_stream(0), d_type(unknown_type), 00089 d_version("dods/0.0"), d_protocol("2.0"), d_status(status) { } 00090 00091 Response(std::fstream *s, int status = 0) : d_stream(0), d_cpp_stream(s), d_type(unknown_type), 00092 d_version("dods/0.0"), d_protocol("2.0"), d_status(status) { } 00093 00095 virtual ~Response() 00096 { 00097 if (d_stream) 00098 fclose(d_stream); 00099 if (d_cpp_stream) 00100 d_cpp_stream->close(); 00101 } 00102 00105 virtual int get_status() const { return d_status; } 00106 virtual FILE *get_stream() const { return d_stream; } 00107 virtual std::istream *get_cpp_stream() const { return d_cpp_stream; } 00108 00109 virtual ObjectType get_type() const { return d_type; } 00110 virtual std::string get_version() const { return d_version; } 00111 virtual std::string get_protocol() const { return d_protocol; } 00113 00116 virtual void set_status(int s) { d_status = s; } 00117 00118 virtual void set_stream(FILE *s) { d_stream = s; } 00119 virtual void set_cpp_stream(std::istream *s) { d_cpp_stream = dynamic_cast<std::fstream*>(s); } 00120 00121 virtual void set_type(ObjectType o) { d_type = o; } 00122 virtual void set_version(const std::string &v) { d_version = v; } 00123 virtual void set_protocol(const std::string &p) { d_protocol = p; } 00125 }; 00126 00127 } // namespace libdap 00128 00129 #endif // response_h