mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
changeable.hpp
Go to the documentation of this file.
1/** \file changeable.hpp
2 * \brief A simple class to track member data changes
3 *
4 * \author Jared R. Males (jaredmales@gmail.com)
5 *
6 * \ingroup utils_files
7 *
8 */
9
10#ifndef mx_base_changeable_hpp
11#define mx_base_changeable_hpp
12
13#include <cstdint>
14#include <limits>
15
16namespace mx
17{
18namespace base
19{
20
21/// A simple class to track member data changes.
22/** Maintains a monotonic counter that derived classes increment anytime a member
23 * datum is changed. This allows for, say, re-initializing automatically on a subsequent
24 * call to a function.
25 *
26 * \ingroup base
27 */
28template <class _derivedT>
30{
31
32 public:
33 typedef _derivedT derivedT;
34
35 /// The integer type of the counter.
36 typedef uint64_t changeT;
37
38 private:
39 /// The counter itself.
40 changeT m_change{ 0 };
41
42 /// A marker for last change, set by \ref setChangePoint
43 changeT m_changePoint{ std::numeric_limits<changeT>::max() };
44
45 public:
46 /// Increment the counter
47 /** Call this function anytime the derived class changes something important.
48 *
49 */
50 void changed()
51 {
52 ++m_change;
53 }
54
55 /// Get the value of the counter
56 /** Get this at a checkpoint and compare it later to decide if any
57 * action should be taken.
58 */
60 {
61 return m_change;
62 }
63
64 void setChangePoint()
65 {
66 m_changePoint = m_change;
67 }
68
69 bool isChanged()
70 {
71 return ( m_change != m_changePoint );
72 }
73};
74
75} // namespace base
76} // namespace mx
77
78#endif // mx_base_changeable_hpp
A simple class to track member data changes.
void changed()
Increment the counter.
uint64_t changeT
The integer type of the counter.
changeT change()
Get the value of the counter.
The mxlib c++ namespace.
Definition mxlib.hpp:37