2 #include "InputPort.hxx"
3 #include "OutputPort.hxx"
4 #include "InputDataStreamPort.hxx"
5 #include "OutputDataStreamPort.hxx"
6 #include "TypeCheckerDataStream.hxx"
8 using namespace YACS::ENGINE;
10 DFToDSForLoop::DFToDSForLoop(Loop *loop, const std::string& name, YACS::DynType type):ElementaryNode(""),_nbOfTimeUsed(1)
12 _name="DF2DS For "; _name+=loop->getName(); _name+=" representing port "; _name+=name;
14 _listOfInputPort.push_back(new InputPort("",this,type));
15 _listOfOutputDataStreamPort.push_back(new OutputDataStreamPort("",this,Loop::MappingDF2DS(type)));
18 DFToDSForLoop::~DFToDSForLoop()
22 InputPort *DFToDSForLoop::getInputPort(const std::string& name) const throw(Exception)
24 return (InputPort *) &_listOfInputPort.back();
27 OutputDataStreamPort *DFToDSForLoop::getOutputDataStreamPort(const std::string& name) const throw(Exception)
29 return (OutputDataStreamPort *) &_listOfOutputDataStreamPort.back();
32 void DFToDSForLoop::execute()
37 DSToDFForLoop::DSToDFForLoop(Loop *loop, const std::string& name, YACS::StreamType type):ElementaryNode(""),_nbOfTimeUsed(1)
39 _name="DS2DF For "; _name+=loop->getName(); _name+=" representing port "; _name+=name;
41 _listOfOutputPort.push_back(new OutputPort("",this,Loop::MappingDS2DF(type)));
42 _listOfInputDataStreamPort.push_back(new InputDataStreamPort("",this,type));
45 DSToDFForLoop::~DSToDFForLoop()
49 OutputPort *DSToDFForLoop::getOutputPort(const std::string& name) const throw(Exception)
51 return (OutputPort *) &_listOfOutputPort.back();
54 InputDataStreamPort *DSToDFForLoop::getInputDataStreamPort(const std::string& name) const throw(Exception)
56 return (InputDataStreamPort *) &_listOfInputDataStreamPort.back();
59 void DSToDFForLoop::execute()
64 Loop::Loop(const std::string& name):ComposedNode(name),_node(0)
73 void Loop::edSetNode(Node *node)
79 void Loop::edAddExtraInputPort(const std::string& inputPortName, YACS::DynType type) throw(Exception)
81 edAddPort<InputPort,YACS::DynType>(inputPortName,_listOfExtraInputPort,type);
84 void Loop::edRemoveExtraInputPort(InputPort *inputPort)
86 edRemovePortTypedFromList<InputPort>(inputPort,_listOfExtraInputPort);
89 YACS::StreamType Loop::MappingDF2DS(YACS::DynType type) throw(Exception)
96 std::string what("Loop::MappingDF2DS : unable to perform DataFlow to DataStream traduction for dataflow type ");
97 what+=Data::edGetTypeInPrintableForm(type);
98 throw Exception(what);
101 YACS::DynType Loop::MappingDS2DF(YACS::StreamType type) throw(Exception)
108 std::string what("Loop::MappingDS2DF : unable to perform DataStream to DataFlow traduction for datastream type ");
109 what+=TypeCheckerDataStream::edGetTypeInPrintableForm(type);
110 throw Exception(what);
113 InPort *Loop::buildDelegateOf(InPort *port, const std::list<ComposedNode *>& pointsOfView)
115 std::string typeOfPortInstance=port->getNameOfTypeOfCurrentInstance();
116 if(typeOfPortInstance!=InputPort::NAME)
119 if(!isNecessaryToBuildSpecificDelegateDF2DS(pointsOfView))
121 InputPort *portCasted=(InputPort *)port;
122 std::list<DSToDFForLoop>::iterator iter;
123 //Determinig if a DSToDFForLoop node has already been created for delegation of 'port'
124 for(iter=_inputsTraducer.begin();iter!=_inputsTraducer.end();iter++)
125 if((*iter).getOutputPort("")->isAlreadyInList(portCasted))
127 if(iter==_inputsTraducer.end())
128 {//first time that 'port' is delegated on higher level
129 _inputsTraducer.push_back(DSToDFForLoop(this,portCasted->getName(),Loop::MappingDF2DS(portCasted->edGetType())));
130 iter=_inputsTraducer.end(); iter--;
131 (*iter).getOutputPort("")->edAddInputPort(portCasted);
132 //WARNING control flow has to be added
133 (*iter).getOutGate()->edAddInGate(portCasted->getNode()->getInGate());//WARNING HERE MAYBE HAS TO BE IMPROVED - SEPARATE COUNTERS
136 (*iter).loopHasOneMoreRef();
137 return (*iter).getInputDataStreamPort("");
140 OutPort *Loop::buildDelegateOf(OutPort *port, const std::list<ComposedNode *>& pointsOfView)
142 std::string typeOfPortInstance=port->getNameOfTypeOfCurrentInstance();
143 if(typeOfPortInstance!=OutputPort::NAME)
146 if(!isNecessaryToBuildSpecificDelegateDF2DS(pointsOfView))
148 OutputPort *portCasted=(OutputPort *)port;
149 std::list<DFToDSForLoop>::iterator iter;
150 //Determinig if a DFToDSForLoop node has already been created for delegation of 'port'
151 for(iter=_outputsTraducer.begin();iter!=_outputsTraducer.end();iter++)
152 if(portCasted->isAlreadyInList((*iter).getInputPort("")))
154 if(iter==_outputsTraducer.end())
155 {//first time that 'port' is delegated on higher level
156 _outputsTraducer.push_back(DFToDSForLoop(this,portCasted->getName(),portCasted->edGetType()));
157 iter=_outputsTraducer.end(); iter--;
158 portCasted->edAddInputPort((*iter).getInputPort(""));
159 //WARNING control flow has to be added
160 portCasted->getNode()->getOutGate()->edAddInGate((*iter).getInGate());//WARNING HERE MAYBE HAS TO BE IMPROVED - SEPARATE COUNTERS
163 (*iter).loopHasOneMoreRef();
164 return (*iter).getOutputDataStreamPort("");
167 InPort *Loop::getDelegateOf(InPort *port, const std::list<ComposedNode *>& pointsOfView) throw(Exception)
169 std::string typeOfPortInstance=port->getNameOfTypeOfCurrentInstance();
170 if(typeOfPortInstance!=InputPort::NAME)
173 if(!isNecessaryToBuildSpecificDelegateDF2DS(pointsOfView))
175 InputPort *portCasted=(InputPort *)port;
176 std::list<DSToDFForLoop>::iterator iter;
177 for(iter=_inputsTraducer.begin();iter!=_inputsTraducer.end();iter++)
178 if((*iter).getOutputPort("")->isAlreadyInList(portCasted))
180 if(iter==_inputsTraducer.end())
182 std::string what("Loop::getDelegateOf Port with name "); what+=portCasted->getName(); what+=" not exported by loop "; what+=_name;
183 throw Exception(what);
186 return (*iter).getInputDataStreamPort("");
189 OutPort *Loop::getDelegateOf(OutPort *port, const std::list<ComposedNode *>& pointsOfView) throw(Exception)
191 std::string typeOfPortInstance=port->getNameOfTypeOfCurrentInstance();
192 if(typeOfPortInstance!=OutputPort::NAME)
195 if(!isNecessaryToBuildSpecificDelegateDF2DS(pointsOfView))
197 OutputPort *portCasted=(OutputPort *)port;
198 std::list<DFToDSForLoop>::iterator iter;
199 for(iter=_outputsTraducer.begin();iter!=_outputsTraducer.end();iter++)
200 if(portCasted->isAlreadyInList((*iter).getInputPort("")))
202 if(iter==_outputsTraducer.end())
204 std::string what("Loop::getDelegateOf Port with name "); what+=portCasted->getName(); what+=" not exported by loop "; what+=_name;
205 throw Exception(what);
208 return (*iter).getOutputDataStreamPort("");
211 InPort *Loop::releaseDelegateOf(InPort *port, const std::list<ComposedNode *>& pointsOfView) throw(Exception)
213 std::string typeOfPortInstance=port->getNameOfTypeOfCurrentInstance();
214 if(typeOfPortInstance!=InputPort::NAME)
217 if(!isNecessaryToBuildSpecificDelegateDF2DS(pointsOfView))
219 InputPort *portCasted=(InputPort *)port;
220 std::list<DSToDFForLoop>::iterator iter;
221 for(iter=_inputsTraducer.begin();iter!=_inputsTraducer.end();iter++)
222 if((*iter).getOutputPort("")->isAlreadyInList(portCasted))
224 if(iter==_inputsTraducer.end())
226 std::string what("Loop::releaseDelegateOf Port with name "); what+=portCasted->getName(); what+=" not exported by loop "; what+=_name;
227 throw Exception(what);
231 InPort *ret=(*iter).getInputDataStreamPort("");
232 if((*iter).loopHasOneLessRef())
233 _inputsTraducer.erase(iter);
238 OutPort *Loop::releaseDelegateOf(OutPort *port, const std::list<ComposedNode *>& pointsOfView) throw(Exception)
240 std::string typeOfPortInstance=port->getNameOfTypeOfCurrentInstance();
241 if(typeOfPortInstance!=OutputPort::NAME)
244 if(!isNecessaryToBuildSpecificDelegateDF2DS(pointsOfView))
246 OutputPort *portCasted=(OutputPort *)port;
247 std::list<DFToDSForLoop>::iterator iter;
248 for(iter=_outputsTraducer.begin();iter!=_outputsTraducer.end();iter++)
249 if(portCasted->isAlreadyInList((*iter).getInputPort("")))
251 if(iter==_outputsTraducer.end())
253 std::string what("Loop::releaseDelegateOf Port with name "); what+=portCasted->getName(); what+=" not exported by loop "; what+=_name;
254 throw Exception(what);
258 OutPort *ret=(*iter).getOutputDataStreamPort("");
259 if((*iter).loopHasOneLessRef())
260 _outputsTraducer.erase(iter);
265 void Loop::checkNoCyclePassingThrough(Node *node) throw(Exception)
267 throw Exception("Loop::checkNoCyclePassingThrough : Internal error occured");
271 * @ note : States if a DF port must be considered on an upper level in hierarchy as a DS port or not from 'pointsOfView' observers.
273 * - True : a traduction DF->DS has to be done
274 * - False : no traduction needed
276 bool Loop::isNecessaryToBuildSpecificDelegateDF2DS(const std::list<ComposedNode *>& pointsOfView)
279 for(std::list<ComposedNode *>::const_iterator iter=pointsOfView.begin();iter!=pointsOfView.end() && !ret;iter++)
280 ret=(*iter)->isRepeatedUnpredictablySeveralTimes();