00001 // Filename: updateSeq.I 00002 // Created by: drose (30Sep99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: UpdateSeq::Default Constructor 00022 // Access: Public 00023 // Description: Creates an UpdateSeq in the 'initial' state. 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE UpdateSeq:: 00026 UpdateSeq() { 00027 _seq = (unsigned int)SC_initial; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: UpdateSeq::initial (named constructor) 00032 // Access: Public, Static 00033 // Description: Returns an UpdateSeq in the 'initial' state. 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE UpdateSeq UpdateSeq:: 00036 initial() { 00037 return UpdateSeq(); 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: UpdateSeq::old (named constructor) 00042 // Access: Public, Static 00043 // Description: Returns an UpdateSeq in the 'old' state. 00044 //////////////////////////////////////////////////////////////////// 00045 INLINE UpdateSeq UpdateSeq:: 00046 old() { 00047 UpdateSeq result; 00048 result._seq = (unsigned int)SC_old; 00049 return result; 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: UpdateSeq::fresh (named constructor) 00054 // Access: Public, Static 00055 // Description: Returns an UpdateSeq in the 'fresh' state. 00056 //////////////////////////////////////////////////////////////////// 00057 INLINE UpdateSeq UpdateSeq:: 00058 fresh() { 00059 UpdateSeq result; 00060 result._seq = (unsigned int)SC_fresh; 00061 return result; 00062 } 00063 00064 //////////////////////////////////////////////////////////////////// 00065 // Function: UpdateSeq::Copy Constructor 00066 // Access: Public 00067 // Description: 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE UpdateSeq:: 00070 UpdateSeq(const UpdateSeq ©) { 00071 _seq = copy._seq; 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: UpdateSeq::Copy Assignment operator 00076 // Access: Public 00077 // Description: 00078 //////////////////////////////////////////////////////////////////// 00079 INLINE UpdateSeq &UpdateSeq:: 00080 operator = (const UpdateSeq ©) { 00081 _seq = copy._seq; 00082 return *this; 00083 } 00084 00085 //////////////////////////////////////////////////////////////////// 00086 // Function: UpdateSeq::clear 00087 // Access: Public 00088 // Description: Resets the UpdateSeq to the 'initial' state. 00089 //////////////////////////////////////////////////////////////////// 00090 INLINE void UpdateSeq:: 00091 clear() { 00092 _seq = (unsigned int)SC_initial; 00093 } 00094 00095 //////////////////////////////////////////////////////////////////// 00096 // Function: UpdateSeq::is_initial 00097 // Access: Public 00098 // Description: Returns true if the UpdateSeq is in the 'initial' 00099 // state. 00100 //////////////////////////////////////////////////////////////////// 00101 INLINE bool UpdateSeq:: 00102 is_initial() const { 00103 return _seq == (unsigned int)SC_initial; 00104 } 00105 00106 //////////////////////////////////////////////////////////////////// 00107 // Function: UpdateSeq::is_old 00108 // Access: Public 00109 // Description: Returns true if the UpdateSeq is in the 'old' state. 00110 //////////////////////////////////////////////////////////////////// 00111 INLINE bool UpdateSeq:: 00112 is_old() const { 00113 return _seq == (unsigned int)SC_old; 00114 } 00115 00116 //////////////////////////////////////////////////////////////////// 00117 // Function: UpdateSeq::is_fresh 00118 // Access: Public 00119 // Description: Returns true if the UpdateSeq is in the 'fresh' 00120 // state. 00121 //////////////////////////////////////////////////////////////////// 00122 INLINE bool UpdateSeq:: 00123 is_fresh() const { 00124 return _seq == (unsigned int)SC_fresh; 00125 } 00126 00127 //////////////////////////////////////////////////////////////////// 00128 // Function: UpdateSeq::is_special 00129 // Access: Public 00130 // Description: Returns true if the UpdateSeq is in any special 00131 // states, i.e. 'initial', 'old', or 'fresh'. 00132 //////////////////////////////////////////////////////////////////// 00133 INLINE bool UpdateSeq:: 00134 is_special() const { 00135 switch (_seq) { 00136 case (unsigned int)SC_initial: 00137 case (unsigned int)SC_old: 00138 case (unsigned int)SC_fresh: 00139 return true; 00140 00141 default: 00142 return false; 00143 } 00144 } 00145 00146 //////////////////////////////////////////////////////////////////// 00147 // Function: UpdateSeq::Equality operator 00148 // Access: Public 00149 // Description: 00150 //////////////////////////////////////////////////////////////////// 00151 INLINE bool UpdateSeq:: 00152 operator == (const UpdateSeq &other) const { 00153 return (_seq == other._seq); 00154 } 00155 00156 //////////////////////////////////////////////////////////////////// 00157 // Function: UpdateSeq::Inequality operator 00158 // Access: Public 00159 // Description: 00160 //////////////////////////////////////////////////////////////////// 00161 INLINE bool UpdateSeq:: 00162 operator != (const UpdateSeq &other) const { 00163 return (_seq != other._seq); 00164 } 00165 00166 //////////////////////////////////////////////////////////////////// 00167 // Function: UpdateSeq::Comparison operator 00168 // Access: Public 00169 // Description: 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE bool UpdateSeq:: 00172 operator < (const UpdateSeq &other) const { 00173 // The special cases of SC_initial or SC_old are less than all other 00174 // non-special numbers, and SC_initial is less than SC_old. The 00175 // special case of SC_fresh is greater than all other non-special 00176 // numbers. For all other cases, we use a circular comparision such 00177 // that n < m iff (signed)(n - m) < 0. 00178 return 00179 (is_special() || other.is_special()) ? (_seq < other._seq) : 00180 ((signed int)(_seq - other._seq) < 0); 00181 } 00182 00183 //////////////////////////////////////////////////////////////////// 00184 // Function: UpdateSeq::Comparison operator 00185 // Access: Public 00186 // Description: 00187 //////////////////////////////////////////////////////////////////// 00188 INLINE bool UpdateSeq:: 00189 operator <= (const UpdateSeq &other) const { 00190 return (*this) == other || (*this) < other; 00191 } 00192 00193 //////////////////////////////////////////////////////////////////// 00194 // Function: UpdateSeq::Preincrement operator 00195 // Access: Public 00196 // Description: 00197 //////////////////////////////////////////////////////////////////// 00198 INLINE UpdateSeq UpdateSeq:: 00199 operator ++ () { 00200 ++_seq; 00201 if (is_special()) { 00202 // Oops, wraparound. We don't want to confuse the new value 00203 // with our special cases. 00204 _seq = (unsigned int)SC_old + 1; 00205 } 00206 00207 return *this; 00208 } 00209 00210 //////////////////////////////////////////////////////////////////// 00211 // Function: UpdateSeq::Postincrement operator 00212 // Access: Public 00213 // Description: 00214 //////////////////////////////////////////////////////////////////// 00215 INLINE UpdateSeq UpdateSeq:: 00216 operator ++ (int) { 00217 UpdateSeq temp = (*this); 00218 operator ++ (); 00219 return temp; 00220 } 00221 00222 //////////////////////////////////////////////////////////////////// 00223 // Function: UpdateSeq::output 00224 // Access: Public 00225 // Description: 00226 //////////////////////////////////////////////////////////////////// 00227 INLINE void UpdateSeq:: 00228 output(ostream &out) const { 00229 switch (_seq) { 00230 case SC_initial: 00231 out << "initial"; 00232 break; 00233 00234 case SC_old: 00235 out << "old"; 00236 break; 00237 00238 case SC_fresh: 00239 out << "fresh"; 00240 break; 00241 00242 default: 00243 out << _seq; 00244 } 00245 } 00246 00247 INLINE ostream &operator << (ostream &out, const UpdateSeq &value) { 00248 value.output(out); 00249 return out; 00250 }