Panda3D
httpEntityTag.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 httpEntityTag.I
10  * @author drose
11  * @date 2003-01-28
12  */
13 
14 /**
15  *
16  */
17 INLINE HTTPEntityTag::
18 HTTPEntityTag() {
19  _weak = false;
20 }
21 
22 /**
23  * This constructor accepts an explicit weak flag and a literal (not quoted)
24  * tag string.
25  */
26 INLINE HTTPEntityTag::
27 HTTPEntityTag(bool weak, const std::string &tag) :
28  _weak(weak),
29  _tag(tag)
30 {
31 }
32 
33 /**
34  *
35  */
36 INLINE HTTPEntityTag::
37 HTTPEntityTag(const HTTPEntityTag &copy) :
38  _weak(copy._weak),
39  _tag(copy._tag)
40 {
41 }
42 
43 /**
44  *
45  */
46 INLINE void HTTPEntityTag::
47 operator = (const HTTPEntityTag &copy) {
48  _weak = copy._weak;
49  _tag = copy._tag;
50 }
51 
52 /**
53  * Returns true if the entity tag is marked as "weak". A consistent weak
54  * entity tag does not guarantee that its resource has not changed in any way,
55  * but it does promise that the resource has not changed in any semantically
56  * meaningful way.
57  */
58 INLINE bool HTTPEntityTag::
59 is_weak() const {
60  return _weak;
61 }
62 
63 /**
64  * Returns the tag as a literal string.
65  */
66 INLINE const std::string &HTTPEntityTag::
67 get_tag() const {
68  return _tag;
69 }
70 
71 /**
72  * Returns true if the two tags have "strong" equivalence: they are the same
73  * tag, and both are "strong".
74  */
75 INLINE bool HTTPEntityTag::
76 strong_equiv(const HTTPEntityTag &other) const {
77  return _tag == other._tag && !_weak && !other._weak;
78 }
79 
80 /**
81  * Returns true if the two tags have "weak" equivalence: they are the same
82  * tag, and one or both may be "weak".
83  */
84 INLINE bool HTTPEntityTag::
85 weak_equiv(const HTTPEntityTag &other) const {
86  return _tag == other._tag;
87 }
88 
89 /**
90  * The == operator tests object equivalence; see also strong_equiv() and
91  * weak_equiv() for the two kinds of HTTP equivalence.
92  */
93 INLINE bool HTTPEntityTag::
94 operator == (const HTTPEntityTag &other) const {
95  return _weak == other._weak && _tag == other._tag;
96 }
97 
98 /**
99  *
100  */
101 INLINE bool HTTPEntityTag::
102 operator != (const HTTPEntityTag &other) const {
103  return !operator == (other);
104 }
105 
106 /**
107  *
108  */
109 INLINE bool HTTPEntityTag::
110 operator < (const HTTPEntityTag &other) const {
111  if (_weak != other._weak) {
112  return (int)_weak < (int)other._weak;
113  }
114  return _tag < other._tag;
115 }
116 
117 /**
118  * Returns a number less than zero if this HTTPEntityTag sorts before the
119  * other one, greater than zero if it sorts after, or zero if they are
120  * equivalent.
121  */
122 INLINE int HTTPEntityTag::
123 compare_to(const HTTPEntityTag &other) const {
124  if (_weak != other._weak) {
125  return (int)_weak - (int)other._weak;
126  }
127  return strcmp(_tag.c_str(), other._tag.c_str());
128 }
129 
130 /**
131  *
132  */
133 INLINE void HTTPEntityTag::
134 output(std::ostream &out) const {
135  out << get_string();
136 }
137 
138 
139 INLINE std::ostream &
140 operator << (std::ostream &out, const HTTPEntityTag &entityTag) {
141  entityTag.output(out);
142  return out;
143 }
bool is_weak() const
Returns true if the entity tag is marked as "weak".
Definition: httpEntityTag.I:59
A container for an "entity tag" from an HTTP server.
Definition: httpEntityTag.h:24
bool operator==(const HTTPEntityTag &other) const
The == operator tests object equivalence; see also strong_equiv() and weak_equiv() for the two kinds ...
Definition: httpEntityTag.I:94
int compare_to(const HTTPEntityTag &other) const
Returns a number less than zero if this HTTPEntityTag sorts before the other one, greater than zero i...
std::string get_string() const
Returns the entity tag formatted for sending to an HTTP server (the tag is quoted,...
bool strong_equiv(const HTTPEntityTag &other) const
Returns true if the two tags have "strong" equivalence: they are the same tag, and both are "strong".
Definition: httpEntityTag.I:76
const std::string & get_tag() const
Returns the tag as a literal string.
Definition: httpEntityTag.I:67
bool weak_equiv(const HTTPEntityTag &other) const
Returns true if the two tags have "weak" equivalence: they are the same tag, and one or both may be "...
Definition: httpEntityTag.I:85