Salome HOME
babe45ddd227b42eaa66ad1f1566b9fdf54ae712
[modules/yacs.git] / src / engine / LinkedBlocPoint.cxx
1 // Copyright (C) 2015-2019  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "LinkedBlocPoint.hxx"
21 #include "PointVisitor.hxx"
22 #include "Exception.hxx"
23
24 #ifdef WIN32
25 #include <algorithm>
26 #endif
27
28
29 using namespace YACS::ENGINE;
30
31 LinkedBlocPoint::LinkedBlocPoint(const std::list<AbstractPoint *>& nodes, AbstractPoint *father):BlocPoint(nodes,father)
32 {
33 }
34
35 Node *LinkedBlocPoint::getFirstNode()
36 {
37   if(_nodes.empty())
38     throw Exception("LinkedBlocPoint::getFirstNode : error no branches !");
39   return _nodes.front()->getFirstNode();
40 }
41
42 Node *LinkedBlocPoint::getLastNode()
43 {
44   if(_nodes.empty())
45     throw Exception("LinkedBlocPoint::getFirstNode : error no branches !");
46   return _nodes.back()->getLastNode();
47 }
48
49 int LinkedBlocPoint::getMaxLevelOfParallelism() const
50 {
51   int ret(0);
52   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
53     ret=std::max(ret,(*it)->getMaxLevelOfParallelism());
54   return ret;
55 }
56
57 void LinkedBlocPoint::getWeightRegardingDPL(ComplexWeight *weight)
58 {
59   ComplexWeight localWeight;
60   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
61   {
62     (*it)->getWeightRegardingDPL(&localWeight);
63     weight->addWeight(&localWeight);
64     localWeight.setToZero();
65   }
66 }
67
68 void LinkedBlocPoint::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
69 {
70   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
71     (*it)->partitionRegardingDPL(pd,zeMap);
72 }
73
74 std::string LinkedBlocPoint::getRepr() const
75 {
76   std::size_t sz(_nodes.size()),ii(0);
77   std::string ret("(");
78   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
79     {
80       ret+=(*it)->getRepr();
81       if(ii!=sz-1)
82         ret+="+";
83     }
84   ret+=")";
85   return ret;
86 }
87
88 void LinkedBlocPoint::accept(PointVisitor *pv)
89 {
90   pv->beginLinkedBlocPoint(this);
91   for(auto it:_nodes)
92     it->accept(pv);
93   pv->endLinkedBlocPoint(this);
94 }
95
96 LinkedBlocPoint::~LinkedBlocPoint()
97 {
98 }