Salome HOME
e9c32e8f5b69c8606a37dda1cfed25e0b5331e5f
[modules/yacs.git] / src / engine / LinkedBlocPoint.cxx
1 // Copyright (C) 2015-2016  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 using namespace YACS::ENGINE;
25
26 LinkedBlocPoint::LinkedBlocPoint(const std::list<AbstractPoint *>& nodes, AbstractPoint *father):BlocPoint(nodes,father)
27 {
28 }
29
30 Node *LinkedBlocPoint::getFirstNode()
31 {
32   if(_nodes.empty())
33     throw Exception("LinkedBlocPoint::getFirstNode : error no branches !");
34   return _nodes.front()->getFirstNode();
35 }
36
37 Node *LinkedBlocPoint::getLastNode()
38 {
39   if(_nodes.empty())
40     throw Exception("LinkedBlocPoint::getFirstNode : error no branches !");
41   return _nodes.back()->getLastNode();
42 }
43
44 int LinkedBlocPoint::getMaxLevelOfParallelism() const
45 {
46   int ret(0);
47   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
48     ret=std::max(ret,(*it)->getMaxLevelOfParallelism());
49   return ret;
50 }
51
52 void LinkedBlocPoint::getWeightRegardingDPL(ComplexWeight *weight)
53 {
54   ComplexWeight localWeight;
55   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
56   {
57     (*it)->getWeightRegardingDPL(&localWeight);
58     weight->addWeight(&localWeight);
59     localWeight.setToZero();
60   }
61 }
62
63 void LinkedBlocPoint::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
64 {
65   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
66     (*it)->partitionRegardingDPL(pd,zeMap);
67 }
68
69 std::string LinkedBlocPoint::getRepr() const
70 {
71   std::size_t sz(_nodes.size()),ii(0);
72   std::string ret("(");
73   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
74     {
75       ret+=(*it)->getRepr();
76       if(ii!=sz-1)
77         ret+="+";
78     }
79   ret+=")";
80   return ret;
81 }
82
83 void LinkedBlocPoint::accept(PointVisitor *pv)
84 {
85   pv->beginLinkedBlocPoint(this);
86   for(auto it:_nodes)
87     it->accept(pv);
88   pv->endLinkedBlocPoint(this);
89 }
90
91 LinkedBlocPoint::~LinkedBlocPoint()
92 {
93 }