-rw-r--r-- | include/opkele/types.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h index f732a1e..520618d 100644 --- a/include/opkele/types.h +++ b/include/opkele/types.h | |||
@@ -8,19 +8,22 @@ | |||
8 | 8 | ||
9 | #include <ostream> | 9 | #include <ostream> |
10 | #include <vector> | 10 | #include <vector> |
11 | #include <string> | 11 | #include <string> |
12 | #include <map> | 12 | #include <map> |
13 | #include <memory> | 13 | #include <memory> |
14 | #include <set> | ||
14 | 15 | ||
15 | namespace opkele { | 16 | namespace opkele { |
16 | using std::vector; | 17 | using std::vector; |
17 | using std::string; | 18 | using std::string; |
18 | using std::map; | 19 | using std::map; |
19 | using std::ostream; | 20 | using std::ostream; |
20 | using std::auto_ptr; | 21 | using std::auto_ptr; |
22 | using std::multimap; | ||
23 | using std::set; | ||
21 | 24 | ||
22 | /** | 25 | /** |
23 | * the OpenID operation mode | 26 | * the OpenID operation mode |
24 | */ | 27 | */ |
25 | typedef enum _mode_t { | 28 | typedef enum _mode_t { |
26 | mode_associate, | 29 | mode_associate, |
@@ -164,9 +167,69 @@ namespace opkele { | |||
164 | * dump the key/value pairs for the parameters to the stream. | 167 | * dump the key/value pairs for the parameters to the stream. |
165 | * @param o output stream | 168 | * @param o output stream |
166 | * @param p the parameters | 169 | * @param p the parameters |
167 | */ | 170 | */ |
168 | ostream& operator << (ostream& o,const params_t& p); | 171 | ostream& operator << (ostream& o,const params_t& p); |
169 | 172 | ||
173 | namespace xrd { | ||
174 | |||
175 | struct priority_compare { | ||
176 | inline bool operator()(long a,long b) const { | ||
177 | return (a<0) ? false : (b<0) ? false : (a<b); | ||
178 | } | ||
179 | }; | ||
180 | |||
181 | template <typename _DT> | ||
182 | class priority_map : public multimap<long,_DT,priority_compare> { | ||
183 | typedef multimap<long,_DT,priority_compare> map_type; | ||
184 | public: | ||
185 | |||
186 | inline _DT& add(long priority,const _DT& d) { | ||
187 | return insert(typename map_type::value_type(priority,d))->second; | ||
188 | } | ||
189 | }; | ||
190 | |||
191 | typedef priority_map<string> canonical_ids_t; | ||
192 | typedef priority_map<string> local_ids_t; | ||
193 | typedef set<string> types_t; | ||
194 | typedef priority_map<string> uris_t; | ||
195 | |||
196 | class service_t { | ||
197 | public: | ||
198 | types_t types; | ||
199 | uris_t uris; | ||
200 | local_ids_t local_ids; | ||
201 | |||
202 | void clear() { | ||
203 | types.clear(); | ||
204 | uris.clear(); local_ids.clear(); | ||
205 | } | ||
206 | }; | ||
207 | typedef priority_map<service_t> services_t; | ||
208 | |||
209 | class XRD_t { | ||
210 | public: | ||
211 | time_t expires; | ||
212 | |||
213 | canonical_ids_t canonical_ids; | ||
214 | local_ids_t local_ids; | ||
215 | services_t services; | ||
216 | |||
217 | void clear() { | ||
218 | expires = 0; | ||
219 | canonical_ids.clear(); local_ids.clear(); | ||
220 | services.clear(); | ||
221 | } | ||
222 | bool empty() const { | ||
223 | return | ||
224 | canonical_ids.empty() | ||
225 | && local_ids.empty() | ||
226 | && services.empty(); | ||
227 | } | ||
228 | |||
229 | }; | ||
230 | |||
231 | } | ||
232 | |||
170 | } | 233 | } |
171 | 234 | ||
172 | #endif /* __OPKELE_TYPES_H */ | 235 | #endif /* __OPKELE_TYPES_H */ |