Ceylan::Model Class Reference

Model of the Model-View-Controller (MVC) design pattern. More...

#include <CeylanModel.h>

Inheritance diagram for Ceylan::Model:

Inheritance graph
[legend]
Collaboration diagram for Ceylan::Model:

Collaboration graph
[legend]

List of all members.

Public Types

enum  TextOutputFormat { rawText, html }
 Defines what text output formats for TextDisplayable instances are available. More...

Public Member Functions

 Model ()
 Basic constructor.
virtual ~Model () throw ()
 Basic virtual destructor.
virtual void addView (View &newView)
 Registers a new view, to which MVC events will be sent.
virtual void removeView (View &view)
 Unregisters specified registered view.
virtual void removeAllViews ()
 Unregisters all registered views.
virtual void subscribeToController (Controller &newController)
 Subscribes to a new controller, from which MVC events will be received.
virtual void unsubscribeFromController (Controller &controller)
 Unsubscribes from specified controller.
virtual void unsubscribeFromAllControllers ()
 Unregisters all registered controllers.
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns a user-friendly description of the state of this object.
virtual const EventgetEventFor (const CallerEventListener &listener)=0
 Returns the event this source has to propagate to the specific listener caller, in order to summarize all past events to this specific listener.
virtual void add (EventListener &listener)
 Registers the specified listener to this source, so that forthcoming events will be sent to it as well.
virtual void remove (const EventListener &listener)
 Unregisters the specified listener from this source, no forthcoming event will be sent to the listener.
virtual void removeAllListeners ()
 Unsubscribes all registered listeners from this source, no forthcoming event will be sent.
virtual void subscribeTo (EventSource &source)
 Subscribes this listener to the specified source, so that forthcoming events will be sent to it as well.
virtual void unsubscribeFrom (EventSource &source)
 Unsubscribes this listener from specified source, no forthcoming event will be received from it.
virtual void unsubscribeFromAllSources ()
 Unsubscribes this listener from all registered sources, no forthcoming event will be received from any.
virtual void forgetSource (EventSource &source)
 Forgets the specified source, but does not notify it that the unsubscription occured on the listener side.
virtual void beNotifiedOf (const Event &newEvent)=0
 Notifies this listener of a new event.
std::list< EventSource * > getSources () const
 Returns a shallow copy of the sources that listener is registered to.

Static Public Member Functions

static const std::string ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high)
 Returns a user-friendly description of this list of pointers to text displayable instances.
static TextOutputFormat GetOutputFormat ()
 Returns the current overall text format to be used by TextDisplayable instances.
static void SetOutputFormat (TextOutputFormat newOutputFormat)
 Sets the current overall text format to be used by TextDisplayable instances.
static const std::string ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high)
 Returns a user-friendly description of this list of pointers to text displayable instances.
static TextOutputFormat GetOutputFormat ()
 Returns the current overall text format to be used by TextDisplayable instances.
static void SetOutputFormat (TextOutputFormat newOutputFormat)
 Sets the current overall text format to be used by TextDisplayable instances.

Protected Member Functions

virtual void notifyAllViews (const MVCEvent &newMVCEvent)
 Notifies all registered views of a new event.
virtual void notifyAllListeners (const Event &newEvent)
 Notifies all currently registered listeners of a new event.
virtual bool isRegistered (const EventListener &listener)
 Tells whether specified listener is registered to this source.

Protected Attributes

std::list< EventListener * > _listeners
 The registered event listeners.
std::list< EventSource * > _sources
 The event sources to which this listener is subscribed to.

Static Protected Attributes

static TextOutputFormat _OutputFormat = rawText
 The text format to be used currently by TextDisplayable instances.
static TextOutputFormat _OutputFormat = rawText
 The text format to be used currently by TextDisplayable instances.

Private Member Functions

 Model (const Model &source)
 Copy constructor made private to ensure that it will be never called.
Modeloperator= (const Model &source)
 Assignment operator made private to ensure that it will be never called.


Detailed Description

Model of the Model-View-Controller (MVC) design pattern.

The model of an object describes its internal state, and is able to make it behave according to its logic.

The controller(s) this model may be listening to will send events thanks to this model's inherited beNotifiedOf method, or will be requested to do so when their model will call their getEventFor method.

Note:
Model is a (callable) source of events for its views, and a (caller) event listener for its controllers.

