libdap Updated for version 3.21.1
libdap4 is an implementation of OPeNDAP's DAP protocol.
AISResources.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) 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 ais_resources_h
27#define ais_resources_h
28
29#include <iostream>
30#include <map>
31#include <string>
32#include <vector>
33
34#include "GNURegex.h"
35
36#ifndef resource_h
37#include "Resource.h"
38#endif
39
40#ifndef ais_exceptions_h
41#include "AISExceptions.h"
42#endif
43
44using namespace std;
45
46namespace libdap {
47
48typedef vector<Resource> ResourceVector;
49typedef ResourceVector::iterator ResourceVectorIter;
50typedef ResourceVector::const_iterator ResourceVectorCIter;
51
70private:
71 // The AIS database is broken into two parts. The entries where the primary
72 // resource is a URL are stored in a map<> while the primaries that are
73 // regular expressions are stored in a vector of pairs. The latter is
74 // searched using the MatchRegexp struct.
75 typedef map<string, ResourceVector> ResourceMap;
76 typedef ResourceMap::iterator ResourceMapIter;
77 typedef ResourceMap::const_iterator ResourceMapCIter;
78
79 typedef pair<string, ResourceVector> RVPair;
80 typedef vector<RVPair> ResourceRegexps;
81 typedef ResourceRegexps::iterator ResourceRegexpsIter;
82 typedef ResourceRegexps::const_iterator ResourceRegexpsCIter;
83
84 ResourceMap d_db; // This holds the URL resources
85 ResourceRegexps d_re; // This holds the regular expression res.
86
87#if 0
88
89 // Scan RegExps looking for a particular regular expression.
90 struct FindRegexp : public binary_function<RVPair, string, bool>
91 {
92 string local_re;
93 FindRegexp(const string &re) : local_re(re)
94 {}
95 bool operator()(const RVPair &p)
96 {
97 return p.first == local_re;
98 }
99 };
100
101 // Scan RegExps looking for one that matches a URL.
102 // *** Make this more efficient by storing the Regex objects in the
103 // vector. 03/11/03 jhrg
104 struct MatchRegexp : public binary_function<RVPair, string, bool>
105 {
106 string candidate;
107 MatchRegexp(const string &url) : candidate(url)
108 {}
109 bool operator()(const RVPair &p)
110 {
111 Regex r(p.first.c_str());
112 return r.match(candidate.c_str(), candidate.length()) != -1;
113 }
114 };
115#endif
116
117 friend class AISResourcesTest; // unit tests access to private stuff
118 friend ostream &operator<<(ostream &os, const AISResources &ais_res);
119
120public:
123 AISResources(const string &database) throw(AISDatabaseReadFailed);
124
125 virtual ~AISResources() {}
126
127 virtual void add_url_resource(const string &url, const Resource &ancillary);
128 virtual void add_url_resource(const string &url, const ResourceVector &rv);
129
130 virtual void add_regexp_resource(const string &regexp, const Resource &ancillary);
131 virtual void add_regexp_resource(const string &regexp, const ResourceVector &rv);
132
133 virtual bool has_resource(const string &primary) const;
134
135 virtual ResourceVector get_resource(const string &primary);
136
137 virtual void read_database(const string &database);
138
139 virtual void write_database(const string &filename);
140};
141
142} // namespace libdap
143
144#endif // ais_resources_h
virtual void write_database(const string &filename)
virtual ResourceVector get_resource(const string &primary)
friend class AISResourcesTest
friend ostream & operator<<(ostream &os, const AISResources &ais_res)
virtual bool has_resource(const string &primary) const
virtual void read_database(const string &database)
virtual void add_regexp_resource(const string &regexp, const Resource &ancillary)
virtual void add_url_resource(const string &url, const Resource &ancillary)
Regular expression matching.
Definition GNURegex.h:54
int match(const char *s, int len, int pos=0) const
Does the pattern match.
Definition GNURegex.cc:136
Associate a rule with an ancillary resource.
Definition Resource.h:49
top level DAP object to house generic methods
Definition AISConnect.cc:30
vector< Resource > ResourceVector
ResourceVector::const_iterator ResourceVectorCIter
ResourceVector::iterator ResourceVectorIter