Public Member Functions | List of all members
ndn::SharedPointerChangeCounter< T > Class Template Reference

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...
 

Detailed Description

template<class T>
class ndn::SharedPointerChangeCounter< T >

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.

Constructor & Destructor Documentation

template<class T>
ndn::SharedPointerChangeCounter< T >::SharedPointerChangeCounter ( )
inline

Create a new SharedPointerChangeCounter with a default a null shared_ptr for the target.

This sets the local change counter to 0.

template<class T>
ndn::SharedPointerChangeCounter< T >::SharedPointerChangeCounter ( T *  target)
inline

Create a new SharedPointerChangeCounter with the given target.

This sets the local change counter to target_->getChangeCount().

Parameters
targetA new object for initializing the shared_ptr to the target.

Member Function Documentation

template<class T>
bool ndn::SharedPointerChangeCounter< T >::checkChanged ( ) const
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.

Returns
True if the change count has been updated, false if not.
template<class T>
const T* ndn::SharedPointerChangeCounter< T >::get ( ) const
inline

Get a const pointer to the target object.

Returns
A const pointer to the target.
template<class T>
T* ndn::SharedPointerChangeCounter< T >::get ( )
inline

Get a pointer to the target object.

If the target is changed, then checkChanged will detect it.

Returns
A pointer to the target.
template<class T>
void ndn::SharedPointerChangeCounter< T >::set ( const ptr_lib::shared_ptr< T > &  target)
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().

Parameters
targetA reference to the shared_ptr to the target object whose assignment operator is called to copy the shared_ptr.

The documentation for this class was generated from the following file: