1 // Copyright (C) 2006-2015 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
20 #include "ToyNode.hxx"
21 #include "TypeCode.hxx"
24 using namespace YACS::ENGINE;
27 char ToyNode::MY_IMPL_NAME[]="TOY";
29 const char ToyNode1S::KIND[]="TESTKIND1";
31 const char ToyNode2S::KIND[]="TESTKIND2";
33 char LimitNode::MY_IMPL_NAME[]="LIMIT";
35 char ToyNode::NAME_FOR_NB[]="NbOfEntries";
37 char SeqToyNode::NAME_NBOFELTS_INSEQ_INPRT[]="NbOfEltsInSeq";
39 char SeqToyNode::NAME_SEQ_OUTPRT[]="MySeq";
41 char Seq2ToyNode::NAME_SEQ_INPRT1[]="SeqIn1";
43 char Seq2ToyNode::NAME_SEQ_INPRT2[]="SeqIn2";
45 char Seq2ToyNode::NAME_SEQ_OUTPRT[]="SeqOut";
47 char Seq3ToyNode::NAME_SEQ_INPRT1[]="SeqIn1";
49 char Seq3ToyNode::NAME_SEQ_INPRT2[]="SeqIn2";
51 char Seq3ToyNode::NAME_SEQ_OUTPRT[]="SeqOut";
53 char LimitNode::NAME_FOR_SWPORT[]="SwitchPort";
55 char LimitNode::NAME_FOR_SWPORT2[]="SwitchPort2";
57 InputToyPort::InputToyPort(const InputToyPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),
61 _data=other._data->clone();
63 _initData=other._initData->clone();
66 InputToyPort::InputToyPort(const string& name, Node *node):InputPort(name, node, Runtime::_tc_double),DataPort(name, node, Runtime::_tc_double),Port(node),_data(0),_initData(0)
70 void InputToyPort::put(const void *data) throw(ConversionException)
75 bool InputToyPort::edIsManuallyInitialized() const
80 void *InputToyPort::get() const throw(YACS::Exception)
85 void InputToyPort::edRemoveManInit()
90 InputPort::edRemoveManInit();
93 InputPort *InputToyPort::clone(Node *newHelder) const
95 return new InputToyPort(*this,newHelder);
98 void InputToyPort::put(Any *data)
106 void InputToyPort::exSaveInit()
108 if(_initData) _initData->decrRef();
110 _initData->incrRef();
113 void InputToyPort::exRestoreInit()
115 if(!_initData)return;
116 if(_data) _data->decrRef();
121 InputToyPort::~InputToyPort()
126 _initData->decrRef();
129 OutputToyPort::OutputToyPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
133 OutputToyPort::OutputToyPort(const OutputToyPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),_data(0)
136 _data=other._data->clone();
139 void OutputToyPort::put(const void *data) throw(ConversionException)
142 OutputPort::put(data);
145 OutputPort *OutputToyPort::clone(Node *newHelder) const
147 return new OutputToyPort(*this,newHelder);
150 void OutputToyPort::put(Any *data)
158 OutputToyPort::~OutputToyPort()
164 void OutputToyPort::exInit()
173 ToyNode::ToyNode(const ToyNode& other, ComposedNode *father):ElementaryNode(other,father),_nbOfInputsPort(other._nbOfInputsPort,this)
177 ToyNode::ToyNode(const string& name):ElementaryNode(name),_nbOfInputsPort(NAME_FOR_NB,this,Runtime::_tc_int)
179 _implementation=MY_IMPL_NAME;
182 void ToyNode::execute()
186 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
189 InputToyPort *p=(InputToyPort *) (*iter);
190 d+=p->getAny()->getDoubleValue();
192 int size=_setOfOutputPort.size();
195 Any *tmp=AtomAny::New((int)_setOfInputPort.size());
196 _nbOfInputsPort.put((const void *)tmp);
198 for(list<OutputPort *>::iterator iter2=_setOfOutputPort.begin();iter2!=_setOfOutputPort.end();iter2++)
200 Any *tmp=AtomAny::New(d);
206 std::list<OutputPort *> ToyNode::getSetOfOutputPort() const
208 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
209 ret.push_back((OutputPort *)&_nbOfInputsPort);
213 int ToyNode::getNumberOfOutputPorts() const
215 return ElementaryNode::getNumberOfInputPorts()+1;
218 OutputPort *ToyNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
220 if(name==NAME_FOR_NB)
221 return (OutputPort *)&_nbOfInputsPort;
223 return ElementaryNode::getOutputPort(name);
226 Node *ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
228 return new ToyNode(*this,father);
231 ToyNode1S::ToyNode1S(const std::string& name):ServiceNode(name)
235 ToyNode1S::ToyNode1S(const ToyNode1S& other, ComposedNode *father):ServiceNode(other,father)
239 void ToyNode1S::execute()
241 //nothing only to test deployment calculation not for running.
244 std::string ToyNode1S::getKind() const
249 ServiceNode *ToyNode1S::createNode(const std::string& name)
251 ToyNode1S* node=new ToyNode1S(name);
252 node->setComponent(_component);
256 Node *ToyNode1S::simpleClone(ComposedNode *father, bool editionOnly) const
258 return new ToyNode1S(*this,father);
261 ToyNode2S::ToyNode2S(const std::string& name):ServiceNode(name)
265 ToyNode2S::ToyNode2S(const ToyNode2S& other, ComposedNode *father):ServiceNode(other,father)
269 void ToyNode2S::execute()
271 //nothing only to test deployment calculation not for running.
274 std::string ToyNode2S::getKind() const
279 ServiceNode *ToyNode2S::createNode(const std::string& name)
281 ToyNode2S* node=new ToyNode2S(name);
282 node->setComponent(_component);
286 Node *ToyNode2S::simpleClone(ComposedNode *father, bool editionOnly) const
288 return new ToyNode2S(*this,father);
291 void SeqToyNode::execute()
293 int val=_inIntValue.getIntValue();
294 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_double,val);
295 double d=(double) val;
296 for(int i=0;i<val;i++)
298 Any *tmp2=AtomAny::New(d);
299 tmp->setEltAtRank(i,tmp2);
303 _seqOut.put((const void *)tmp);
307 SeqToyNode::SeqToyNode(const SeqToyNode& other, ComposedNode *father):ElementaryNode(other,father),
308 _seqOut(other._seqOut,this),
309 _inIntValue(other._inIntValue,this)
313 SeqToyNode::SeqToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
314 _inIntValue(NAME_NBOFELTS_INSEQ_INPRT,this,Runtime::_tc_int)
316 _implementation=ToyNode::MY_IMPL_NAME;
317 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
318 _seqOut.edSetType(tc);
322 int SeqToyNode::getNumberOfInputPorts() const
324 return ElementaryNode::getNumberOfInputPorts()+1;
327 std::list<InputPort *> SeqToyNode::getSetOfInputPort() const
329 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
330 ret.push_back((InputPort *)&_inIntValue);
334 InputPort *SeqToyNode::getInputPort(const std::string& name) const throw(YACS::Exception)
336 if(name==NAME_NBOFELTS_INSEQ_INPRT)
337 return (InputPort *)&_inIntValue;
339 return ElementaryNode::getInputPort(name);
342 int SeqToyNode::getNumberOfOutputPorts() const
344 return ElementaryNode::getNumberOfOutputPorts()+1;
347 std::list<OutputPort *> SeqToyNode::getSetOfOutputPort() const
349 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
350 ret.push_back((OutputPort *)&_seqOut);
354 OutputPort *SeqToyNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
356 if(name==NAME_SEQ_OUTPRT)
357 return (OutputPort *)&_seqOut;
359 return ElementaryNode::getOutputPort(name);
362 Node *SeqToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
364 return new SeqToyNode(*this,father);
367 void Seq2ToyNode::execute()
369 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
370 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
371 int val=vals1->size();
372 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_int,val);
373 for(int i=0;i<val;i++)
375 Any *tmp2=AtomAny::New((int)((*vals1)[i]->getDoubleValue()+(*vals2)[i]->getDoubleValue()));
376 tmp->setEltAtRank(i,tmp2);
379 _seqOut.put((const void *)tmp);
383 Seq2ToyNode::Seq2ToyNode(const Seq2ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
384 _seqOut(other._seqOut,this),
385 _inValue1(other._inValue1,this),
386 _inValue2(other._inValue1,this)
390 Seq2ToyNode::Seq2ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
391 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
392 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
394 _implementation=ToyNode::MY_IMPL_NAME;
395 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
396 _inValue1.edSetType(tc);
397 _inValue2.edSetType(tc);
399 tc=new TypeCodeSeq("","",Runtime::_tc_int);
400 _seqOut.edSetType(tc);
404 int Seq2ToyNode::getNumberOfInputPorts() const
406 return ElementaryNode::getNumberOfOutputPorts()+2;
409 std::list<InputPort *> Seq2ToyNode::getSetOfInputPort() const
411 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
412 ret.push_back((InputPort *)&_inValue1);
413 ret.push_back((InputPort *)&_inValue2);
417 InputPort *Seq2ToyNode::getInputPort(const std::string& name) const throw(YACS::Exception)
419 if(name==NAME_SEQ_INPRT1)
420 return (InputPort *)&_inValue1;
421 else if(name==NAME_SEQ_INPRT2)
422 return (InputPort *)&_inValue2;
424 return ElementaryNode::getInputPort(name);
427 int Seq2ToyNode::getNumberOfOutputPorts() const
429 return ElementaryNode::getNumberOfOutputPorts()+1;
432 std::list<OutputPort *> Seq2ToyNode::getSetOfOutputPort() const
434 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
435 ret.push_back((OutputPort *)&_seqOut);
439 OutputPort *Seq2ToyNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
441 if(name==NAME_SEQ_OUTPRT)
442 return (OutputPort *)&_seqOut;
444 return ElementaryNode::getOutputPort(name);
447 Node *Seq2ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
449 return new Seq2ToyNode(*this,father);
452 void Seq3ToyNode::execute()
454 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
455 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
456 int val=vals1->size();
457 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_int);
458 SequenceAny *tmp=SequenceAny::New(tc1,val);
460 for(int i=0;i<val;i++)
462 Any *anyTemp=(Any *)(*vals1)[i];
463 SequenceAny *anyTemp2=(SequenceAny *)anyTemp;
464 int val2=anyTemp2->size();
465 SequenceAny *tmp2=SequenceAny::New(Runtime::_tc_int,val2);
466 for(int j=0;j<val2;j++)
468 Any *tmp3=AtomAny::New((int)((*vals1)[i][j]->getDoubleValue()+(*vals2)[i][j]->getDoubleValue()));
469 tmp2->setEltAtRank(j,tmp3);
472 tmp->setEltAtRank(i,tmp2);
475 _seqOut.put((const void *)tmp);
479 Seq3ToyNode::Seq3ToyNode(const Seq3ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
480 _seqOut(other._seqOut,this),
481 _inValue1(other._inValue1,this),
482 _inValue2(other._inValue1,this)
486 Seq3ToyNode::Seq3ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
487 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
488 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
490 _implementation=ToyNode::MY_IMPL_NAME;
491 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_double);
492 TypeCodeSeq *tc2=new TypeCodeSeq("","",tc1);
494 _inValue1.edSetType(tc2);
495 _inValue2.edSetType(tc2);
497 tc1=new TypeCodeSeq("","",Runtime::_tc_int);
498 tc2=new TypeCodeSeq("","",tc1);
500 _seqOut.edSetType(tc2);
504 int Seq3ToyNode::getNumberOfInputPorts() const
506 return ElementaryNode::getNumberOfOutputPorts()+2;
509 std::list<InputPort *> Seq3ToyNode::getSetOfInputPort() const
511 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
512 ret.push_back((InputPort *)&_inValue1);
513 ret.push_back((InputPort *)&_inValue2);
517 InputPort *Seq3ToyNode::getInputPort(const std::string& name) const throw(YACS::Exception)
519 if(name==NAME_SEQ_INPRT1)
520 return (InputPort *)&_inValue1;
521 else if(name==NAME_SEQ_INPRT2)
522 return (InputPort *)&_inValue2;
524 return ElementaryNode::getInputPort(name);
527 int Seq3ToyNode::getNumberOfOutputPorts() const
529 return ElementaryNode::getNumberOfOutputPorts()+1;
532 std::list<OutputPort *> Seq3ToyNode::getSetOfOutputPort() const
534 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
535 ret.push_back((OutputPort *)&_seqOut);
539 OutputPort *Seq3ToyNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
541 if(name==NAME_SEQ_OUTPRT)
542 return (OutputPort *)&_seqOut;
544 return ElementaryNode::getOutputPort(name);
547 Node *Seq3ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
549 return new Seq3ToyNode(*this,father);
552 InputLimitPort::InputLimitPort(const InputLimitPort& other, Node *newHelder):InputPort(other,newHelder),
553 DataPort(other,newHelder),Port(other,newHelder),
554 _data(0),_initData(0)
557 _data=other._data->clone();
559 _initData=other._initData->clone();
562 InputLimitPort::InputLimitPort(const string& name, Node *node)
563 :InputPort(name, node, Runtime::_tc_double),
564 DataPort(name, node, Runtime::_tc_double),
565 Port(node),_data(0),_initData(0)
569 void InputLimitPort::put(const void *data) throw(ConversionException)
574 InputPort *InputLimitPort::clone(Node *newHelder) const
576 return new InputLimitPort(*this,newHelder);
579 bool InputLimitPort::edIsManuallyInitialized() const
584 void *InputLimitPort::get() const throw(YACS::Exception)
588 string what="InputLimitPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
589 throw Exception(what);
591 return (void *)_data;
594 void InputLimitPort::edRemoveManInit()
597 _initData->decrRef();
599 InputPort::edRemoveManInit();
602 void InputLimitPort::put(Any *data)
610 void InputLimitPort::exSaveInit()
612 if(_initData) _initData->decrRef();
614 _initData->incrRef();
617 void InputLimitPort::exRestoreInit()
619 if(!_initData)return;
620 if(_data) _data->decrRef();
625 InputLimitPort::~InputLimitPort()
630 _initData->decrRef();
633 OutputLimitPort::OutputLimitPort(const OutputLimitPort& other, Node *newHelder):OutputPort(other,newHelder),
634 DataPort(other,newHelder),Port(other,newHelder),_data(0)
637 _data=other._data->clone();
640 OutputLimitPort::OutputLimitPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
644 void OutputLimitPort::put(const void *data) throw(ConversionException)
647 OutputPort::put(data);
650 OutputPort *OutputLimitPort::clone(Node *newHelder) const
652 return new OutputLimitPort(*this,newHelder);
655 void OutputLimitPort::put(Any *data)
663 OutputLimitPort::~OutputLimitPort()
669 void LimitNode::init(bool start)
676 void LimitNode::execute()
678 _current+=_entry.getAny()->getDoubleValue();
679 Any *tmp=AtomAny::New(_current);
680 _counterPort.put((const void *)tmp);
682 bool verdict=(_current<_limit);
683 tmp=AtomAny::New(verdict);
684 _switchPort.put((const void *)tmp);
688 Node *LimitNode::simpleClone(ComposedNode *father, bool editionOnly) const
690 return new LimitNode(*this,father);
693 std::list<InputPort *> LimitNode::getSetOfInputPort() const
695 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
696 ret.push_back((InputPort *)&_entry);
700 std::list<OutputPort *> LimitNode::getSetOfOutputPort() const
702 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
703 ret.push_back((OutputPort *)&_switchPort);
704 ret.push_back((OutputPort *)&_counterPort);
708 InputPort *LimitNode::getInputPort(const std::string& name) const throw(YACS::Exception)
710 if(name==NAME_FOR_SWPORT)
711 return (InputPort *)&_entry;
713 return ElementaryNode::getInputPort(name);
716 OutputPort *LimitNode::getOutputPort(const std::string& name) const throw(YACS::Exception)
718 if(name==NAME_FOR_SWPORT)
719 return (OutputPort *)&_switchPort;
720 else if(name==NAME_FOR_SWPORT2)
721 return (OutputPort *)&_counterPort;
723 return ElementaryNode::getOutputPort(name);
726 LimitNode::LimitNode(const LimitNode& other, ComposedNode *father):ElementaryNode(other,father),
727 _limit(other._limit),_current(other._limit),
728 _entry(other._entry,this),
729 _switchPort(other._switchPort,this),
730 _counterPort(other._counterPort,this)
734 LimitNode::LimitNode(const string& name):ElementaryNode(name),_limit(0.),_current(0.),
735 _entry(NAME_FOR_SWPORT,this),
736 _switchPort(NAME_FOR_SWPORT,this, Runtime::_tc_bool),
737 _counterPort(NAME_FOR_SWPORT2,this, Runtime::_tc_double)