From 250da110a79b13043e8f75fab2b3cdd553406f35 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 2 Oct 2015 15:57:07 +0200 Subject: [PATCH] map->list for InGates too. --- src/engine/Bloc.hxx | 4 ++-- src/engine/InGate.cxx | 47 ++++++++++++++++++++++++++++++++----------- src/engine/InGate.hxx | 5 ++--- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/engine/Bloc.hxx b/src/engine/Bloc.hxx index 7560f7124..a46ae682c 100644 --- a/src/engine/Bloc.hxx +++ b/src/engine/Bloc.hxx @@ -110,8 +110,8 @@ namespace YACS template<> struct CFDirectionVisTraits { - typedef std::map::iterator Iterator; - typedef std::map& Nexts; + typedef std::list< std::pair >::iterator Iterator; + typedef std::list< std::pair >& Nexts; static Nexts getNexts(Node *node) { return node->getInGate()->edMapOutGate(); } }; diff --git a/src/engine/InGate.cxx b/src/engine/InGate.cxx index 49eb3abb5..7a85b6e98 100644 --- a/src/engine/InGate.cxx +++ b/src/engine/InGate.cxx @@ -23,6 +23,8 @@ //#define _DEVDEBUG_ #include "YacsTrace.hxx" +#include + using namespace YACS::ENGINE; using namespace std; @@ -43,11 +45,20 @@ string InGate::getNameOfTypeOfCurrentInstance() const void InGate::edDisconnectAllLinksToMe() { - for(map::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++) + for(list< std::pair >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++) ((*iter).first)->edRemoveInGate(this,false); _backLinks.clear(); } +class ItemCmp +{ +private: + OutGate *_itf; +public: + ItemCmp(OutGate *itf):_itf(itf) { } + bool operator()(const std::pair& elt) const { return elt.first==_itf; } +}; + //! Notify this port that an upstream node connected by a control flow link is finished /*! * Calls the node's gate method : Node::exUpdateState @@ -57,7 +68,9 @@ void InGate::edDisconnectAllLinksToMe() void InGate::exNotifyFromPrecursor(OutGate *from) { DEBTRACE("InGate::exNotifyFromPrecursor"); - map< OutGate *, bool >::iterator iter=_backLinks.find(from); + list< pair >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from))); + if(iter==_backLinks.end()) + throw YACS::Exception("InGate::exNotifyFromPrecursor : precursor not found !"); (*iter).second=true; if(exIsReady()) _node->exUpdateState(); @@ -69,7 +82,8 @@ void InGate::exNotifyFromPrecursor(OutGate *from) */ void InGate::exNotifyFailed() { - if(_node) _node->exFailedState(); + if(_node) + _node->exFailedState(); } //! Notify this port that an upstream node connected by a control flow link has been disabled @@ -84,12 +98,18 @@ void InGate::exNotifyDisabled() void InGate::edAppendPrecursor(OutGate *from) { - _backLinks[from]=false; + list< pair >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from))); + if(iter!=_backLinks.end()) + (*iter).second=false; + else + _backLinks.push_back(pair(from,false)); } void InGate::edRemovePrecursor(OutGate *from) { - _backLinks.erase(from); + list< pair >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from))); + if(iter!=_backLinks.end()) + _backLinks.erase(iter); } int InGate::getNumberOfBackLinks() const @@ -99,14 +119,14 @@ int InGate::getNumberOfBackLinks() const void InGate::exReset() { - for(map::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++) + for(list< std::pair >::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++) (*iter).second=false; } bool InGate::exIsReady() const { - bool isReady=true; - for(map::const_iterator iter=_backLinks.begin();iter!=_backLinks.end() && isReady;iter++) + bool isReady(true); + for(list< std::pair >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end() && isReady;iter++) isReady=(*iter).second; return isReady; } @@ -114,13 +134,16 @@ bool InGate::exIsReady() const std::list InGate::getBackLinks() { list listo; - for(map::iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++) + for(list< std::pair >::const_iterator iter=_backLinks.begin();iter!=_backLinks.end();iter++) listo.push_back(iter->first); - return listo; + return listo; } void InGate::setPrecursorDone(OutGate *from) { - map< OutGate *, bool >::iterator iter=_backLinks.find(from); - (*iter).second=true; + list< std::pair >::iterator iter(std::find_if(_backLinks.begin(),_backLinks.end(),ItemCmp(from))); + if(iter!=_backLinks.end()) + (*iter).second=true; + else + throw YACS::Exception("InGate::setPrecursorDone : precursor not found !"); } diff --git a/src/engine/InGate.hxx b/src/engine/InGate.hxx index 3ac671fcc..b3186bf3d 100644 --- a/src/engine/InGate.hxx +++ b/src/engine/InGate.hxx @@ -24,7 +24,6 @@ #include "Port.hxx" #include "define.hxx" -#include #include namespace YACS @@ -40,13 +39,13 @@ namespace YACS protected: static const char NAME[]; private: - std::map< OutGate *, bool > _backLinks; + std::list< std::pair > _backLinks; public: InGate(Node *node); virtual ~InGate(); std::string getNameOfTypeOfCurrentInstance() const; void exNotifyFromPrecursor(OutGate *fromgate); - std::map& edMapOutGate() { return _backLinks; } + std::list< std::pair >& edMapOutGate() { return _backLinks; } void edAppendPrecursor(OutGate *fromgate); void edRemovePrecursor(OutGate *fromgate); int getNumberOfBackLinks() const; -- 2.39.2