The link between a model and its views could take into account various aspects, themes: not all views are interested in each and every event.

Models have to implement both the beNotifiedOf method (so that they can listen to controller) and the getSourceEvent virtual method (since they must be able to be triggered, notably by Views).

Definition at line 135 of file CeylanModel.h.


Member Enumeration Documentation

Defines what text output formats for TextDisplayable instances are available.

Enumerator:
rawText 
html 

Definition at line 124 of file CeylanTextDisplayable.h.

Defines what text output formats for TextDisplayable instances are available.

Enumerator:
rawText 
html 

Definition at line 124 of file CeylanTextDisplayable.h.


Constructor & Destructor Documentation

Model::Model (  )  [explicit]

Basic constructor.

Definition at line 68 of file CeylanModel.cc.

Model::~Model (  )  throw () [virtual]

Basic virtual destructor.

Definition at line 77 of file CeylanModel.cc.

References toString(), and unsubscribeFromAllControllers().

Ceylan::Model::Model ( const Model source  )  [private]

Copy constructor made private to ensure that it will be never called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

void EventSource::add ( EventListener listener  )  [virtual, inherited]

Registers the specified listener to this source, so that forthcoming events will be sent to it as well.

Exceptions:
EventException if listener is already registered to the event source.

Definition at line 118 of file CeylanEventSource.cc.

References Ceylan::EventSource::_listeners, and Ceylan::EventListener::toString().

Referenced by Ceylan::EventListener::subscribeTo().

void Model::addView ( View newView  )  [virtual]

Registers a new view, to which MVC events will be sent.

Exceptions:
EventException if view was already registered.

Definition at line 92 of file CeylanModel.cc.

virtual void Ceylan::EventListener::beNotifiedOf ( const Event newEvent  )  [pure virtual, inherited]

Notifies this listener of a new event.

Note:
The event is not by default checked to testify that this listener received an event from a source it is, at the time of this call, registered to.

This event remains property of the EventSource, which will take care of its life cycle.

Implemented in Ceylan::Locatable.

void EventListener::forgetSource ( EventSource source  )  [virtual, inherited]

Forgets the specified source, but does not notify it that the unsubscription occured on the listener side.

Therefore, if the source were to send new events, this listener would be notified, and may not be aware it received an event from a source it is not registered to any more.

See also:
beNotifiedOf
This method should mostly be used by event sources being deallocated, having realized that some listeners were still subscribed, and wanting nevertheless that the listeners remove these sources from their list. Otherwise, on the source side, should unsubscribeFrom be used instead, the listeners list would be modified in turn while iterating on it in the source destructor, which may cause a crash.

Alternatively, on these listener deallocations, if nothing was done in the case of a deallocated source still having at least one listener left, a call to the remove method of these source instances would be tempted, and may cause a crash since sources could be already deallocated.

Note:
This method is therefore a parachute which should not be used by the application. It is used too when the source has to manage the life cycle of its listeners, and has to deallocate them.
This listener can be registered multiple times to this source.

Exceptions:
EventException if listener was not already registered to the event source, and if debug mode for events is activated.

Definition at line 191 of file CeylanEventListener.cc.

References Ceylan::EventListener::_sources, generalUtils::false, Ceylan::EventSource::toString(), and generalUtils::true.

virtual const Event& Ceylan::CallableEventSource::getEventFor ( const CallerEventListener listener  )  [pure virtual, inherited]

Returns the event this source has to propagate to the specific listener caller, in order to summarize all past events to this specific listener.

Parameters:
listener the caller event listener for which the event is forged.
This method is mostly to be used by the caller listener itself on situations where the communication needs to be listener-driven.

More precisely, with basic event sources and listeners, the source triggers the notifications, and the listener has to adapt itself, by storing messages for later use or by acting immediately, accordingly. It is therefore source-driven.

On cases where the listener activation is not to be ruled by sources (ex: if listeners are specifically scheduled already, or if sources, from a listener point of view, would send unnecessary notifications as long as listener is not ready), caller listeners can be used.

They are in charge of driving the communication process: whenever they deem it useful, they ask their sources to return an event describing their current state.

This allows to propagate only fresh and required events for listeners, which is the appropriate way of handling events in all the cases where listeners drive the pace of the pair.

