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 
00047 class Resource
00048 {
00049 public:
00050 
00068     enum rule { overwrite, replace, fallback };
00069 
00072     Resource() : d_url(""), d_rule(overwrite)
00073     {}
00074 
00078     Resource(const string &u) : d_url(u), d_rule(overwrite)
00079     {}
00080 
00084     Resource(const string &u, const rule &r) : d_url(u), d_rule(r)
00085     {}
00086 
00097     Resource(const string &u, const string &r) throw(Error) : d_url(u)
00098     {
00099         if (r == "replace")
00100             d_rule = replace;
00101         else if (r == "fallback")
00102             d_rule = fallback;
00103         else if (r == "overwrite" || r == "default")
00104             d_rule = overwrite;
00105         else
00106             throw Error(string("An AIS Resource object was created with an unknown rule type '") + r);
00107     }
00108 
00109     virtual ~Resource()
00110 {}
00111 
00113     virtual string get_url() const
00114     {
00115         return d_url;
00116     }
00117 
00120     virtual void set_url(const string &u)
00121     {
00122         d_url = u;
00123     }
00124 
00126     virtual Resource::rule get_rule() const
00127     {
00128         return d_rule;
00129     }
00130 
00133     virtual void set_rule(const Resource::rule &r)
00134     {
00135         d_rule = r;
00136     }
00137 
00142     friend ostream &operator<<(ostream &os, const Resource &r);
00143 
00144 
00145 private:
00146 
00147     string d_url;
00148     Resource::rule d_rule;
00149 };
00150 
00151 #endif // resource_h

Generated on Wed Jun 27 12:56:39 2007 for libdap++ by  doxygen 1.4.7