Panda3D
|
00001 // Filename: httpDate.I 00002 // Created by: drose (28Jan03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: HTTPDate::Constructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE HTTPDate:: 00022 HTTPDate() : _time(-1) { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: HTTPDate::Constructor 00027 // Access: Published 00028 // Description: 00029 //////////////////////////////////////////////////////////////////// 00030 INLINE HTTPDate:: 00031 HTTPDate(time_t time) : _time(time) { 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: HTTPDate::Copy Constructor 00036 // Access: Published 00037 // Description: 00038 //////////////////////////////////////////////////////////////////// 00039 INLINE HTTPDate:: 00040 HTTPDate(const HTTPDate ©) : _time(copy._time) { 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: HTTPDate::Copy Assignment Operator 00045 // Access: Published 00046 // Description: 00047 //////////////////////////////////////////////////////////////////// 00048 INLINE void HTTPDate:: 00049 operator = (const HTTPDate ©) { 00050 _time = copy._time; 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: HTTPDate::now (named constructor) 00055 // Access: Published, Static 00056 // Description: Returns an HTTPDate that represents the current time 00057 // and date. 00058 //////////////////////////////////////////////////////////////////// 00059 INLINE HTTPDate HTTPDate:: 00060 now() { 00061 return HTTPDate(time(NULL)); 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: HTTPDate::is_valid 00066 // Access: Published 00067 // Description: Returns true if the date is meaningful, or false if 00068 // it is -1 (which generally indicates the source string 00069 // could not be parsed.) 00070 //////////////////////////////////////////////////////////////////// 00071 INLINE bool HTTPDate:: 00072 is_valid() const { 00073 return (_time != (time_t)(-1)); 00074 } 00075 00076 //////////////////////////////////////////////////////////////////// 00077 // Function: HTTPDate::get_time 00078 // Access: Published 00079 // Description: Returns the date as a C time_t value. 00080 //////////////////////////////////////////////////////////////////// 00081 INLINE time_t HTTPDate:: 00082 get_time() const { 00083 return _time; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: HTTPDate::Operator == 00088 // Access: Published 00089 // Description: 00090 //////////////////////////////////////////////////////////////////// 00091 INLINE bool HTTPDate:: 00092 operator == (const HTTPDate &other) const { 00093 return _time == other._time; 00094 } 00095 00096 //////////////////////////////////////////////////////////////////// 00097 // Function: HTTPDate::Operator != 00098 // Access: Published 00099 // Description: 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE bool HTTPDate:: 00102 operator != (const HTTPDate &other) const { 00103 return !operator == (other); 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: HTTPDate::Operator < 00108 // Access: Published 00109 // Description: 00110 //////////////////////////////////////////////////////////////////// 00111 INLINE bool HTTPDate:: 00112 operator < (const HTTPDate &other) const { 00113 return _time < other._time; 00114 } 00115 00116 //////////////////////////////////////////////////////////////////// 00117 // Function: HTTPDate::Operator > 00118 // Access: Published 00119 // Description: 00120 //////////////////////////////////////////////////////////////////// 00121 INLINE bool HTTPDate:: 00122 operator > (const HTTPDate &other) const { 00123 return _time > other._time; 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: HTTPDate::compare_to 00128 // Access: Published 00129 // Description: Returns a number less than zero if this HTTPDate 00130 // sorts before the other one, greater than zero if it 00131 // sorts after, or zero if they are equivalent. 00132 //////////////////////////////////////////////////////////////////// 00133 INLINE int HTTPDate:: 00134 compare_to(const HTTPDate &other) const { 00135 return (int)(_time - other._time); 00136 } 00137 00138 //////////////////////////////////////////////////////////////////// 00139 // Function: HTTPDate::operator += 00140 // Access: Published 00141 // Description: 00142 //////////////////////////////////////////////////////////////////// 00143 INLINE void HTTPDate:: 00144 operator += (int seconds) { 00145 _time += seconds; 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: HTTPDate::operator -= 00150 // Access: Published 00151 // Description: 00152 //////////////////////////////////////////////////////////////////// 00153 INLINE void HTTPDate:: 00154 operator -= (int seconds) { 00155 _time -= seconds; 00156 } 00157 00158 //////////////////////////////////////////////////////////////////// 00159 // Function: HTTPDate::operator + 00160 // Access: Published 00161 // Description: 00162 //////////////////////////////////////////////////////////////////// 00163 INLINE HTTPDate HTTPDate:: 00164 operator + (int seconds) const { 00165 return HTTPDate(_time + seconds); 00166 } 00167 00168 //////////////////////////////////////////////////////////////////// 00169 // Function: HTTPDate::operator - 00170 // Access: Published 00171 // Description: 00172 //////////////////////////////////////////////////////////////////// 00173 INLINE HTTPDate HTTPDate:: 00174 operator - (int seconds) const { 00175 return HTTPDate(_time - seconds); 00176 } 00177 00178 //////////////////////////////////////////////////////////////////// 00179 // Function: HTTPDate::operator - 00180 // Access: Published 00181 // Description: 00182 //////////////////////////////////////////////////////////////////// 00183 INLINE int HTTPDate:: 00184 operator - (const HTTPDate &other) const { 00185 return (int)(_time - other._time); 00186 } 00187 00188 00189 INLINE istream & 00190 operator >> (istream &in, HTTPDate &date) { 00191 if (!date.input(in)) { 00192 in.clear(ios::failbit | in.rdstate()); 00193 } 00194 return in; 00195 } 00196 00197 INLINE ostream & 00198 operator << (ostream &out, const HTTPDate &date) { 00199 date.output(out); 00200 return out; 00201 } 00202 00203