Ignore:
Timestamp:
Dec 13, 2011, 9:43:39 AM (14 years ago)
Author:
Frederik Heber <heber@…>
Children:
e2e035e
Parents:
e7352a5
git-author:
Frederik Heber <heber@…> (12/01/11 09:09:18)
git-committer:
Frederik Heber <heber@…> (12/13/11 09:43:39)
Message:

NotificationChannels is now static entity.

  • this is in line with the other static entities on Observable that are intended to save memory (before we needed 8 bytes for the pointer in each and every Observable instances, whether it had channels or not.)
  • Modified NOTIFY macro to accomodate for the changes.
  • enhanced documentation of class Notifications.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer.hpp

    re7352a5 rbc2698  
    168168  static void enque_notification_internal(Observable *publisher, Notification_ptr notification);
    169169
    170   Channels *NotificationChannels;
     170  typedef std::map<Observable*, Channels *> ChannelMap;
     171  static ChannelMap NotificationChannels;
    171172
    172173private:
     
    197198};
    198199
    199 /** Notifications are sort of new channels of an Observable.
     200/** Notifications are sort of news channels of an Observable.
    200201 * Via the NOTIFY() macro updates can be transmitted in a specific channel.
    201202 * Observers can subscribe to Notification in much the same way as they can to
    202  * the Observable itself. Usually, Notifications
     203 * the Observable itself. Usually, Notifications are used along
     204 * with the usual OBSERVE() macro to generate both the specific and
     205 * the global message of change.
    203206 */
    204207class Notification {
     
    287290#define PASTE_HELPER(a,b) a ## b
    288291#define OBSERVE Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(this)
    289 #define NOTIFY(channelno) do{Observable::enque_notification_internal(this,NotificationChannels->getChannel(channelno));}while(0)
     292#define NOTIFY(channelno) do{const ChannelMap::const_iterator iter=NotificationChannels.find(this);ASSERT(iter!=NotificationChannels.end(),"NOTIFY() - channel not found.");Observable::enque_notification_internal(this,iter->second->getChannel(channelno));}while(0)
    290293#define LOCK_OBSERVABLE(observable) Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(&(observable))
    291294
Note: See TracChangeset for help on using the changeset viewer.