Panda3D
updateSeq.h
1 // Filename: updateSeq.h
2 // Created by: drose (30Sep99)
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 #ifndef UPDATE_SEQ
16 #define UPDATE_SEQ
17 
18 #include "pandabase.h"
19 #include "pmutex.h"
20 #include "mutexHolder.h"
21 #include "atomicAdjust.h"
22 #include "numeric_types.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : UpdateSeq
26 // Description : This is a sequence number that increments
27 // monotonically. It can be used to track cache
28 // updates, or serve as a kind of timestamp for any
29 // changing properties.
30 //
31 // A special class is used instead of simply an int, so
32 // we can elegantly handle such things as wraparound and
33 // special cases. There are two special cases.
34 // Firstly, a sequence number is 'initial' when it is
35 // first created. This sequence is older than any other
36 // sequence number. Secondly, a sequence number may be
37 // explicitly set to 'old'. This is older than any
38 // other sequence number except 'initial'. Finally, we
39 // have the explicit number 'fresh', which is newer
40 // than any other sequence number. All other sequences
41 // are numeric and are monotonically increasing.
42 ////////////////////////////////////////////////////////////////////
43 class EXPCL_PANDA_PUTIL UpdateSeq {
44 PUBLISHED:
45  INLINE UpdateSeq();
46  INLINE static UpdateSeq initial();
47  INLINE static UpdateSeq old();
48  INLINE static UpdateSeq fresh();
49 
50  INLINE UpdateSeq(const UpdateSeq &copy);
51  INLINE UpdateSeq &operator = (const UpdateSeq &copy);
52 
53  INLINE void clear();
54 
55  INLINE bool is_initial() const;
56  INLINE bool is_old() const;
57  INLINE bool is_fresh() const;
58  INLINE bool is_special() const;
59 
60  INLINE bool operator == (const UpdateSeq &other) const;
61  INLINE bool operator != (const UpdateSeq &other) const;
62  INLINE bool operator < (const UpdateSeq &other) const;
63  INLINE bool operator <= (const UpdateSeq &other) const;
64  INLINE bool operator > (const UpdateSeq &other) const;
65  INLINE bool operator >= (const UpdateSeq &other) const;
66 
67  INLINE UpdateSeq operator ++ ();
68  INLINE UpdateSeq operator ++ (int);
69 
70  INLINE AtomicAdjust::Integer get_seq() const;
71 
72  INLINE void output(ostream &out) const;
73 
74 private:
75  INLINE static bool priv_is_special(AtomicAdjust::Integer seq);
76  INLINE static bool priv_lt(AtomicAdjust::Integer a, AtomicAdjust::Integer b);
77  INLINE static bool priv_le(AtomicAdjust::Integer a, AtomicAdjust::Integer b);
78 
79 private:
80  enum SpecialCases {
81  SC_initial = 0,
82  SC_old = 1,
83  SC_fresh = ~(unsigned int)0,
84  };
85 
86  AtomicAdjust::Integer _seq;
87 };
88 
89 INLINE ostream &operator << (ostream &out, const UpdateSeq &value);
90 
91 #include "updateSeq.I"
92 
93 #endif
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43