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