]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/BagPoint.cxx
Salome HOME
small debug
[modules/yacs.git] / src / engine / BagPoint.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 "BagPoint.hxx"
21 #include "Exception.hxx"
22 #include "LinkedBlocPoint.hxx"
23 #include "ForkBlocPoint.hxx"
24
25 #include <sstream>
26 #include <algorithm>
27
28 using namespace YACS::ENGINE;
29
30 BagPoint::BagPoint(const std::list<AbstractPoint *>& nodes, AbstractPoint *father):BlocPoint(nodes,father)
31 {
32 }
33
34 Node *BagPoint::getFirstNode()
35 {
36   if(_nodes.size()!=1)
37     throw YACS::Exception("BagPoint::getFirstNode : invalid call !");
38   else
39     return (*_nodes.begin())->getFirstNode();
40 }
41
42 Node *BagPoint::getLastNode()
43 {
44   if(_nodes.size()!=1)
45     throw YACS::Exception("BagPoint::getLastNode : invalid call !");
46   else
47     return (*_nodes.begin())->getLastNode();
48 }
49
50 int BagPoint::getMaxLevelOfParallelism() const
51 {
52   if(_nodes.size()!=1)
53     throw YACS::Exception("BagPoint::getMaxLevelOfParallelism : invalid call !");
54   else
55     return (*_nodes.begin())->getMaxLevelOfParallelism();
56 }
57
58 std::string BagPoint::getRepr() const
59 {
60   std::ostringstream oss;
61   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
62     oss << (*it)->getRepr() << " - ";
63   return oss.str();
64 }
65
66 #include <iostream>
67
68 void BagPoint::replaceInMe(BlocPoint *aSet)
69 {
70   const std::list<AbstractPoint *>& pts(aSet->getListOfPoints());
71   for(std::list<AbstractPoint *>::const_iterator it0=pts.begin();it0!=pts.end();it0++)
72     {
73       std::list<AbstractPoint *>::iterator it1(std::find(_nodes.begin(),_nodes.end(),*it0));
74       if(it1==_nodes.end())
75         throw Exception("SetOfPoints::replaceInMe : internal error !");
76       _nodes.erase(it1);
77     }
78   _nodes.push_back(aSet);
79 }
80
81 void BagPoint::deal1(bool& somethingDone)
82 {
83   somethingDone=false;
84   for(std::list<AbstractPoint *>::iterator it=_nodes.begin();it!=_nodes.end();it++)
85     {
86       if(!(*it)->isSimplyLinkedBeforeAfter(this))
87         if(!(*it)->isSimplyLinkedAfterNullBefore(this) && !(*it)->isSimplyLinkedBeforeNullAfter(this))
88            continue;
89       LinkedBlocPoint *try0((*it)->tryAsLink(this));
90       if(try0)
91         {
92           replaceInMe(try0);
93           somethingDone=true;
94           break;
95         }
96     }
97 }
98
99 void BagPoint::deal2(bool& somethingDone)
100 {
101   somethingDone=false;
102   for(std::list<AbstractPoint *>::iterator it=_nodes.begin();it!=_nodes.end();it++)
103     {
104       if(!(*it)->isSimplyLinkedBeforeAfter(this))
105         continue;
106       ForkBlocPoint *try1((*it)->tryAsFork(this));
107       if(try1)
108         {
109           replaceInMe(try1);
110           somethingDone=true;
111           break;
112         }
113     }
114 }
115
116 void BagPoint::deal2Bis(bool& somethingDone)
117 {
118   somethingDone=false;
119   for(std::list<AbstractPoint *>::iterator it=_nodes.begin();it!=_nodes.end();it++)
120     {
121       if(!(*it)->isSimplyLinkedAfterNullBefore(this))
122         continue;
123       ForkBlocPoint *try1((*it)->tryAsForkBis(this));
124       if(try1)
125         {
126           replaceInMe(try1);
127           somethingDone=true;
128           break;
129         }
130     }
131 }
132
133 void BagPoint::deal2Ter(bool& somethingDone)
134 {
135   somethingDone=false;
136   for(std::list<AbstractPoint *>::iterator it=_nodes.begin();it!=_nodes.end();it++)
137     {
138       if(!(*it)->isSimplyLinkedBeforeNullAfter(this))
139         continue;
140       ForkBlocPoint *try1((*it)->tryAsForkTer(this));
141       if(try1)
142         {
143           replaceInMe(try1);
144           somethingDone=true;
145           break;
146         }
147       }
148 }
149