Panda3D

updateSeq.h

00001 // Filename: updateSeq.h
00002 // Created by:  drose (30Sep99)
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 #ifndef UPDATE_SEQ
00016 #define UPDATE_SEQ
00017 
00018 #include "pandabase.h"
00019 #include "pmutex.h"
00020 #include "mutexHolder.h"
00021 #include "atomicAdjust.h"
00022 #include "numeric_types.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_PUTIL UpdateSeq {
00044 PUBLISHED:
00045   INLINE UpdateSeq();
00046   INLINE static UpdateSeq initial();
00047   INLINE static UpdateSeq old();
00048   INLINE static UpdateSeq fresh();
00049 
00050   INLINE UpdateSeq(const UpdateSeq &copy);
00051   INLINE UpdateSeq &operator = (const UpdateSeq &copy);
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   INLINE bool operator > (const UpdateSeq &other) const;
00065   INLINE bool operator >= (const UpdateSeq &other) const;
00066 
00067   INLINE UpdateSeq operator ++ ();
00068   INLINE UpdateSeq operator ++ (int);
00069 
00070   INLINE void output(ostream &out) const;
00071 
00072 private:
00073   INLINE static bool priv_is_special(AtomicAdjust::Integer seq);
00074   INLINE static bool priv_lt(AtomicAdjust::Integer a, AtomicAdjust::Integer b);
00075   INLINE static bool priv_le(AtomicAdjust::Integer a, AtomicAdjust::Integer b);
00076 
00077 private:
00078   enum SpecialCases {
00079     SC_initial = 0,
00080     SC_old = 1,
00081     SC_fresh = ~(unsigned int)0,
00082   };
00083 
00084   AtomicAdjust::Integer _seq;
00085 };
00086 
00087 INLINE ostream &operator << (ostream &out, const UpdateSeq &value);
00088 
00089 #include "updateSeq.I"
00090 
00091 #endif
 All Classes Functions Variables Enumerations