ircproxy  The Ultimate Cyborg

Watched< T > Class Template Reference

#include <Watched.h>

List of all members.


Detailed Description

template<typename T>
class Watched< T >

A wrapper class for arbitrary objects of type T that need to be watched.

Definition at line 74 of file Watched.h.


Public Member Functions

 Watched (char const *name)
 Construct a Watched instance with debug name name.
 Watched (char const *name, T const &value)
 Construct a Watched instance with debug name name and value value.
 Watched (Watched const &b)
 Copy constructor.
 ~Watched ()
 Destructor.
void print_name (std::ostream &os) const
 Print M_name to os for debugging purposes.
void add_event_server (boost::shared_ptr< ExpressionEventServer > const &event_server)
 Add an event server to the event notification list.
void sub_event_server (ExpressionEventServer *event_server)
 Remove an event server from the event notification list.
template<typename T2>
Watchedoperator= (T2 const &b)
 Templated assignment operator.
Watchedoperator= (Watched const &b)
 Assignment operator.
template<typename T2>
Watchedoperator &= (T2 const &b)
 Templated bitwise AND assignment operator.
Watchedoperator &= (Watched const &b)
 Bitwise AND assignment operator.
template<typename T2>
Watchedoperator|= (T2 const &b)
 Templated bitwise OR assignment operator.
Watchedoperator|= (Watched const &b)
 Bitwise OR assignment operator.
template<typename T2>
Watchedoperator^= (T2 const &b)
 Templated bitwise XOR assignment operator.
Watchedoperator^= (Watched const &b)
 Bitwise XOR assignment operator.
operator~ (void)
 Bitwise NOT operator.
WatchedExpression< T > operator* (void)
 Dereference operator. Returns the Watched variable as Expression type.
T const & value (void) const
 Return underlying value.
 operator T const & ()
 Cast operator. Return underlying value.

Private Member Functions

void changed_to (T const &b)
 Inform listening Expression event servers that this variable changed value.

Private Attributes

M_value
 The underlying value.
bool M_being_destructed
 Set when this object is being destructed.
std::set< boost::shared_ptr
< ExpressionEventServer > > 
M_event_servers
 The event servers that watch expressions depending on this variable.
char const * M_name
 A name for this object, for debugging purposes.

Constructor & Destructor Documentation

template<typename T>
Watched< T >::Watched ( char const *  name  )  [inline, explicit]

Construct a Watched instance with debug name name.

Definition at line 86 of file Watched.h.

00086 : M_being_destructed(false), M_name(name) { }

template<typename T>
Watched< T >::Watched ( char const *  name,
T const &  value 
) [inline, explicit]

Construct a Watched instance with debug name name and value value.

Definition at line 88 of file Watched.h.

00088 : M_value(value), M_being_destructed(false), M_name(name) { }

template<typename T>
Watched< T >::Watched ( Watched< T > const &  b  )  [inline]

Copy constructor.

Definition at line 95 of file Watched.h.

00095                               : M_value(b.M_value), M_being_destructed(false)
00096         {
00097 #ifdef CWDEBUG
00098           if (!b.M_event_servers.empty())
00099             Dout(dc::warning, "Copy-constructing a Watched<" <<
00100                 type_info_of<T>().demangled_name() << "> that is being used by one or more ExpressionEventServer's");
00101 #endif
00102         }

template<typename T>
Watched< T >::~Watched (  )  [inline]

Destructor.

Destructor. Inform listening Expression event servers that this variable is no longer watched.

Definition at line 305 of file Watched.h.

References Watched< T >::M_being_destructed, and Watched< T >::M_event_servers.

00306 {
00307   M_being_destructed = true;
00308   for (std::set<boost::shared_ptr<ExpressionEventServer> >::iterator iter = M_event_servers.begin(); iter != M_event_servers.end();)
00309     (*iter++)->bool_destructed();
00310 }


Member Function Documentation

template<typename T>
void Watched< T >::print_name ( std::ostream &  os  )  const [inline]

Print M_name to os for debugging purposes.

Definition at line 108 of file Watched.h.

00108 { os << M_name; }

template<typename T>
void Watched< T >::add_event_server ( boost::shared_ptr< ExpressionEventServer > const &  event_server  )  [inline]

Add an event server to the event notification list.

Definition at line 112 of file Watched.h.

00113     {
00114       M_event_servers.insert(event_server);
00115     }

template<typename T>
void Watched< T >::sub_event_server ( ExpressionEventServer event_server  )  [inline]

Remove an event server from the event notification list.

Definition at line 118 of file Watched.h.

00119     {
00120       if (M_being_destructed)
00121         return;
00122       std::set<boost::shared_ptr<ExpressionEventServer> >::iterator iter = M_event_servers.begin();
00123       while (iter != M_event_servers.end())
00124       {
00125         if ((*iter).get() == event_server)
00126           break;
00127         ++iter;
00128       }
00129       ASSERT(iter != M_event_servers.end());
00130       M_event_servers.erase(iter);
00131     }

template<typename T>
template<typename T2>
Watched& Watched< T >::operator= ( T2 const &  b  )  [inline]

Templated assignment operator.

Definition at line 135 of file Watched.h.

