PureMVC PureMVC

PureMVC::Core::View Class Reference

#include "View.hpp"

Inherits Interfaces::IView.

Collaboration diagram for PureMVC::Core::View:

List of all members.

Classes

class  InsertedObserver
struct  IPassiveObserver
struct  IteratorConverter
struct  IteratorRange
class  RemovingObserver

Public Member Functions

 View (std::string const &key=PureMVC::Core::View::DEFAULT_KEY)
virtual ~View (void)
virtual bool hasMediator (std::string const &mediator_name) const
void joinAllPassiveObserver (void)
virtual MediatorNames listMediatorNames (void) const
virtual void notifyObservers (INotification const &notification)
virtual void registerMediator (IMediator *mediator)
virtual void registerObserver (std::string const &notification_name, IObserver *observer)
virtual IMediator * removeMediator (std::string const &mediator_name)
virtual void removeObserver (std::string const &notification_name, IObserver const *notify_context)
virtual IMediator const & retrieveMediator (std::string const &mediator_name) const
virtual IMediator & retrieveMediator (std::string const &mediator_name)

Static Public Member Functions

static IView & getInstance (std::string const &key=PureMVC::Core::View::DEFAULT_KEY)
static void removeView (std::string const &key)

Static Public Attributes

static char const *const DEFAULT_KEY

Protected Types

typedef std::map< std::string,
IMediator * > 
MediatorMap
typedef std::multimap
< std::string, IObserver * > 
ObserverMap
typedef std::list
< IPassiveObserver * > 
PassiveObserverList

Protected Member Functions

template<typename _DerivedType >
 View (_DerivedType *instance, std::string const &key=PureMVC::Core::View::DEFAULT_KEY)
virtual void initializeView (void)

Static Protected Member Functions

static IView * find (std::string const &key)
static void insert (std::string const &key, IView *view)

Protected Attributes

int _inloop_counter
MediatorMap _mediator_map
std::string const _multiton_key
ObserverMap _observer_map
PassiveObserverList _passive_observer_list
Mutex _synchronous_access

Static Protected Attributes

static char const *const MULTITON_MSG

Detailed Description

A Multiton IView implementation.

In PureMVC, the View class assumes these responsibilities:

  • Maintain a cache of IMediator instances.
  • Provide methods for registering, retrieving, and removing IMediators.
  • Notifiying IMediators when they are registered or removed.
  • Managing the observer lists for each INotification in the application.
  • Providing a method for attaching IObservers to an INotification's observer list.
  • Providing a method for broadcasting an INotification.
  • Notifying the IObservers of a given INotification when it broadcast.
See also:
Patterns/Mediator/Mediator.hpp PureMVC::Patterns::Mediator
Patterns/Observer/Observer.hpp PureMVC::Patterns::Observer
Patterns/Observer/Notification.hpp PureMVC::Patterns::Notification

Definition at line 63 of file View.hpp.


Member Typedef Documentation

typedef std::map<std::string, IMediator*> PureMVC::Core::View::MediatorMap [protected]

Definition at line 66 of file View.hpp.

typedef std::multimap<std::string, IObserver*> PureMVC::Core::View::ObserverMap [protected]

Definition at line 67 of file View.hpp.

Definition at line 144 of file View.hpp.


Constructor & Destructor Documentation

PureMVC::Core::View::View ( std::string const &  key = PureMVC::Core::View::DEFAULT_KEY) [explicit]

Constructor.

This IView implementation is a Multiton, so you should not call the constructor directly, but instead call the static Multiton Factory method View::getInstance(key)

Exceptions:
ErrorError if instance for this Multiton key has already been constructed
template<typename _DerivedType >
PureMVC::Core::View::View ( _DerivedType *  instance,
std::string const &  key = PureMVC::Core::View::DEFAULT_KEY 
) [inline, explicit, protected]

Constructor.

Support call virtual method in constructor of base class (View).

Condition: Derived class (class inherit from View) must implement method: initializeView

Please use in this way:

