A ChangeCounter keeps a shared_ptr to a target object whose change count is tracked by a local change count. More...
#include <change-counter.hpp>
Public Member Functions | |
SharedPointerChangeCounter () | |
Create a new SharedPointerChangeCounter with a default a null shared_ptr for the target. More... | |
SharedPointerChangeCounter (T *target) | |
Create a new SharedPointerChangeCounter with the given target. More... | |
const T * | get () const |
Get a const pointer to the target object. More... | |
T * | get () |
Get a pointer to the target object. More... | |
void | set (const ptr_lib::shared_ptr< T > &target) |
Set the shared_ptr to the target to the given value. 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 shared_ptr to 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 normal value type, see ChangeCounter.
|
inline |
Create a new SharedPointerChangeCounter with a default a null shared_ptr for the target.
This sets the local change counter to 0.
|
inline |
Create a new SharedPointerChangeCounter with the given target.
This sets the local change counter to target_->getChangeCount().
target | A new object for initializing the shared_ptr to the target. |
|
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. However, if the shared_ptr to the target is null, 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 pointer to the target object.
|
inline |
Get a pointer to the target object.
If the target is changed, then checkChanged will detect it.
|
inline |
Set the shared_ptr to the target to the given value.
If target is not null, this sets the local change counter to target->getChangeCount().
target | A reference to the shared_ptr to the target object whose assignment operator is called to copy the shared_ptr. |