Returns:
an event that can be the latest sent event (if any), or an event especially created for this specific call of this specific listener. The purpose of this event is to make so that the listener is given the information it would have received if all the previous events had been sent to it. This returned event is 'const' so that the same event can be instanciated once and shown multiple times to the same ad/or to different listeners, if needed.
Note:
This listener-driven event propagation is especially useful for memory-less sources such as most controllers, according to the MVC framework: for models, the only interesting information is their current state, thus the propagated source event could be used to summarize to the model what is the current controller state, without having to take into account any past information.
Exceptions:
EventException if the caller event listener is not already registered to this source.
See also:
isRegistered the helper method to check whether specified listener is registered.

TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat (  )  [static, inherited]

TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat (  )  [static, inherited]

list< EventSource * > EventListener::getSources (  )  const [inherited]

Returns a shallow copy of the sources that listener is registered to.

Note:
The returned list contains the same pointer values as the internal one.

Definition at line 238 of file CeylanEventListener.cc.

References Ceylan::EventListener::_sources.

bool EventSource::isRegistered ( const EventListener listener  )  [protected, virtual, inherited]

Tells whether specified listener is registered to this source.

Definition at line 252 of file CeylanEventSource.cc.

References Ceylan::EventSource::_listeners, and generalUtils::false.

void EventSource::notifyAllListeners ( const Event newEvent  )  [protected, virtual, inherited]

Notifies all currently registered listeners of a new event.

Note:
This source takes ownership of this event.

Definition at line 270 of file CeylanEventSource.cc.

References Ceylan::EventSource::_listeners.

Referenced by Ceylan::Locatable::changed(), and notifyAllViews().

void Model::notifyAllViews ( const MVCEvent newMVCEvent  )  [protected, virtual]

Notifies all registered views of a new event.

Note:
This event remains property of this model, which will take care of its life cycle.

Definition at line 175 of file CeylanModel.cc.

References Ceylan::EventSource::notifyAllListeners().

Model& Ceylan::Model::operator= ( const Model source  )  [private]

Assignment operator made private to ensure that it will be never called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

void EventSource::remove ( const EventListener listener  )  [virtual, inherited]

Unregisters the specified listener from this source, no forthcoming event will be sent to the listener.

Exceptions:
EventException if listener was not already registered to the event source.
Note:
This method does nothing special with regard to the listener instance, it acts only on the source. The reason for that is that the unsubscriptions should be initiated on the listener side, not on the source one.
See also:
Ceylan::EventListener::unsubscribeFrom

Definition at line 142 of file CeylanEventSource.cc.

References Ceylan::EventSource::_listeners, generalUtils::false, Ceylan::EventListener::toString(), and generalUtils::true.

void EventSource::removeAllListeners (  )  [virtual, inherited]

Unsubscribes all registered listeners from this source, no forthcoming event will be sent.

This source will request each of its listeners to unsubscribe from it, then the source will forget them in turn.

The links will be removed, but no instance will be deleted by this call.

See also:
Ceylan::EventListener::unsubscribeFromAllSources

Definition at line 204 of file CeylanEventSource.cc.

References Ceylan::EventSource::_listeners.

Referenced by removeAllViews(), and Ceylan::Locatable::~Locatable().

void Model::removeAllViews (  )  [virtual]

Unregisters all registered views.

Each of its views will be requested to unsubscribe from this model.

The links will be removed, but no instance will be deleted by this call.

Definition at line 111 of file CeylanModel.cc.

References Ceylan::EventSource::removeAllListeners().

void Model::removeView ( View view  )  [virtual]

Unregisters specified registered view.

Exceptions:
EventException if view was not already registered.

Definition at line 102 of file CeylanModel.cc.

void TextDisplayable::SetOutputFormat ( TextOutputFormat  newOutputFormat  )  [static, inherited]

Sets the current overall text format to be used by TextDisplayable instances.

Parameters:
newOutputFormat the new output format.

Definition at line 72 of file CeylanTextDisplayable.cc.

References Ceylan::TextDisplayable::_OutputFormat.

Referenced by Ceylan::Log::LogHolder::LogHolder().

void TextDisplayable::SetOutputFormat ( TextOutputFormat  newOutputFormat  )  [static, inherited]

Sets the current overall text format to be used by TextDisplayable instances.

Parameters:
newOutputFormat the new output format.

Definition at line 72 of file CeylanTextDisplayable.cc.

References Ceylan::TextDisplayable::_OutputFormat.