ConcreateView::ConcreateView(void) :View(this) { // Your code here }

Factory method View::getInstance( key )

Exceptions:
ErrorError if instance for this Multiton key has already been constructed

Definition at line 196 of file View.hpp.

            :_multiton_key(key)
            {
                if (find(key))
                    throw std::runtime_error(MULTITON_MSG);
                insert(_multiton_key, this);
                instance->_DerivedType::initializeView();
            }
virtual PureMVC::Core::View::~View ( void  ) [virtual]

Virtual destructor.


Member Function Documentation

static IView* PureMVC::Core::View::find ( std::string const &  key) [static, protected]
static IView& PureMVC::Core::View::getInstance ( std::string const &  key = PureMVC::Core::View::DEFAULT_KEY) [static]

View Singleton Factory method.

Returns:
the Singleton instance of View
virtual bool PureMVC::Core::View::hasMediator ( std::string const &  mediator_name) const [virtual]

Check if a Mediator is registered or not

Parameters:
mediator_name
Returns:
whether a Mediator is registered with the given mediator_name.
virtual void PureMVC::Core::View::initializeView ( void  ) [protected, virtual]

Initialize the Singleton View instance.

Called automatically by the constructor, this is your opportunity to initialize the Singleton instance in your subclass without overriding the constructor.

Returns:
void
static void PureMVC::Core::View::insert ( std::string const &  key,
IView *  view 
) [static, protected]
void PureMVC::Core::View::joinAllPassiveObserver ( void  )
virtual MediatorNames PureMVC::Core::View::listMediatorNames ( void  ) const [virtual]

List all names of mediator

Returns:
the aggregate container of mediator_name.
virtual void PureMVC::Core::View::notifyObservers ( INotification const &  notification) [virtual]

Notify the IObservers for a particular INotification.

All previously attached IObservers for this INotification's list are notified and are passed a reference to the INotification in the order in which they were registered.

Parameters:
notificationthe INotification to notify IObservers of.
virtual void PureMVC::Core::View::registerMediator ( IMediator *  mediator) [virtual]

Register an IMediator instance with the View.

Registers the IMediator so that it can be retrieved by name, and further interrogates the IMediator for its INotification interests.

If the IMediator returns any INotification names to be notified about, an Observer is created encapsulating the IMediator instance's handleNotification method and registering it as an Observer for all INotifications the IMediator is interested in.

Parameters:
mediatora reference to the IMediator instance
virtual void PureMVC::Core::View::registerObserver ( std::string const &  notification_name,
IObserver *  observer 
) [virtual]

Register an IObserver to be notified of INotifications with a given name.

Parameters:
notification_namethe name of the INotifications to notify this IObserver of
observerthe IObserver to register
virtual IMediator* PureMVC::Core::View::removeMediator ( std::string const &  mediator_name) [virtual]

Remove an IMediator from the View.

Parameters:
mediator_namename of the IMediator instance to be removed.
Returns:
the IMediator that was removed from the View
virtual void PureMVC::Core::View::removeObserver ( std::string const &  notification_name,
IObserver const *  notify_context 
) [virtual]

Remove the observer for a given notifyContext from an observer list for a given Notification name.

Parameters:
notification_namewhich observer list to remove from
notify_contextremove the observer with this object as its notify_context
static void PureMVC::Core::View::removeView ( std::string const &  key) [static]

Remove an IView instance

Parameters:
keyof IView instance to remove
virtual IMediator& PureMVC::Core::View::retrieveMediator ( std::string const &  mediator_name) [virtual]

Retrieve an IMediator from the View.

Parameters:
mediator_namethe name of the IMediator instance to retrieve.
Returns:
the IMediator instance previously registered with the given mediator_name.
virtual IMediator const& PureMVC::Core::View::retrieveMediator ( std::string const &  mediator_name) const [virtual]

Retrieve an IMediator from the View.

Parameters:
mediator_namethe name of the IMediator instance to retrieve.
Returns:
the IMediator instance previously registered with the given mediator_name.

Member Data Documentation

Definition at line 143 of file View.hpp.

Definition at line 139 of file View.hpp.

std::string const PureMVC::Core::View::_multiton_key [protected]

Definition at line 137 of file View.hpp.

Definition at line 141 of file View.hpp.

Definition at line 148 of file View.hpp.

char const* const PureMVC::Core::View::DEFAULT_KEY [static]

Definition at line 131 of file View.hpp.

char const* const PureMVC::Core::View::MULTITON_MSG [static, protected]

Definition at line 134 of file View.hpp.


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