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
namespace
mx
14
{
15
namespace
base
16
{
17
18
/// A simple class to track member data changes.
19
/** Maintains a monotonic counter that derived classes increment anytime a member
20
* datum is changed. This allows for, say, re-initializing automatically on a subsequent
21
* call to a function.
22
*
23
* \ingroup base
24
*/
25
template
<
class
_derivedT>
26
class
changeable
27
{
28
29
public
:
30
typedef
_derivedT derivedT;
31
32
/// The integer type of the counter.
33
typedef
uint64_t
changeT
;
34
35
private
:
36
/// The counter itself.
37
changeT
m_change{ 0 };
38
39
/// A marker for last change, set by \ref setChangePoint
40
changeT
m_changePoint{ std::numeric_limits<changeT>::max() };
41
42
public
:
43
/// Increment the counter
44
/** Call this function anytime the derived class changes something important.
45
*
46
*/
47
void
changed
()
48
{
49
++m_change;
50
}
51
52
/// Get the value of the counter
53
/** Get this at a checkpoint and compare it later to decide if any
54
* action should be taken.
55
*/
56
changeT
change
()
57
{
58
return
m_change;
59
}
60
61
void
setChangePoint()
62
{
63
m_changePoint = m_change;
64
}
65
66
bool
isChanged()
67
{
68
return
( m_change != m_changePoint );
69
}
70
};
71
72
}
// namespace base
73
}
// namespace mx
74
75
#endif
// mx_base_changeable_hpp
mx::base::changeable
A simple class to track member data changes.
Definition
changeable.hpp:27
mx::base::changeable::changed
void changed()
Increment the counter.
Definition
changeable.hpp:47
mx::base::changeable::changeT
uint64_t changeT
The integer type of the counter.
Definition
changeable.hpp:33
mx::base::changeable::change
changeT change()
Get the value of the counter.
Definition
changeable.hpp:56
mx
The mxlib c++ namespace.
Definition
mxError.hpp:106
base
changeable.hpp
Generated on Wed Mar 5 2025 10:09:15 for mxlib by
1.9.8