00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef ais_resources_h
00027 #define ais_resources_h
00028
00029 #include <string>
00030 #include <iostream>
00031 #include <vector>
00032 #include <map>
00033
00034 #include "GNURegex.h"
00035
00036 #ifndef resource_h
00037 #include "Resource.h"
00038 #endif
00039
00040 #ifndef ais_exceptions_h
00041 #include "AISExceptions.h"
00042 #endif
00043
00044 using namespace std;
00045
00046 namespace libdap
00047 {
00048
00049 typedef vector<Resource> ResourceVector;
00050 typedef ResourceVector::iterator ResourceVectorIter;
00051 typedef ResourceVector::const_iterator ResourceVectorCIter;
00052
00070 class AISResources
00071 {
00072 private:
00073
00074
00075
00076
00077 typedef map<string, ResourceVector> ResourceMap;
00078 typedef ResourceMap::iterator ResourceMapIter;
00079 typedef ResourceMap::const_iterator ResourceMapCIter;
00080
00081 typedef pair<string, ResourceVector> RVPair;
00082 typedef vector<RVPair> ResourceRegexps;
00083 typedef ResourceRegexps::iterator ResourceRegexpsIter;
00084 typedef ResourceRegexps::const_iterator ResourceRegexpsCIter;
00085
00086 ResourceMap d_db;
00087 ResourceRegexps d_re;
00088
00089
00090 struct FindRegexp : public binary_function<RVPair, string, bool>
00091 {
00092 string local_re;
00093 FindRegexp(const string &re) : local_re(re)
00094 {}
00095 bool operator()(const RVPair &p)
00096 {
00097 return p.first == local_re;
00098 }
00099 };
00100
00101
00102
00103
00104 struct MatchRegexp : public binary_function<RVPair, string, bool>
00105 {
00106 string candidate;
00107 MatchRegexp(const string &url) : candidate(url)
00108 {}
00109 bool operator()(const RVPair &p)
00110 {
00111 Regex r(p.first.c_str());
00112 return r.match(candidate.c_str(), candidate.length()) != -1;
00113 }
00114 };
00115
00116 friend class AISResourcesTest;
00117 friend ostream &operator<<(ostream &os, const AISResources &ais_res);
00118
00119 public:
00121 AISResources()
00122 {}
00123 AISResources(const string &database) throw(AISDatabaseReadFailed);
00124
00125 virtual ~AISResources()
00126 {}
00127
00128 virtual void add_url_resource(const string &url,
00129 const Resource &ancillary);
00130 virtual void add_url_resource(const string &url, const ResourceVector &rv);
00131
00132 virtual void add_regexp_resource(const string ®exp,
00133 const Resource &ancillary);
00134 virtual void add_regexp_resource(const string ®exp,
00135 const ResourceVector &rv);
00136
00137 virtual bool has_resource(const string &primary) const;
00138
00139 virtual ResourceVector get_resource(const string &primary);
00140
00141 virtual void read_database(const string &database);
00142
00143 virtual void write_database(const string &filename);
00144 };
00145
00146 }
00147
00148 #endif // ais_resources_h