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

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

Detailed Description

template<class T>
class ndn::ChangeCounter< T >

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.

Constructor & Destructor Documentation

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

Create a new ChangeCounter with a default value for the target.

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

template<class T>
ndn::ChangeCounter< T >::ChangeCounter ( const T &  target)
inline

Create a new ChangeCounter, calling the copy constructor on T with the given target.

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

Parameters
targetThe target to copy.

Member Function Documentation

template<class T>
bool ndn::ChangeCounter< 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. 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.

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

Get a const reference to the target object.

Returns
A const reference to the target.
template<class T>
T& ndn::ChangeCounter< T >::get ( )
inline

Get a reference to the target object.

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

Returns
A reference to the target.
template<class T>
void ndn::ChangeCounter< T >::set ( const T &  target)
inline

Set the target to the given target.

This sets the local change counter to target.getChangeCount().

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

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