Index: src/Patterns/Observer.cpp
===================================================================
--- src/Patterns/Observer.cpp	(revision 9ad39100c520f261ac05516e4832db65f031d140)
+++ src/Patterns/Observer.cpp	(revision 0c1d972b5cd5790e8579c86f2e76863867a9c955)
@@ -10,4 +10,5 @@
 
 #include <iostream>
+#include <cassert>
 
 using namespace std;
@@ -24,5 +25,5 @@
 
 map<Observable*, int> Observable::depth;
-multimap<Observable*,Observer*> Observable::callTable;
+map<Observable*,multimap<int,Observer*>*> Observable::callTable;
 set<Observable*> Observable::busyObservables;
 
@@ -54,6 +55,4 @@
 /************* Notification mechanism for observables **************/
 
-typedef multimap<Observable*,Observer*>::iterator callIterator;
-typedef pair<callIterator, callIterator> iteratorRange;
 
 void Observable::notifyAll() {
@@ -64,9 +63,12 @@
   // and call all observers
   if(callTable.count(this)) {
-     iteratorRange callerRange = callTable.equal_range(this);
-     callIterator iter;
-     for(iter=callerRange.first;iter!=callerRange.second;iter++){
-       (*iter).second->update(this);
-     }
+    // elements are stored sorted by keys in the multimap
+    // so iterating over it gives us a the callees sorted by
+    // the priorities
+    callees_t *callees = callTable[this];
+    callees_t::iterator iter;
+    for(iter=callees->begin();iter!=callees->end();iter++){
+      (*iter).second->update(this);
+    }
   }
   // done with notification, we can leave the set of busy subjects
@@ -97,21 +99,35 @@
 
 // methods to sign-on and off
-void Observable::signOn(Observer *target) {
+void Observable::signOn(Observer *target,int priority) {
+  assert(priority>=-20 && priority<=+20 && "Priority out of range [-20:+20]");
   bool res = false;
-  iteratorRange callerRange = callTable.equal_range(this);
-  callIterator iter;
-  for(iter=callerRange.first;iter!=callerRange.second;iter++){
+  callees_t *callees = 0;
+  if(callTable.count(this)){
+    callees = callTable[this];
+  }
+  else {
+    callees = new multimap<int,Observer*>;
+    callTable.insert(pair<Observable*,callees_t*>(this,callees));
+  }
+
+  callees_t::iterator iter;
+  for(iter=callees->begin();iter!=callees->end();iter++){
     res |= ((*iter).second == target);
   }
   if(!res)
-    callTable.insert(pair<Observable*,Observer*>(this,target));
+    callees->insert(pair<int,Observer*>(priority,target));
 }
 
 void Observable::signOff(Observer *target) {
-  iteratorRange callerRange = callTable.equal_range(this);
-  callIterator iter;
-  for(iter=callerRange.first;iter!=callerRange.second;iter++) {
+  assert(callTable.count(this) && "SignOff called for an Observable without Observers.");
+  callees_t *callees = callTable[this];
+  callees_t::iterator iter;
+  for(iter=callees->begin();iter!=callees->end();iter++) {
     if((*iter).second == target)
-      callTable.erase(iter);
+      callees->erase(iter);
+  }
+  if(callees->empty()){
+    callTable.erase(this);
+    delete callees;
   }
 }
@@ -127,11 +143,14 @@
 Observable::~Observable()
 {
-  // delete all entries for this observable
-  iteratorRange callerRange = callTable.equal_range(this);
-  callIterator iter;
-  for(iter=callerRange.first;iter!=callerRange.second;iter++){
-    (*iter).second->subjectKilled(this);
+  if(callTable.count(this)) {
+    // delete all entries for this observable
+    callees_t *callees = callTable[this];
+    callees_t::iterator iter;
+    for(iter=callees->begin();iter!=callees->end();iter++){
+      (*iter).second->subjectKilled(this);
+    }
+    callTable.erase(this);
+    delete callees;
   }
-  callTable.erase(callerRange.first,callerRange.second);
 }
 
Index: src/Patterns/Observer.hpp
===================================================================
--- src/Patterns/Observer.hpp	(revision 9ad39100c520f261ac05516e4832db65f031d140)
+++ src/Patterns/Observer.hpp	(revision 0c1d972b5cd5790e8579c86f2e76863867a9c955)
@@ -50,5 +50,5 @@
   virtual ~Observable();
 
-  virtual void signOn(Observer *target);
+  virtual void signOn(Observer *target, int priority=0);
   virtual void signOff(Observer *target);
 
@@ -72,6 +72,7 @@
 
 private:
+  typedef std::multimap<int,Observer*> callees_t;
   static std::map<Observable*, int> depth;
-  static std::multimap<Observable*,Observer*> callTable;
+  static std::map<Observable*,callees_t*> callTable;
   static std::set<Observable*> busyObservables;
 };
