/**
  *  This function removes a listener from listening for notification
  *  This may be called during a notify call on the currently notified listener only
  */
 virtual void removeListener(ListenerPtr p) {
     this->listenerRemoved(p);
     if (mListeners.size()>1) {
         typename ListenerMap::iterator where=mListenerIndex.find(p);
         assert(where!=mListenerIndex.end());
         if (where->second+1!=mListeners.size()) {
             mListenerIndex[mListeners.back()]=where->second;
             mListeners[where->second]=mListeners.back();
         }
         mListeners.resize(mListeners.size()-1);                
         mListenerIndex.erase(where);
     }else {
         this->lastListenerRemoved(p);
         assert(mListeners[0]==p);
         mListeners.resize(0);
         mListenerIndex=ListenerMap();
     }
 }
void Environment::cleanupUnusedListeners(ListenerMap& list)
{
  for(ListenerMap::iterator giter = list.begin(), gend = list.end(); giter != gend; ++giter)
    cleanupUnusedListeners(giter->second);
}