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