Referenced by Ceylan::Log::LogHolder::LogHolder().

void EventListener::subscribeTo ( EventSource source  )  [virtual, inherited]

Subscribes this listener to the specified source, so that forthcoming events will be sent to it as well.

Note:
A listener can be subscribed to multiple sources at once.
Exceptions:
EventException if listener is already registered to the specified event source.

Definition at line 87 of file CeylanEventListener.cc.

References Ceylan::EventListener::_sources, Ceylan::EventSource::add(), and Ceylan::EventSource::toString().

Referenced by Ceylan::Controller::Controller(), Ceylan::EventListener::EventListener(), Ceylan::Locatable::Locatable(), and subscribeToController().

void Model::subscribeToController ( Controller newController  )  [virtual]

Subscribes to a new controller, from which MVC events will be received.

Exceptions:
EventException if model was already registered.

Definition at line 120 of file CeylanModel.cc.

References Ceylan::EventListener::subscribeTo().

const std::string TextDisplayable::ToString ( std::list< TextDisplayable * >  displayables,
Ceylan::VerbosityLevels  level = Ceylan::high 
) [static, inherited]

Returns a user-friendly description of this list of pointers to text displayable instances.

Parameters:
displayables a list of pointers to TextDisplayable instances/
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
toString, Ceylan::VerbosityLevels

Definition at line 45 of file CeylanTextDisplayable.cc.

References Ceylan::formatStringList().

const std::string TextDisplayable::ToString ( std::list< TextDisplayable * >  displayables,
Ceylan::VerbosityLevels  level = Ceylan::high 
) [static, inherited]

Returns a user-friendly description of this list of pointers to text displayable instances.

Parameters:
displayables a list of pointers to TextDisplayable instances/
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
toString, Ceylan::VerbosityLevels

Definition at line 45 of file CeylanTextDisplayable.cc.

References Ceylan::formatStringList().

const string Model::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [virtual]

Returns a user-friendly description of the state of this object.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
TextDisplayable

Reimplemented from Ceylan::CallableEventSource.

Definition at line 148 of file CeylanModel.cc.

References Ceylan::EventSource::_listeners, and Ceylan::EventListener::_sources.

Referenced by ~Model().

void EventListener::unsubscribeFrom ( EventSource source  )  [virtual, inherited]

Unsubscribes this listener from specified source, no forthcoming event will be received from it.

This is the usual method to call when one wants that this listener to not listen any more to the specified source.

It is in fact implemented by notifying this source of the unsubscription of this listener, and by forgetting it.

Exceptions:
EventException if listener was not already registered to the event source.

Definition at line 113 of file CeylanEventListener.cc.

References Ceylan::EventListener::_sources, and Ceylan::EventSource::toString().

Referenced by Ceylan::Locatable::detachFromFather(), and unsubscribeFromController().

void Model::unsubscribeFromAllControllers (  )  [virtual]

Unregisters all registered controllers.

Definition at line 139 of file CeylanModel.cc.

References Ceylan::EventListener::unsubscribeFromAllSources().

Referenced by ~Model().

void EventListener::unsubscribeFromAllSources (  )  [virtual, inherited]

Unsubscribes this listener from all registered sources, no forthcoming event will be received from any.

Definition at line 160 of file CeylanEventListener.cc.

References Ceylan::EventListener::_sources.

Referenced by unsubscribeFromAllControllers(), and Ceylan::EventListener::~EventListener().

void Model::unsubscribeFromController ( Controller controller  )  [virtual]

Unsubscribes from specified controller.

Exceptions:
EventException if model was not already registered.

Definition at line 130 of file CeylanModel.cc.

References Ceylan::EventListener::unsubscribeFrom().


Member Data Documentation

std::list<EventListener *> Ceylan::EventSource::_listeners [protected, inherited]

TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited]

The text format to be used currently by TextDisplayable instances.

Note:
Defaults to raw text.

Definition at line 158 of file CeylanTextDisplayable.h.

Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().

TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited]

The text format to be used currently by TextDisplayable instances.

Note:
Defaults to raw text.

Definition at line 158 of file CeylanTextDisplayable.h.

Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().

std::list<EventSource *> Ceylan::EventListener::_sources [protected, inherited]


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

Generated on Thu Jun 4 20:40:17 2009 for Ceylan by  doxygen 1.5.8