Ignore:
Timestamp:
Sep 1, 2011, 11:07:47 AM (14 years ago)
Author:
Frederik Heber <heber@…>
Children:
9e776f
Parents:
451f17
git-author:
Frederik Heber <heber@…> (09/01/11 11:02:49)
git-committer:
Frederik Heber <heber@…> (09/01/11 11:07:47)
Message:

Extended Observables by NotificationChannels member variable.

  • new class Channels that aggregates Notifications.
  • NOTIFY now just takes a channel number.
  • may or may not be instantiated for a given Observable.
  • Observable just needs to add enum of all desired channels and addChannel on each of these.
  • ObserverUnitTest has been adapted.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer.cpp

    r451f17 r74e0f7  
    271271}
    272272
     273Notification_ptr Observable::getChannel(size_t no) const
     274{
     275  ASSERT(NotificationChannels != NULL,
     276      "Observable::getChannel() - observable has no channels.");
     277  return NotificationChannels->getChannel(no);
     278}
     279
    273280/** Handles sub-observables that just got killed
    274281 *  when an sub-observerable dies we usually don't need to do anything
     
    350357
    351358Notification::Notification(Observable *_owner) :
    352     owner(_owner)
     359    owner(_owner), channelno(-1)
     360{}
     361
     362Notification::Notification(Observable *_owner, size_t _channelno) :
     363    owner(_owner), channelno(_channelno)
    353364{}
    354365
     
    369380  }
    370381}
     382
     383Channels::Channels(Observable *_owner) :
     384  owner(_owner)
     385{}
     386
     387Channels::~Channels()
     388{
     389  // free all present Notifications
     390  for(NotificationTypetoRefMap::iterator iter = ChannelMap.begin();
     391      !ChannelMap.empty(); iter = ChannelMap.begin()) {
     392    delete iter->second;
     393    ChannelMap.erase(iter);
     394  }
     395}
     396
     397void Channels::addChannel(size_t no)
     398{
     399  NotificationTypetoRefMap::const_iterator iter = ChannelMap.find(no);
     400  ASSERT(iter == ChannelMap.end(),
     401      "Channels::addChannel() - channel "+toString(int(no))+" is already present in ChannelMap.");
     402  ChannelMap.insert( std::make_pair(no, new Notification(owner, no)) );
     403}
     404
     405void Channels::removeChannel(size_t no)
     406{
     407  NotificationTypetoRefMap::iterator iter = ChannelMap.find(no);
     408  ASSERT(iter != ChannelMap.end(),
     409      "Channels::removeChannel() - channel "+toString(int(no))+" not present in ChannelMap.");
     410  delete iter->second;
     411  ChannelMap.erase(iter);
     412}
     413
     414Notification_ptr Channels::getChannel(size_t no) const
     415{
     416  NotificationTypetoRefMap::const_iterator iter = ChannelMap.find(no);
     417  ASSERT(iter != ChannelMap.end(),
     418      "Channels::getChannel() - channel "+toString(int(no))+" not present in ChannelMap.");
     419  return iter->second;
     420}
     421
     422size_t Channels::getType(Notification_ptr channel) const
     423{
     424  return channel->getChannelNo();
     425}
     426
    371427
    372428#ifdef LOG_OBSERVER
Note: See TracChangeset for help on using the changeset viewer.