Changeset 8fe1e2


Ignore:
Timestamp:
Dec 13, 2011, 9:46:12 AM (14 years ago)
Author:
Frederik Heber <heber@…>
Children:
75d156
Parents:
549b62
git-author:
Frederik Heber <heber@…> (12/02/11 09:58:19)
git-committer:
Frederik Heber <heber@…> (12/13/11 09:46:12)
Message:

Added Observable::signOn() to get int wrapped in class PriorityLevel.

  • PriorityLevel makes the valid range check.
  • also this is preparatory for using size_t channelno instead of the ref to the notification in signing on to channels.
  • this is required for relaying notifications.
Location:
src/Patterns
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Cacheable.hpp

    r549b62 r8fe1e2  
    180180    // we sign on with the best(=lowest) priority, so cached values are recalculated before
    181181    // anybody else might ask for updated values
    182     owner->signOn(this,-20);
     182    owner->signOn(this,Observable::PriorityLevel(int(-20)));
    183183  }
    184184
  • src/Patterns/Observer/Observable.cpp

    r549b62 r8fe1e2  
    2020#include "MemDebug.hpp"
    2121
     22#include "Observable.hpp"
     23
    2224#include "Assert.hpp"
    2325#include "Channels.hpp"
     26#include "defs.hpp"
    2427#include "Notification.hpp"
    25 #include "Observable.hpp"
    2628
    2729
     
    3638std::map<Observable*, int> Observable::depth;  //!< Map of Observables to the depth of the DAG of Observers
    3739std::map<Observable*,std::multimap<int,Observer*> > Observable::callTable; //!< Table for each Observable of all its Observers
    38 std::map<Observable*,std::set<Notification*> > Observable::notifications;
     40std::map<Observable*,std::set<Notification*> > Observable::notifications; //!< Table for all current notifications to perform
    3941std::set<Observable*> Observable::busyObservables; //!< Set of Observables that are currently busy notifying their sign-on'ed Observers
    4042Observable::ChannelMap Observable::NotificationChannels; //!< Map of Observables to their Channels.
     43
     44// ValidRange must be initialized before PriorityLevel.
     45range<int> Observable::PriorityLevel::ValidRange(-20, 21);
     46Observable::PriorityLevel Observable::PriorityDefault(int(0));
     47
     48/** Constructor of PriorityLevel.
     49 *
     50 * \note We check whether the level is within Observable::PriorityLevel::ValidRange.
     51 *
     52 * @param i priority level encapsulated in this class.
     53 */
     54Observable::PriorityLevel::PriorityLevel(const int i) :
     55    level(i)
     56{
     57  ASSERT(ValidRange.isInRange(level),
     58      "Observable::PriorityLevel::PriorityLevel() - Priority level "
     59      +toString(level)+" out of range "+toString(ValidRange)+".");
     60}
     61
     62Observable::PriorityLevel::~PriorityLevel()
     63{}
    4164
    4265/** Attaching Sub-observables to Observables.
     
    206229 * \param priority number in [-20,20]
    207230 */
    208 void Observable::signOn(Observer *target,int priority) const
    209 {
    210   ASSERT(priority>=-20 && priority<=+20,
    211       "Priority out of range [-20:+20] when signing on Observer");
     231void Observable::signOn(Observer *target, PriorityLevel priority) const
     232{
    212233#ifdef LOG_OBSERVER
    213234  observerLog().addMessage() << "@@ Signing on " << observerLog().getName(target) << " to " << observerLog().getName(const_cast<Observable *>(this)) << std::endl;
     
    221242  }
    222243  if(!res)
    223     callees.insert(std::pair<int,Observer*>(priority,target));
     244    callees.insert(std::pair<int,Observer*>(priority.level,target));
    224245}
    225246
  • src/Patterns/Observer/Observable.hpp

    r549b62 r8fe1e2  
    1818#include <string>
    1919
     20#include "Range.hpp"
    2021#include "Observer/defs.hpp"
    2122#include "Observer/Observer.hpp"
     
    3536  virtual ~Observable();
    3637
     38  /** This class is only used to distinguish from size_t in the overload.
     39   *
     40   * It encapsulates a const int (the priority level) and checks valid bounds
     41   * in constructor.
     42   *
     43   */
     44  class PriorityLevel {
     45  public:
     46    explicit PriorityLevel(const int i);
     47    ~PriorityLevel();
     48
     49    const int level;
     50  private:
     51    static range<int> ValidRange;
     52  };
     53
    3754  /**
    3855   * Sign an Observer on to this Observable. The Observer will be notified
     
    4663   * ussually no need to order the update sequence.
    4764   */
    48   virtual void signOn(Observer *target, int priority=0) const;
     65  virtual void signOn(Observer *target, PriorityLevel priority = PriorityDefault) const;
    4966
    5067  /**
     
    95112  static ChannelMap NotificationChannels;
    96113
     114  static PriorityLevel PriorityDefault;
     115
    97116private:
    98117  typedef std::multimap<int,Observer*> callees_t;
Note: See TracChangeset for help on using the changeset viewer.