00136     {
00137       T previous_value(M_value);
00138       M_value = b;
00139       if (M_value != previous_value)
00140         changed_to(M_value);
00141       return *this;
00142     }

template<typename T>
Watched& Watched< T >::operator= ( Watched< T > const &  b  )  [inline]

Assignment operator.

Definition at line 145 of file Watched.h.

00146     {
00147       if (M_value != b.M_value)
00148         changed_to(b.M_value);
00149       return *this;
00150     }

template<typename T>
template<typename T2>
Watched& Watched< T >::operator &= ( T2 const &  b  )  [inline]

Templated bitwise AND assignment operator.

Definition at line 154 of file Watched.h.

00155     {
00156       T previous_value(M_value);
00157       M_value &= b;
00158       if (M_value != previous_value)
00159         changed_to(M_value);
00160       return *this;
00161     }

template<typename T>
Watched& Watched< T >::operator &= ( Watched< T > const &  b  )  [inline]

Bitwise AND assignment operator.

Definition at line 164 of file Watched.h.

00165     {
00166       T previous_value(M_value);
00167       M_value &= b.M_value;
00168       if (M_value != previous_value)
00169         changed_to(M_value);
00170       return *this;
00171     }

template<typename T>
template<typename T2>
Watched& Watched< T >::operator|= ( T2 const &  b  )  [inline]

Templated bitwise OR assignment operator.

Definition at line 175 of file Watched.h.

00176     {
00177       T previous_value(M_value);
00178       M_value |= b;
00179       if (M_value != previous_value)
00180         changed_to(M_value);
00181       return *this;
00182     }

template<typename T>
Watched& Watched< T >::operator|= ( Watched< T > const &  b  )  [inline]

Bitwise OR assignment operator.

Definition at line 185 of file Watched.h.

00186     {
00187       T previous_value(M_value);
00188       M_value |= b.M_value;
00189       if (M_value != previous_value)
00190         changed_to(M_value);
00191       return *this;
00192     }

template<typename T>
template<typename T2>
Watched& Watched< T >::operator^= ( T2 const &  b  )  [inline]

Templated bitwise XOR assignment operator.

Definition at line 196 of file Watched.h.

00197     {
00198       T previous_value(M_value);
00199       M_value ^= b;
00200       if (M_value != previous_value)
00201         changed_to(M_value);
00202       return *this;
00203     }

template<typename T>
Watched& Watched< T >::operator^= ( Watched< T > const &  b  )  [inline]

Bitwise XOR assignment operator.

Definition at line 206 of file Watched.h.

00207     {
00208       T previous_value(M_value);
00209       M_value ^= b.M_value;
00210       if (M_value != previous_value)
00211         changed_to(M_value);
00212       return *this;
00213     }

template<typename T>
T Watched< T >::operator~ ( void   )  [inline]

Bitwise NOT operator.

Definition at line 216 of file Watched.h.

00216 { return ~M_value; }

template<typename T>
WatchedExpression<T> Watched< T >::operator* ( void   )  [inline]

Dereference operator. Returns the Watched variable as Expression type.

Definition at line 219 of file Watched.h.

00219 { return WatchedExpression<T>(*this); }

template<typename T>
T const& Watched< T >::value ( void   )  const [inline]

Return underlying value.

Definition at line 222 of file Watched.h.

Referenced by AuthState::auth_ping_argument(), operator &(), operator!=(), operator==(), operator>(), operator>=(), operator^(), and operator|().

00222 { return M_value; }

template<typename T>
Watched< T >::operator T const & (  )  [inline]

Cast operator. Return underlying value.

Definition at line 225 of file Watched.h.

00225 { return M_value; }

template<typename T>
void Watched< T >::changed_to ( T const &  b  )  [inline, private]

Inform listening Expression event servers that this variable changed value.

Definition at line 294 of file Watched.h.

References Watched< T >::M_event_servers, and Watched< T >::M_value.

Referenced by Watched< UserModeMask >::operator &=(), Watched< UserModeMask >::operator=(), Watched< UserModeMask >::operator^=(), and Watched< UserModeMask >::operator|=().

00295 {
00296   M_value = b;
00297   std::set<boost::shared_ptr<ExpressionEventServer> >::iterator iter = M_event_servers.begin();
00298   // The call to bool_changed can remove iter from the set<>. Therefore increment iter before calling bool_changed.
00299   while (iter != M_event_servers.end())
00300     (*iter++)->bool_changed();
00301 }


Member Data Documentation

template<typename T>
bool Watched< T >::M_being_destructed [private]

Set when this object is being destructed.

Definition at line 77 of file Watched.h.

Referenced by Watched< UserModeMask >::sub_event_server(), and Watched< T >::~Watched().

template<typename T>
std::set<boost::shared_ptr<ExpressionEventServer> > Watched< T >::M_event_servers [private]

The event servers that watch expressions depending on this variable.

Definition at line 78 of file Watched.h.

Referenced by Watched< UserModeMask >::add_event_server(), Watched< T >::changed_to(), Watched< UserModeMask >::sub_event_server(), and Watched< T >::~Watched().

template<typename T>
char const* Watched< T >::M_name [private]

A name for this object, for debugging purposes.

Definition at line 80 of file Watched.h.


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

Copyright © 2005-2007 Carlo Wood.  All rights reserved.