Salome HOME
updated copyright message
[modules/yacs.git] / src / engine / Dispatcher.cxx
index 8307dbbef52b1e585356b6220eb53a6a881e909e..46d649cfd021f122661fba471fc420baff87eeb1 100644 (file)
@@ -1,21 +1,22 @@
-//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2023  CEA, EDF
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "Dispatcher.hxx"
 #include "Node.hxx"
 #include <iostream>
@@ -34,6 +35,16 @@ void Observer::notifyObserver(Node* object, const std::string& event)
   DEBTRACE("notifyObserver " << event << object );
 }
 
+void Observer::notifyObserver2(Node* object,const std::string& event, void *something)
+{
+  DEBTRACE("notifyObserver2 " << event << object );
+}
+
+void Observer::notifyObserverFromClone(Node *originalInstance, const std::string& event, Node *clonedInstanceGeneratingEvent)
+{
+  DEBTRACE("notifyObserverFromClone " << event << originalInstance );
+}
+
 Dispatcher* Dispatcher::_singleton = 0;
 
 Dispatcher::~Dispatcher()
@@ -74,17 +85,43 @@ void Dispatcher::printObservers()
 void Dispatcher::dispatch(Node* object, const std::string& event)
 {
   DEBTRACE("Dispatcher::dispatch " << event );
-  typedef std::set<Observer*>::iterator jt;
   std::pair<Node*,std::string> key(object,event);
-  if(_observers.count(key) != 0)
+  std::map< std::pair<Node*,std::string> , std::set<Observer*> >::const_iterator it(_observers.find(key));
+  if(it!=_observers.end())
     {
-      for(jt iter=_observers[key].begin();iter!=_observers[key].end();iter++)
+      for(std::set<Observer*>::const_iterator iter=(*it).second.begin();iter!=(*it).second.end();iter++)
         {
           (*iter)->notifyObserver(object,event);
         }
     }
 }
 
+void Dispatcher::dispatch2(Node* object,const std::string& event, void *something)
+{
+  std::pair<Node*,std::string> key(object,event);
+  std::map< std::pair<Node*,std::string> , std::set<Observer*> >::const_iterator it(_observers.find(key));
+  if(it!=_observers.end())
+    {
+      for(std::set<Observer*>::const_iterator iter=(*it).second.begin();iter!=(*it).second.end();iter++)
+        {
+          (*iter)->notifyObserver2(object,event,something);
+        }
+    }
+}
+
+void Dispatcher::dispatchFromClone(Node *originalInstance, const std::string& event, Node *clonedInstanceGeneratingEvent)
+{
+  std::pair<Node*,std::string> key(originalInstance,event);
+  std::map< std::pair<Node*,std::string> , std::set<Observer*> >::const_iterator it(_observers.find(key));
+  if(it!=_observers.end())
+    {
+      for(std::set<Observer*>::const_iterator iter=(*it).second.begin();iter!=(*it).second.end();iter++)
+        {
+          (*iter)->notifyObserverFromClone(originalInstance,event,clonedInstanceGeneratingEvent);
+        }
+    }
+}
+
 void Dispatcher::addObserver(Observer* observer,Node* object, const std::string& event)
 {
   _observers[std::pair<Node*,std::string>(object,event)].insert(observer);