Panda3D
httpDate.I
1 // Filename: httpDate.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: HTTPDate::Constructor
18 // Access: Published
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE HTTPDate::
22 HTTPDate() : _time(-1) {
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: HTTPDate::Constructor
27 // Access: Published
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 INLINE HTTPDate::
31 HTTPDate(time_t time) : _time(time) {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: HTTPDate::Copy Constructor
36 // Access: Published
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 INLINE HTTPDate::
40 HTTPDate(const HTTPDate &copy) : _time(copy._time) {
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: HTTPDate::Copy Assignment Operator
45 // Access: Published
46 // Description:
47 ////////////////////////////////////////////////////////////////////
48 INLINE void HTTPDate::
49 operator = (const HTTPDate &copy) {
50  _time = copy._time;
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: HTTPDate::now (named constructor)
55 // Access: Published, Static
56 // Description: Returns an HTTPDate that represents the current time
57 // and date.
58 ////////////////////////////////////////////////////////////////////
59 INLINE HTTPDate HTTPDate::
60 now() {
61  return HTTPDate(time(NULL));
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: HTTPDate::is_valid
66 // Access: Published
67 // Description: Returns true if the date is meaningful, or false if
68 // it is -1 (which generally indicates the source string
69 // could not be parsed.)
70 ////////////////////////////////////////////////////////////////////
71 INLINE bool HTTPDate::
72 is_valid() const {
73  return (_time != (time_t)(-1));
74 }
75 
76 ////////////////////////////////////////////////////////////////////
77 // Function: HTTPDate::get_time
78 // Access: Published
79 // Description: Returns the date as a C time_t value.
80 ////////////////////////////////////////////////////////////////////
81 INLINE time_t HTTPDate::
82 get_time() const {
83  return _time;
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: HTTPDate::Operator ==
88 // Access: Published
89 // Description:
90 ////////////////////////////////////////////////////////////////////
91 INLINE bool HTTPDate::
92 operator == (const HTTPDate &other) const {
93  return _time == other._time;
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: HTTPDate::Operator !=
98 // Access: Published
99 // Description:
100 ////////////////////////////////////////////////////////////////////
101 INLINE bool HTTPDate::
102 operator != (const HTTPDate &other) const {
103  return !operator == (other);
104 }
105 
106 ////////////////////////////////////////////////////////////////////
107 // Function: HTTPDate::Operator <
108 // Access: Published
109 // Description:
110 ////////////////////////////////////////////////////////////////////
111 INLINE bool HTTPDate::
112 operator < (const HTTPDate &other) const {
113  return _time < other._time;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: HTTPDate::Operator >
118 // Access: Published
119 // Description:
120 ////////////////////////////////////////////////////////////////////
121 INLINE bool HTTPDate::
122 operator > (const HTTPDate &other) const {
123  return _time > other._time;
124 }
125 
126 ////////////////////////////////////////////////////////////////////
127 // Function: HTTPDate::compare_to
128 // Access: Published
129 // Description: Returns a number less than zero if this HTTPDate
130 // sorts before the other one, greater than zero if it
131 // sorts after, or zero if they are equivalent.
132 ////////////////////////////////////////////////////////////////////
133 INLINE int HTTPDate::
134 compare_to(const HTTPDate &other) const {
135  return (int)(_time - other._time);
136 }
137 
138 ////////////////////////////////////////////////////////////////////
139 // Function: HTTPDate::operator +=
140 // Access: Published
141 // Description:
142 ////////////////////////////////////////////////////////////////////
143 INLINE void HTTPDate::
144 operator += (int seconds) {
145  _time += seconds;
146 }
147 
148 ////////////////////////////////////////////////////////////////////
149 // Function: HTTPDate::operator -=
150 // Access: Published
151 // Description:
152 ////////////////////////////////////////////////////////////////////
153 INLINE void HTTPDate::
154 operator -= (int seconds) {
155  _time -= seconds;
156 }
157 
158 ////////////////////////////////////////////////////////////////////
159 // Function: HTTPDate::operator +
160 // Access: Published
161 // Description:
162 ////////////////////////////////////////////////////////////////////
163 INLINE HTTPDate HTTPDate::
164 operator + (int seconds) const {
165  return HTTPDate(_time + seconds);
166 }
167 
168 ////////////////////////////////////////////////////////////////////
169 // Function: HTTPDate::operator -
170 // Access: Published
171 // Description:
172 ////////////////////////////////////////////////////////////////////
173 INLINE HTTPDate HTTPDate::
174 operator - (int seconds) const {
175  return HTTPDate(_time - seconds);
176 }
177 
178 ////////////////////////////////////////////////////////////////////
179 // Function: HTTPDate::operator -
180 // Access: Published
181 // Description:
182 ////////////////////////////////////////////////////////////////////
183 INLINE int HTTPDate::
184 operator - (const HTTPDate &other) const {
185  return (int)(_time - other._time);
186 }
187 
188 
189 INLINE istream &
190 operator >> (istream &in, HTTPDate &date) {
191  if (!date.input(in)) {
192  in.clear(ios::failbit | in.rdstate());
193  }
194  return in;
195 }
196 
197 INLINE ostream &
198 operator << (ostream &out, const HTTPDate &date) {
199  date.output(out);
200  return out;
201 }
202 
203 
bool is_valid() const
Returns true if the date is meaningful, or false if it is -1 (which generally indicates the source st...
Definition: httpDate.I:72
int compare_to(const HTTPDate &other) const
Returns a number less than zero if this HTTPDate sorts before the other one, greater than zero if it ...
Definition: httpDate.I:134
A container for an HTTP-legal time/date indication.
Definition: httpDate.h:30
static HTTPDate now()
Returns an HTTPDate that represents the current time and date.
Definition: httpDate.I:60
time_t get_time() const
Returns the date as a C time_t value.
Definition: httpDate.I:82