observer::IObserver< T > Class Template Reference

#include <observer.h>

Inheritance diagram for observer::IObserver< T >:
pdfobjects::utils::ProgressObserver

List of all members.

Public Types

typedef int priority_t

Public Member Functions

 IObserver ()
virtual void notify (boost::shared_ptr< T > newValue, boost::shared_ptr< const IChangeContext< T > > context) const =0 throw ()
virtual priority_t getPriority () const =0 throw ()
bool setActive (bool active)
bool isActive () const
virtual ~IObserver () throw ()

Private Attributes

bool active

Detailed Description

template<typename T>
class observer::IObserver< T >

Observer interface (pure abstract class).

Observer is mechanism how to be informed that somethig has changed. Implementator of this interface produces handler for this change event.
This should be used in following way:

Interface is template to enable different value types to be used (type parameter stands for value type to be managed - informed about change). This enables only one type to be handled by one implementator (with all subtypes).
Value change handling is done in notify method (see for more details). This method is called after value has been changed.
Each observer implementation has its priority which is used be value keeper to determine order in which to notify obsevers, if there is more then one.
Observer can be in active/inactive state depending on the active flag value. See setActive, isActive methods.
Exception NOTE: No method throws an exception.


Member Typedef Documentation

template<typename T>
typedef int observer::IObserver< T >::priority_t

Type for priority.


Constructor & Destructor Documentation

template<typename T>
observer::IObserver< T >::IObserver (  )  [inline]

Default constructor.

template<typename T>
virtual observer::IObserver< T >::~IObserver (  )  throw () [inline, virtual]

Virtual destructor.


Member Function Documentation

template<typename T>
virtual priority_t observer::IObserver< T >::getPriority (  )  const throw () [pure virtual]
template<typename T>
bool observer::IObserver< T >::isActive (  )  const [inline]

Returns current value of the active flag.

Returns:
true if observer can be notified, false otherwise.
template<typename T>
virtual void observer::IObserver< T >::notify ( boost::shared_ptr< T >  newValue,
boost::shared_ptr< const IChangeContext< T > >  context 
) const throw () [pure virtual]

Notify method.

Parameters:
newValue New value of changed value or its part.
context Value change context.

Each time value keeper, which implements ObserverHandler, changes value (or its part), all registered observers are notified about that by this method calling.
newValue stands for new value or its part (if value is complex).
contex contains additional information about change. It depends on value keeper which information is provided (if any). It may be NULL (value stored in shared_ptr may be NULL - more precisely - use contex.get()==NULL condition for checking) which means that no information is provided. Method implementator should check context type (using getType() method). Accoring this type cast to correct IChangeContext subclass and use information.

Example:
Lets say that T is IProperty. If observer is registered on simple type, newValue contains new value of this simple one. If it is registered on complex type, it contains changed value (item) inside this complex type (value keeper part is changed).

Implemented in gui::TreeItemGenericObserver< ObservedItem >.

template<typename T>
bool observer::IObserver< T >::setActive ( bool  active  )  [inline]

Sets active flag value.

Parameters:
active Flag value to be set.
Returns:
previous value of the flag.

Member Data Documentation

template<typename T>
bool observer::IObserver< T >::active [private]

Active flag. Observer is ignored by observer handler if it is false.

Referenced by observer::IObserver< ObservedItem >::isActive().


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