libdap++ Updated for version 3.8.2

Resource.h

Go to the documentation of this file.
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) 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 //
00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
00025 
00026 #ifndef resource_h
00027 #define resource_h
00028 
00029 #include <string>
00030 #include <iostream>
00031 
00032 #ifndef _error_h
00033 #include "Error.h"
00034 #endif
00035 
00036 using namespace std;
00037 
00038 namespace libdap
00039 {
00040 
00050 class Resource
00051 {
00052 public:
00053 
00071     enum rule { overwrite, replace, fallback };
00072 
00075     Resource() : d_url(""), d_rule(overwrite)
00076     {}
00077 
00081     Resource(const string &u) : d_url(u), d_rule(overwrite)
00082     {}
00083 
00087     Resource(const string &u, const rule &r) : d_url(u), d_rule(r)
00088     {}
00089 
00100     Resource(const string &u, const string &r) throw(Error) : d_url(u)
00101     {
00102         if (r == "replace")
00103             d_rule = replace;
00104         else if (r == "fallback")
00105             d_rule = fallback;
00106         else if (r == "overwrite" || r == "default")
00107             d_rule = overwrite;
00108         else
00109             throw Error(string("An AIS Resource object was created with an unknown rule type '") + r);
00110     }
00111 
00112     virtual ~Resource()
00113 {}
00114 
00116     virtual string get_url() const
00117     {
00118         return d_url;
00119     }
00120 
00123     virtual void set_url(const string &u)
00124     {
00125         d_url = u;
00126     }
00127 
00129     virtual Resource::rule get_rule() const
00130     {
00131         return d_rule;
00132     }
00133 
00136     virtual void set_rule(const Resource::rule &r)
00137     {
00138         d_rule = r;
00139     }
00140 
00145     friend ostream &operator<<(ostream &os, const Resource &r);
00146 
00147 
00148 private:
00149 
00150     string d_url;
00151     Resource::rule d_rule;
00152 };
00153 
00154 } // namespace libdap
00155 
00156 #endif // resource_h