A ChangeCounter keeps a target object whose change count is tracked by a local change count. More...
#include <change-counter.hpp>
Public Member Functions | |
ChangeCounter () | |
Create a new ChangeCounter with a default value for the target. More... | |
ChangeCounter (const T &target) | |
Create a new ChangeCounter, calling the copy constructor on T with the given target. More... | |
const T & | get () const |
Get a const reference to the target object. More... | |
T & | get () |
Get a reference to the target object. More... | |
void | set (const T &target) |
Set the target to the given target. More... | |
bool | checkChanged () const |
If the target's change count is different than the local change count, then update the local change count and return true. More... | |
A ChangeCounter keeps a target object whose change count is tracked by a local change count.
You can set to a new target which updates the local change count, and you can call checkChanged to check if the target (or one of the target's targets) has been changed. The target type T must have a method getChangeCount. If you need the target to be a shared_ptr, see SharedPointerChangeCounter.
|
inline |
Create a new ChangeCounter with a default value for the target.
This sets the local change counter to target_.getChangeCount().
|
inline |
Create a new ChangeCounter, calling the copy constructor on T with the given target.
This sets the local change counter to target_.getChangeCount().
target | The target to copy. |
|
inline |
If the target's change count is different than the local change count, then update the local change count and return true.
Otherwise return false, meaning that the target has not changed. Also, if the target is null, simply return false. This is useful since the target (or one of the target's targets) may be changed and you need to find out.
|
inline |
Get a const reference to the target object.
|
inline |
Get a reference to the target object.
If the target is changed, then checkChanged will detect it.
|
inline |
Set the target to the given target.
This sets the local change counter to target.getChangeCount().
target | A reference to the target object whose assignment operator is called to copy it. |