00001 // Filename: updateSeq.h 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 #ifndef UPDATE_SEQ 00020 #define UPDATE_SEQ 00021 00022 #include <pandabase.h> 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Class : UpdateSeq 00026 // Description : This is a sequence number that increments 00027 // monotonically. It can be used to track cache 00028 // updates, or serve as a kind of timestamp for any 00029 // changing properties. 00030 // 00031 // A special class is used instead of simply an int, so 00032 // we can elegantly handle such things as wraparound and 00033 // special cases. There are two special cases. 00034 // Firstly, a sequence number is 'initial' when it is 00035 // first created. This sequence is older than any other 00036 // sequence number. Secondly, a sequence number may be 00037 // explicitly set to 'old'. This is older than any 00038 // other sequence number except 'initial'. Finally, we 00039 // have the explicit number 'fresh', which is newer 00040 // than any other sequence number. All other sequences 00041 // are numeric and are monotonically increasing. 00042 //////////////////////////////////////////////////////////////////// 00043 class EXPCL_PANDA UpdateSeq { 00044 public: 00045 INLINE UpdateSeq(); 00046 INLINE static UpdateSeq initial(); 00047 INLINE static UpdateSeq old(); 00048 INLINE static UpdateSeq fresh(); 00049 00050 INLINE UpdateSeq(const UpdateSeq ©); 00051 INLINE UpdateSeq &operator = (const UpdateSeq ©); 00052 00053 INLINE void clear(); 00054 00055 INLINE bool is_initial() const; 00056 INLINE bool is_old() const; 00057 INLINE bool is_fresh() const; 00058 INLINE bool is_special() const; 00059 00060 INLINE bool operator == (const UpdateSeq &other) const; 00061 INLINE bool operator != (const UpdateSeq &other) const; 00062 INLINE bool operator < (const UpdateSeq &other) const; 00063 INLINE bool operator <= (const UpdateSeq &other) const; 00064 00065 INLINE UpdateSeq operator ++ (); 00066 INLINE UpdateSeq operator ++ (int); 00067 00068 INLINE void output(ostream &out) const; 00069 00070 private: 00071 enum SpecialCases { 00072 SC_initial = 0, 00073 SC_old = 1, 00074 SC_fresh = ~0, 00075 }; 00076 00077 unsigned int _seq; 00078 }; 00079 00080 INLINE ostream &operator << (ostream &out, const UpdateSeq &value); 00081 00082 #include "updateSeq.I" 00083 00084 #endif