Panda3D
documentSpec.I
1 // Filename: documentSpec.I
2 // Created by: drose (28Jan03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: DocumentSpec::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE DocumentSpec::
22 DocumentSpec() {
23  _request_mode = RM_any;
24  _cache_control = CC_allow_cache;
25  _flags = 0;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: DocumentSpec::Constructor
30 // Access: Published
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE DocumentSpec::
34 DocumentSpec(const string &url) :
35  _url(url)
36 {
37  _request_mode = RM_any;
38  _cache_control = CC_allow_cache;
39  _flags = 0;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: DocumentSpec::Constructor
44 // Access: Published
45 // Description:
46 ////////////////////////////////////////////////////////////////////
47 INLINE DocumentSpec::
48 DocumentSpec(const URLSpec &url) :
49  _url(url)
50 {
51  _request_mode = RM_any;
52  _cache_control = CC_allow_cache;
53  _flags = 0;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: DocumentSpec::Copy Constructor
58 // Access: Published
59 // Description:
60 ////////////////////////////////////////////////////////////////////
61 INLINE DocumentSpec::
62 DocumentSpec(const DocumentSpec &copy) :
63  _url(copy._url),
64  _tag(copy._tag),
65  _date(copy._date),
66  _request_mode(copy._request_mode),
67  _cache_control(copy._cache_control),
68  _flags(copy._flags)
69 {
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: DocumentSpec::Copy Assignment Operator
74 // Access: Published
75 // Description:
76 ////////////////////////////////////////////////////////////////////
77 INLINE void DocumentSpec::
78 operator = (const DocumentSpec &copy) {
79  _url = copy._url;
80  _tag = copy._tag;
81  _date = copy._date;
82  _request_mode = copy._request_mode;
83  _cache_control = copy._cache_control;
84  _flags = copy._flags;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: DocumentSpec::operator ==
89 // Access: Published
90 // Description:
91 ////////////////////////////////////////////////////////////////////
92 INLINE bool DocumentSpec::
93 operator == (const DocumentSpec &other) const {
94  return compare_to(other) == 0;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: DocumentSpec::operator !=
99 // Access: Published
100 // Description:
101 ////////////////////////////////////////////////////////////////////
102 INLINE bool DocumentSpec::
103 operator != (const DocumentSpec &other) const {
104  return compare_to(other) != 0;
105 }
106 
107 ////////////////////////////////////////////////////////////////////
108 // Function: DocumentSpec::operator <
109 // Access: Published
110 // Description:
111 ////////////////////////////////////////////////////////////////////
112 INLINE bool DocumentSpec::
113 operator < (const DocumentSpec &other) const {
114  return compare_to(other) < 0;
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: DocumentSpec::set_url
119 // Access: Published
120 // Description: Changes the URL of the DocumentSpec without modifying
121 // its other properties. Normally this would be a
122 // strange thing to do, because the tag and date are
123 // usually strongly associated with the URL. To get a
124 // DocumentSpec pointing to a new URL, you would
125 // normally create a new DocumentSpec object.
126 ////////////////////////////////////////////////////////////////////
127 INLINE void DocumentSpec::
128 set_url(const URLSpec &url) {
129  _url = url;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: DocumentSpec::get_url
134 // Access: Published
135 // Description: Retrieves the URL of the DocumentSpec.
136 ////////////////////////////////////////////////////////////////////
137 INLINE const URLSpec &DocumentSpec::
138 get_url() const {
139  return _url;
140 }
141 
142 ////////////////////////////////////////////////////////////////////
143 // Function: DocumentSpec::set_tag
144 // Access: Published
145 // Description: Changes the identity tag associated with the
146 // DocumentSpec.
147 ////////////////////////////////////////////////////////////////////
148 INLINE void DocumentSpec::
149 set_tag(const HTTPEntityTag &tag) {
150  _tag = tag;
151  _flags |= F_has_tag;
152 }
153 
154 ////////////////////////////////////////////////////////////////////
155 // Function: DocumentSpec::has_tag
156 // Access: Published
157 // Description: Returns true if an identity tag is associated with
158 // the DocumentSpec.
159 ////////////////////////////////////////////////////////////////////
160 INLINE bool DocumentSpec::
161 has_tag() const {
162  return (_flags & F_has_tag) != 0;
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: DocumentSpec::get_tag
167 // Access: Published
168 // Description: Returns the identity tag associated with the
169 // DocumentSpec, if there is one. It is an error to
170 // call this if has_tag() returns false.
171 //
172 // The identity tag is set by the HTTP server to
173 // uniquely refer to a particular version of a document.
174 ////////////////////////////////////////////////////////////////////
175 INLINE const HTTPEntityTag &DocumentSpec::
176 get_tag() const {
177  nassertr(has_tag(), _tag);
178  return _tag;
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: DocumentSpec::clear_tag
183 // Access: Published
184 // Description: Removes the identity tag associated with the
185 // DocumentSpec, if there is one.
186 ////////////////////////////////////////////////////////////////////
187 INLINE void DocumentSpec::
189  _flags &= ~F_has_tag;
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: DocumentSpec::set_date
194 // Access: Published
195 // Description: Changes the last-modified date associated with the
196 // DocumentSpec.
197 ////////////////////////////////////////////////////////////////////
198 INLINE void DocumentSpec::
199 set_date(const HTTPDate &date) {
200  _date = date;
201  _flags |= F_has_date;
202 }
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: DocumentSpec::has_date
206 // Access: Published
207 // Description: Returns true if a last-modified date is associated
208 // with the DocumentSpec.
209 ////////////////////////////////////////////////////////////////////
210 INLINE bool DocumentSpec::
211 has_date() const {
212  return (_flags & F_has_date) != 0;
213 }
214 
215 ////////////////////////////////////////////////////////////////////
216 // Function: DocumentSpec::get_date
217 // Access: Published
218 // Description: Returns the last-modified date associated with the
219 // DocumentSpec, if there is one. It is an error to
220 // call this if has_date() returns false.
221 ////////////////////////////////////////////////////////////////////
222 INLINE const HTTPDate &DocumentSpec::
223 get_date() const {
224  nassertr(has_date(), _date);
225  return _date;
226 }
227 
228 ////////////////////////////////////////////////////////////////////
229 // Function: DocumentSpec::clear_date
230 // Access: Published
231 // Description: Removes the last-modified date associated with the
232 // DocumentSpec, if there is one.
233 ////////////////////////////////////////////////////////////////////
234 INLINE void DocumentSpec::
236  _flags &= ~F_has_date;
237 }
238 
239 ////////////////////////////////////////////////////////////////////
240 // Function: DocumentSpec::set_request_mode
241 // Access: Published
242 // Description: Sets the request mode of this DocumentSpec. This is
243 // only relevant when using the DocumentSpec to generate
244 // a request (for instance, in HTTPChannel). This
245 // specifies whether the document request will ask the
246 // server for a newer version than the indicated
247 // version, or the exact version, neither, or either.
248 //
249 // The possible values are:
250 //
251 // RM_any: ignore date and tag (if specified), and
252 // retrieve any document that matches the URL. For a
253 // subrange request, if the document matches the
254 // version indicated exactly, retrieve the subrange
255 // only; otherwise, retrieve the entire document.
256 //
257 // RM_equal: request only the precise version of the
258 // document that matches the particular date and/or
259 // tag exactly, if specified; fail if this version is
260 // not available.
261 //
262 // RM_newer: request any document that is newer than
263 // the version indicated by the particular date and/or
264 // tag; fail if only that version (or older versions)
265 // are available.
266 //
267 // RM_newer_or_equal: request any document that
268 // matches the version indicated by the particular
269 // date and/or tag, or is a newer version; fail if
270 // only older versions are available.
271 //
272 // In any of the above, you may specify either or both
273 // of the last-modified date and the identity tag,
274 // whichever is known to the client.
275 //
276 // The default mode is RM_any.
277 ////////////////////////////////////////////////////////////////////
278 INLINE void DocumentSpec::
279 set_request_mode(DocumentSpec::RequestMode request_mode) {
280  _request_mode = request_mode;
281 }
282 
283 ////////////////////////////////////////////////////////////////////
284 // Function: DocumentSpec::get_request_mode
285 // Access: Published
286 // Description: Returns the request mode of this DocumentSpec. See
287 // set_request_mode().
288 ////////////////////////////////////////////////////////////////////
289 INLINE DocumentSpec::RequestMode DocumentSpec::
291  return _request_mode;
292 }
293 
294 ////////////////////////////////////////////////////////////////////
295 // Function: DocumentSpec::set_cache_control
296 // Access: Published
297 // Description: Specifies what kind of cached value is acceptable for
298 // this document. Warning: some HTTP proxies may not
299 // respect this setting and may return a cached result
300 // anyway.
301 //
302 // CC_allow_cache: the normal HTTP behavior; the
303 // server may return a cached value if it believes it
304 // is valid.
305 //
306 // CC_revalidate: a proxy is forced to contact the
307 // origin server and verify that is cached value is in
308 // fact still valid before it returns it.
309 //
310 // CC_no_cache: a proxy must not return its cached
311 // value at all, but is forced to go all the way back
312 // to the origin server for the official document.
313 //
314 // The default mode is CC_allow_cache.
315 ////////////////////////////////////////////////////////////////////
316 INLINE void DocumentSpec::
317 set_cache_control(DocumentSpec::CacheControl cache_control) {
318  _cache_control = cache_control;
319 }
320 
321 ////////////////////////////////////////////////////////////////////
322 // Function: DocumentSpec::get_cache_control
323 // Access: Published
324 // Description: Returns the request mode of this DocumentSpec. See
325 // set_cache_control().
326 ////////////////////////////////////////////////////////////////////
327 INLINE DocumentSpec::CacheControl DocumentSpec::
329  return _cache_control;
330 }
331 
332 INLINE istream &
333 operator >> (istream &in, DocumentSpec &doc) {
334  if (!doc.input(in)) {
335  in.clear(ios::failbit | in.rdstate());
336  }
337  return in;
338 }
339 
340 INLINE ostream &
341 operator << (ostream &out, const DocumentSpec &doc) {
342  doc.output(out);
343  return out;
344 }
void clear_tag()
Removes the identity tag associated with the DocumentSpec, if there is one.
Definition: documentSpec.I:188
A container for a URL, e.g.
Definition: urlSpec.h:29
const URLSpec & get_url() const
Retrieves the URL of the DocumentSpec.
Definition: documentSpec.I:138
A container for an "entity tag" from an HTTP server.
Definition: httpEntityTag.h:27
bool has_date() const
Returns true if a last-modified date is associated with the DocumentSpec.
Definition: documentSpec.I:211
void set_cache_control(CacheControl cache_control)
Specifies what kind of cached value is acceptable for this document.
Definition: documentSpec.I:317
void set_date(const HTTPDate &date)
Changes the last-modified date associated with the DocumentSpec.
Definition: documentSpec.I:199
bool input(istream &in)
Can be used to read in the DocumentSpec from a stream generated either by output() or write()...
void set_request_mode(RequestMode request_mode)
Sets the request mode of this DocumentSpec.
Definition: documentSpec.I:279
void set_tag(const HTTPEntityTag &tag)
Changes the identity tag associated with the DocumentSpec.
Definition: documentSpec.I:149
RequestMode get_request_mode() const
Returns the request mode of this DocumentSpec.
Definition: documentSpec.I:290
const HTTPDate & get_date() const
Returns the last-modified date associated with the DocumentSpec, if there is one. ...
Definition: documentSpec.I:223
void set_url(const URLSpec &url)
Changes the URL of the DocumentSpec without modifying its other properties.
Definition: documentSpec.I:128
const HTTPEntityTag & get_tag() const
Returns the identity tag associated with the DocumentSpec, if there is one.
Definition: documentSpec.I:176
A container for an HTTP-legal time/date indication.
Definition: httpDate.h:30
void clear_date()
Removes the last-modified date associated with the DocumentSpec, if there is one. ...
Definition: documentSpec.I:235
An STL function object class, this is intended to be used on any ordered collection of class objects ...
Definition: stl_compares.h:79
CacheControl get_cache_control() const
Returns the request mode of this DocumentSpec.
Definition: documentSpec.I:328
A descriptor that refers to a particular version of a document.
Definition: documentSpec.h:33
bool has_tag() const
Returns true if an identity tag is associated with the DocumentSpec.
Definition: documentSpec.I:161