Panda3D
updateSeq.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file updateSeq.h
10  * @author drose
11  * @date 1999-09-30
12  */
13 
14 #ifndef UPDATE_SEQ
15 #define UPDATE_SEQ
16 
17 #include "pandabase.h"
18 #include "pmutex.h"
19 #include "mutexHolder.h"
20 #include "atomicAdjust.h"
21 #include "numeric_types.h"
22 
23 /**
24  * This is a sequence number that increments monotonically. It can be used to
25  * track cache updates, or serve as a kind of timestamp for any changing
26  * properties.
27  *
28  * A special class is used instead of simply an int, so we can elegantly
29  * handle such things as wraparound and special cases. There are two special
30  * cases. Firstly, a sequence number is 'initial' when it is first created.
31  * This sequence is older than any other sequence number. Secondly, a
32  * sequence number may be explicitly set to 'old'. This is older than any
33  * other sequence number except 'initial'. Finally, we have the explicit
34  * number 'fresh', which is newer than any other sequence number. All other
35  * sequences are numeric and are monotonically increasing.
36  */
37 class EXPCL_PANDA_PUTIL UpdateSeq {
38 private:
39  constexpr UpdateSeq(unsigned int seq);
40 
41 PUBLISHED:
42  constexpr UpdateSeq();
43  constexpr static UpdateSeq initial() { return UpdateSeq(SC_initial); }
44  constexpr static UpdateSeq old() { return UpdateSeq(SC_old); }
45  constexpr static UpdateSeq fresh() { return UpdateSeq(SC_fresh); }
46 
47  INLINE UpdateSeq(const UpdateSeq &copy);
48  constexpr UpdateSeq(const UpdateSeq &&from) noexcept;
49  INLINE UpdateSeq &operator = (const UpdateSeq &copy);
50 
51  INLINE void clear();
52 
53  INLINE bool is_initial() const;
54  INLINE bool is_old() const;
55  INLINE bool is_fresh() const;
56  INLINE bool is_special() const;
57 
58  INLINE bool operator == (const UpdateSeq &other) const;
59  INLINE bool operator != (const UpdateSeq &other) const;
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 
65  INLINE UpdateSeq operator ++ ();
66  INLINE UpdateSeq operator ++ (int);
67 
68  INLINE AtomicAdjust::Integer get_seq() const;
69  MAKE_PROPERTY(seq, get_seq);
70 
71  INLINE void output(std::ostream &out) const;
72 
73 private:
74  INLINE static bool priv_is_special(AtomicAdjust::Integer seq);
75  INLINE static bool priv_lt(AtomicAdjust::Integer a, AtomicAdjust::Integer b);
76  INLINE static bool priv_le(AtomicAdjust::Integer a, AtomicAdjust::Integer b);
77 
78 private:
79  enum SpecialCases : unsigned int {
80  SC_initial = 0,
81  SC_old = 1,
82  SC_fresh = ~(unsigned int)0,
83  };
84 
85  AtomicAdjust::Integer _seq;
86 };
87 
88 INLINE std::ostream &operator << (std::ostream &out, const UpdateSeq &value);
89 
90 #include "updateSeq.I"
91 
92 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a sequence number that increments monotonically.
Definition: updateSeq.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.