Panda3D
 All Classes Functions Variables Enumerations
httpEntityTag.I
1 // Filename: httpEntityTag.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: HTTPEntityTag::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE HTTPEntityTag::
22 HTTPEntityTag() {
23  _weak = false;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: HTTPEntityTag::Constructor
28 // Access: Published
29 // Description: This constructor accepts an explicit weak flag and a
30 // literal (not quoted) tag string.
31 ////////////////////////////////////////////////////////////////////
32 INLINE HTTPEntityTag::
33 HTTPEntityTag(bool weak, const string &tag) :
34  _weak(weak),
35  _tag(tag)
36 {
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: HTTPEntityTag::Copy Constructor
41 // Access: Published
42 // Description:
43 ////////////////////////////////////////////////////////////////////
44 INLINE HTTPEntityTag::
45 HTTPEntityTag(const HTTPEntityTag &copy) :
46  _weak(copy._weak),
47  _tag(copy._tag)
48 {
49 }
50 
51 ////////////////////////////////////////////////////////////////////
52 // Function: HTTPEntityTag::Copy Assignment Operator
53 // Access: Published
54 // Description:
55 ////////////////////////////////////////////////////////////////////
56 INLINE void HTTPEntityTag::
57 operator = (const HTTPEntityTag &copy) {
58  _weak = copy._weak;
59  _tag = copy._tag;
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: HTTPEntityTag::is_weak
64 // Access: Published
65 // Description: Returns true if the entity tag is marked as "weak".
66 // A consistent weak entity tag does not guarantee that
67 // its resource has not changed in any way, but it does
68 // promise that the resource has not changed in any
69 // semantically meaningful way.
70 ////////////////////////////////////////////////////////////////////
71 INLINE bool HTTPEntityTag::
72 is_weak() const {
73  return _weak;
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: HTTPEntityTag::get_tag
78 // Access: Published
79 // Description: Returns the tag as a literal string.
80 ////////////////////////////////////////////////////////////////////
81 INLINE const string &HTTPEntityTag::
82 get_tag() const {
83  return _tag;
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: HTTPEntityTag::strong_equiv
88 // Access: Published
89 // Description: Returns true if the two tags have "strong" equivalence:
90 // they are the same tag, and both are "strong".
91 ////////////////////////////////////////////////////////////////////
92 INLINE bool HTTPEntityTag::
93 strong_equiv(const HTTPEntityTag &other) const {
94  return _tag == other._tag && !_weak && !other._weak;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: HTTPEntityTag::weak_equiv
99 // Access: Published
100 // Description: Returns true if the two tags have "weak" equivalence:
101 // they are the same tag, and one or both may be "weak".
102 ////////////////////////////////////////////////////////////////////
103 INLINE bool HTTPEntityTag::
104 weak_equiv(const HTTPEntityTag &other) const {
105  return _tag == other._tag;
106 }
107 
108 ////////////////////////////////////////////////////////////////////
109 // Function: HTTPEntityTag::Operator ==
110 // Access: Published
111 // Description: The == operator tests object equivalence; see also
112 // strong_equiv() and weak_equiv() for the two kinds of
113 // HTTP equivalence.
114 ////////////////////////////////////////////////////////////////////
115 INLINE bool HTTPEntityTag::
116 operator == (const HTTPEntityTag &other) const {
117  return _weak == other._weak && _tag == other._tag;
118 }
119 
120 ////////////////////////////////////////////////////////////////////
121 // Function: HTTPEntityTag::Operator !=
122 // Access: Published
123 // Description:
124 ////////////////////////////////////////////////////////////////////
125 INLINE bool HTTPEntityTag::
126 operator != (const HTTPEntityTag &other) const {
127  return !operator == (other);
128 }
129 
130 ////////////////////////////////////////////////////////////////////
131 // Function: HTTPEntityTag::Operator <
132 // Access: Published
133 // Description:
134 ////////////////////////////////////////////////////////////////////
135 INLINE bool HTTPEntityTag::
136 operator < (const HTTPEntityTag &other) const {
137  if (_weak != other._weak) {
138  return (int)_weak < (int)other._weak;
139  }
140  return _tag < other._tag;
141 }
142 
143 ////////////////////////////////////////////////////////////////////
144 // Function: HTTPEntityTag::compare_to
145 // Access: Published
146 // Description: Returns a number less than zero if this HTTPEntityTag
147 // sorts before the other one, greater than zero if it
148 // sorts after, or zero if they are equivalent.
149 ////////////////////////////////////////////////////////////////////
150 INLINE int HTTPEntityTag::
151 compare_to(const HTTPEntityTag &other) const {
152  if (_weak != other._weak) {
153  return (int)_weak - (int)other._weak;
154  }
155  return strcmp(_tag.c_str(), other._tag.c_str());
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: HTTPEntityTag::output
160 // Access: Published
161 // Description:
162 ////////////////////////////////////////////////////////////////////
163 INLINE void HTTPEntityTag::
164 output(ostream &out) const {
165  out << get_string();
166 }
167 
168 
169 INLINE ostream &
170 operator << (ostream &out, const HTTPEntityTag &entityTag) {
171  entityTag.output(out);
172  return out;
173 }
174 
175 
A container for an &quot;entity tag&quot; from an HTTP server.
Definition: httpEntityTag.h:27
bool strong_equiv(const HTTPEntityTag &other) const
Returns true if the two tags have &quot;strong&quot; equivalence: they are the same tag, and both are &quot;strong&quot;...
Definition: httpEntityTag.I:93
bool operator==(const HTTPEntityTag &other) const
The == operator tests object equivalence; see also strong_equiv() and weak_equiv() for the two kinds ...
bool is_weak() const
Returns true if the entity tag is marked as &quot;weak&quot;.
Definition: httpEntityTag.I:72
string get_string() const
Returns the entity tag formatted for sending to an HTTP server (the tag is quoted, with a conditional W/ prefix).
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...
bool weak_equiv(const HTTPEntityTag &other) const
Returns true if the two tags have &quot;weak&quot; equivalence: they are the same tag, and one or both may be &quot;...
const string & get_tag() const
Returns the tag as a literal string.
Definition: httpEntityTag.I:82