1 // Copyright (C) 2006-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "OutPort.hxx"
22 #include "ComposedNode.hxx"
27 using namespace YACS::ENGINE;
30 InPort::InPort(const InPort& other, Node *newHelder):
31 DataPort(other,newHelder),Port(other,newHelder)
35 InPort::InPort(const std::string& name, Node *node, TypeCode* type):
36 DataPort(name,node,type),Port(node)
44 //! Returns number of \b physical backlinks \b NOT number of user backlinks.
45 int InPort::edGetNumberOfLinks() const
47 return _backLinks.size();
50 void InPort::edRemoveAllLinksLinkedWithMe()
52 set< std::pair<OutPort *,bool> > temp(_backLinks);//edRemoveLink called after causes invalidation of set iterator.
55 set<OutPort *> trueBackOutputs;
56 iter.first->getAllRepresented(trueBackOutputs);
57 for( auto iter2 : trueBackOutputs )
58 _node->getRootNode()->edRemoveLink(iter2,this);
64 //! Returns \b physical backlinks \b NOT user backlinks.
65 std::set<OutPort *> InPort::edSetOutPort() const
67 std::set<OutPort *> ret;
68 for( auto iter : _backLinks )
69 ret.insert(iter.first);
73 bool InPort::canSafelySqueezeMemory() const
77 for(auto bl : _backLinks)
86 * \param [in] isLoopProof - Tells if the data coming from \a fromPort will be send again in case of \a this is initialized. This value is
87 * important if \a this is an InPort of a Node contained directly or not inside a Loop, ForEachLoop, OptimizerLoop.
88 * In this case, to optimize memory consumption (see squeezeMemory method), we need to know if data coming from \a fromPort
89 * will be generated again in case.
90 * If true (the default) it means that for that link is a link loop proof so no need to take care. If false, the link is not loop proof so
91 * event in the context of agressive memory management the data can't be safely released.
93 void InPort::edNotifyReferencedBy(OutPort *fromPort, bool isLoopProof)
95 auto it(std::find_if(_backLinks.begin(),_backLinks.end(),[fromPort](const std::pair<OutPort *,bool>& p){ return p.first==fromPort; }));
96 if(it!=_backLinks.end())
98 _backLinks.insert(std::pair<OutPort *,bool>(fromPort,isLoopProof));
102 void InPort::edNotifyDereferencedBy(OutPort *fromPort)
104 auto it(std::find_if(_backLinks.begin(),_backLinks.end(),[fromPort](const std::pair<OutPort *,bool>& p){ return p.first==fromPort; }));
105 if(it!=_backLinks.end())
106 _backLinks.erase(it);
110 void InPort::getAllRepresentants(std::set<InPort *>& repr) const
112 repr.insert((InPort *)this);