1 // Copyright (C) 2006-2023 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)
75 bool InputToyPort::edIsManuallyInitialized() const
80 void *InputToyPort::get() const
85 void InputToyPort::edRemoveManInit()
90 InputPort::edRemoveManInit();
93 InputPort *InputToyPort::clone(Node *newHelder) const
95 return new InputToyPort(*this,newHelder);
98 void InputToyPort::releaseData()
105 void InputToyPort::put(Any *data)
107 InputToyPort::releaseData();
112 void InputToyPort::exSaveInit()
114 if(_initData) _initData->decrRef();
116 _initData->incrRef();
119 void InputToyPort::exRestoreInit()
121 if(!_initData)return;
122 if(_data) _data->decrRef();
127 InputToyPort::~InputToyPort()
132 _initData->decrRef();
135 OutputToyPort::OutputToyPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
139 OutputToyPort::OutputToyPort(const OutputToyPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),_data(0)
142 _data=other._data->clone();
145 void OutputToyPort::put(const void *data)
148 OutputPort::put(data);
151 OutputPort *OutputToyPort::clone(Node *newHelder) const
153 return new OutputToyPort(*this,newHelder);
156 void OutputToyPort::put(Any *data)
164 OutputToyPort::~OutputToyPort()
170 void OutputToyPort::exInit()
179 ToyNode::ToyNode(const ToyNode& other, ComposedNode *father):ElementaryNode(other,father),_nbOfInputsPort(other._nbOfInputsPort,this)
183 ToyNode::ToyNode(const string& name):ElementaryNode(name),_nbOfInputsPort(NAME_FOR_NB,this,Runtime::_tc_int)
185 _implementation=MY_IMPL_NAME;
188 void ToyNode::execute()
192 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
195 InputToyPort *p=(InputToyPort *) (*iter);
196 d+=p->getAny()->getDoubleValue();
198 int size=_setOfOutputPort.size();
201 Any *tmp=AtomAny::New((int)_setOfInputPort.size());
202 _nbOfInputsPort.put((const void *)tmp);
204 for(list<OutputPort *>::iterator iter2=_setOfOutputPort.begin();iter2!=_setOfOutputPort.end();iter2++)
206 Any *tmp=AtomAny::New(d);
212 std::list<OutputPort *> ToyNode::getSetOfOutputPort() const
214 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
215 ret.push_back((OutputPort *)&_nbOfInputsPort);
219 int ToyNode::getNumberOfOutputPorts() const
221 return ElementaryNode::getNumberOfInputPorts()+1;
224 OutputPort *ToyNode::getOutputPort(const std::string& name) const
226 if(name==NAME_FOR_NB)
227 return (OutputPort *)&_nbOfInputsPort;
229 return ElementaryNode::getOutputPort(name);
232 Node *ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
234 return new ToyNode(*this,father);
237 ToyNode1S::ToyNode1S(const std::string& name):ServiceNode(name)
241 ToyNode1S::ToyNode1S(const ToyNode1S& other, ComposedNode *father):ServiceNode(other,father)
245 void ToyNode1S::execute()
247 //nothing only to test deployment calculation not for running.
250 std::string ToyNode1S::getKind() const
255 ServiceNode *ToyNode1S::createNode(const std::string& name)
257 ToyNode1S* node=new ToyNode1S(name);
258 node->setComponent(_component);
262 Node *ToyNode1S::simpleClone(ComposedNode *father, bool editionOnly) const
264 return new ToyNode1S(*this,father);
267 ToyNode2S::ToyNode2S(const std::string& name):ServiceNode(name)
271 ToyNode2S::ToyNode2S(const ToyNode2S& other, ComposedNode *father):ServiceNode(other,father)
275 void ToyNode2S::execute()
277 //nothing only to test deployment calculation not for running.
280 std::string ToyNode2S::getKind() const
285 ServiceNode *ToyNode2S::createNode(const std::string& name)
287 ToyNode2S* node=new ToyNode2S(name);
288 node->setComponent(_component);
292 Node *ToyNode2S::simpleClone(ComposedNode *father, bool editionOnly) const
294 return new ToyNode2S(*this,father);
297 void SeqToyNode::execute()
299 int val=_inIntValue.getIntValue();
300 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_double,val);
301 double d=(double) val;
302 for(int i=0;i<val;i++)
304 Any *tmp2=AtomAny::New(d);
305 tmp->setEltAtRank(i,tmp2);
309 _seqOut.put((const void *)tmp);
313 SeqToyNode::SeqToyNode(const SeqToyNode& other, ComposedNode *father):ElementaryNode(other,father),
314 _seqOut(other._seqOut,this),
315 _inIntValue(other._inIntValue,this)
319 SeqToyNode::SeqToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
320 _inIntValue(NAME_NBOFELTS_INSEQ_INPRT,this,Runtime::_tc_int)
322 _implementation=ToyNode::MY_IMPL_NAME;
323 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
324 _seqOut.edSetType(tc);
328 int SeqToyNode::getNumberOfInputPorts() const
330 return ElementaryNode::getNumberOfInputPorts()+1;
333 std::list<InputPort *> SeqToyNode::getSetOfInputPort() const
335 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
336 ret.push_back((InputPort *)&_inIntValue);
340 InputPort *SeqToyNode::getInputPort(const std::string& name) const
342 if(name==NAME_NBOFELTS_INSEQ_INPRT)
343 return (InputPort *)&_inIntValue;
345 return ElementaryNode::getInputPort(name);
348 int SeqToyNode::getNumberOfOutputPorts() const
350 return ElementaryNode::getNumberOfOutputPorts()+1;
353 std::list<OutputPort *> SeqToyNode::getSetOfOutputPort() const
355 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
356 ret.push_back((OutputPort *)&_seqOut);
360 OutputPort *SeqToyNode::getOutputPort(const std::string& name) const
362 if(name==NAME_SEQ_OUTPRT)
363 return (OutputPort *)&_seqOut;
365 return ElementaryNode::getOutputPort(name);
368 Node *SeqToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
370 return new SeqToyNode(*this,father);
373 void Seq2ToyNode::execute()
375 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
376 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
377 int val=vals1->size();
378 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_int,val);
379 for(int i=0;i<val;i++)
381 Any *tmp2=AtomAny::New((int)((*vals1)[i]->getDoubleValue()+(*vals2)[i]->getDoubleValue()));
382 tmp->setEltAtRank(i,tmp2);
385 _seqOut.put((const void *)tmp);
389 Seq2ToyNode::Seq2ToyNode(const Seq2ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
390 _seqOut(other._seqOut,this),
391 _inValue1(other._inValue1,this),
392 _inValue2(other._inValue1,this)
396 Seq2ToyNode::Seq2ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
397 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
398 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
400 _implementation=ToyNode::MY_IMPL_NAME;
401 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
402 _inValue1.edSetType(tc);
403 _inValue2.edSetType(tc);
405 tc=new TypeCodeSeq("","",Runtime::_tc_int);
406 _seqOut.edSetType(tc);
410 int Seq2ToyNode::getNumberOfInputPorts() const
412 return ElementaryNode::getNumberOfOutputPorts()+2;
415 std::list<InputPort *> Seq2ToyNode::getSetOfInputPort() const
417 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
418 ret.push_back((InputPort *)&_inValue1);
419 ret.push_back((InputPort *)&_inValue2);
423 InputPort *Seq2ToyNode::getInputPort(const std::string& name) const
425 if(name==NAME_SEQ_INPRT1)
426 return (InputPort *)&_inValue1;
427 else if(name==NAME_SEQ_INPRT2)
428 return (InputPort *)&_inValue2;
430 return ElementaryNode::getInputPort(name);
433 int Seq2ToyNode::getNumberOfOutputPorts() const
435 return ElementaryNode::getNumberOfOutputPorts()+1;
438 std::list<OutputPort *> Seq2ToyNode::getSetOfOutputPort() const
440 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
441 ret.push_back((OutputPort *)&_seqOut);
445 OutputPort *Seq2ToyNode::getOutputPort(const std::string& name) const
447 if(name==NAME_SEQ_OUTPRT)
448 return (OutputPort *)&_seqOut;
450 return ElementaryNode::getOutputPort(name);
453 Node *Seq2ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
455 return new Seq2ToyNode(*this,father);
458 void Seq3ToyNode::execute()
460 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
461 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
462 int val=vals1->size();
463 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_int);
464 SequenceAny *tmp=SequenceAny::New(tc1,val);
466 for(int i=0;i<val;i++)
468 Any *anyTemp=(Any *)(*vals1)[i];
469 SequenceAny *anyTemp2=(SequenceAny *)anyTemp;
470 int val2=anyTemp2->size();
471 SequenceAny *tmp2=SequenceAny::New(Runtime::_tc_int,val2);
472 for(int j=0;j<val2;j++)
474 Any *tmp3=AtomAny::New((int)((*vals1)[i][j]->getDoubleValue()+(*vals2)[i][j]->getDoubleValue()));
475 tmp2->setEltAtRank(j,tmp3);
478 tmp->setEltAtRank(i,tmp2);
481 _seqOut.put((const void *)tmp);
485 Seq3ToyNode::Seq3ToyNode(const Seq3ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
486 _seqOut(other._seqOut,this),
487 _inValue1(other._inValue1,this),
488 _inValue2(other._inValue1,this)
492 Seq3ToyNode::Seq3ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
493 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
494 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
496 _implementation=ToyNode::MY_IMPL_NAME;
497 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_double);
498 TypeCodeSeq *tc2=new TypeCodeSeq("","",tc1);
500 _inValue1.edSetType(tc2);
501 _inValue2.edSetType(tc2);
503 tc1=new TypeCodeSeq("","",Runtime::_tc_int);
504 tc2=new TypeCodeSeq("","",tc1);
506 _seqOut.edSetType(tc2);
510 int Seq3ToyNode::getNumberOfInputPorts() const
512 return ElementaryNode::getNumberOfOutputPorts()+2;
515 std::list<InputPort *> Seq3ToyNode::getSetOfInputPort() const
517 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
518 ret.push_back((InputPort *)&_inValue1);
519 ret.push_back((InputPort *)&_inValue2);
523 InputPort *Seq3ToyNode::getInputPort(const std::string& name) const
525 if(name==NAME_SEQ_INPRT1)
526 return (InputPort *)&_inValue1;
527 else if(name==NAME_SEQ_INPRT2)
528 return (InputPort *)&_inValue2;
530 return ElementaryNode::getInputPort(name);
533 int Seq3ToyNode::getNumberOfOutputPorts() const
535 return ElementaryNode::getNumberOfOutputPorts()+1;
538 std::list<OutputPort *> Seq3ToyNode::getSetOfOutputPort() const
540 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
541 ret.push_back((OutputPort *)&_seqOut);
545 OutputPort *Seq3ToyNode::getOutputPort(const std::string& name) const
547 if(name==NAME_SEQ_OUTPRT)
548 return (OutputPort *)&_seqOut;
550 return ElementaryNode::getOutputPort(name);
553 Node *Seq3ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
555 return new Seq3ToyNode(*this,father);
558 InputLimitPort::InputLimitPort(const InputLimitPort& other, Node *newHelder):InputPort(other,newHelder),
559 DataPort(other,newHelder),Port(other,newHelder),
560 _data(0),_initData(0)
563 _data=other._data->clone();
565 _initData=other._initData->clone();
568 InputLimitPort::InputLimitPort(const string& name, Node *node)
569 :InputPort(name, node, Runtime::_tc_double),
570 DataPort(name, node, Runtime::_tc_double),
571 Port(node),_data(0),_initData(0)
575 void InputLimitPort::put(const void *data)
580 InputPort *InputLimitPort::clone(Node *newHelder) const
582 return new InputLimitPort(*this,newHelder);
585 bool InputLimitPort::edIsManuallyInitialized() const
590 void *InputLimitPort::get() const
594 string what="InputLimitPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
595 throw Exception(what);
597 return (void *)_data;
600 void InputLimitPort::edRemoveManInit()
603 _initData->decrRef();
605 InputPort::edRemoveManInit();
608 void InputLimitPort::releaseData()
615 void InputLimitPort::put(Any *data)
617 InputLimitPort::releaseData();
622 void InputLimitPort::exSaveInit()
624 if(_initData) _initData->decrRef();
626 _initData->incrRef();
629 void InputLimitPort::exRestoreInit()
631 if(!_initData)return;
632 if(_data) _data->decrRef();
637 InputLimitPort::~InputLimitPort()
642 _initData->decrRef();
645 OutputLimitPort::OutputLimitPort(const OutputLimitPort& other, Node *newHelder):OutputPort(other,newHelder),
646 DataPort(other,newHelder),Port(other,newHelder),_data(0)
649 _data=other._data->clone();
652 OutputLimitPort::OutputLimitPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
656 void OutputLimitPort::put(const void *data)
659 OutputPort::put(data);
662 OutputPort *OutputLimitPort::clone(Node *newHelder) const
664 return new OutputLimitPort(*this,newHelder);
667 void OutputLimitPort::put(Any *data)
675 OutputLimitPort::~OutputLimitPort()
681 void LimitNode::init(bool start)
688 void LimitNode::execute()
690 _current+=_entry.getAny()->getDoubleValue();
691 Any *tmp=AtomAny::New(_current);
692 _counterPort.put((const void *)tmp);
694 bool verdict=(_current<_limit);
695 tmp=AtomAny::New(verdict);
696 _switchPort.put((const void *)tmp);
700 Node *LimitNode::simpleClone(ComposedNode *father, bool editionOnly) const
702 return new LimitNode(*this,father);
705 std::list<InputPort *> LimitNode::getSetOfInputPort() const
707 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
708 ret.push_back((InputPort *)&_entry);
712 std::list<OutputPort *> LimitNode::getSetOfOutputPort() const
714 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
715 ret.push_back((OutputPort *)&_switchPort);
716 ret.push_back((OutputPort *)&_counterPort);
720 InputPort *LimitNode::getInputPort(const std::string& name) const
722 if(name==NAME_FOR_SWPORT)
723 return (InputPort *)&_entry;
725 return ElementaryNode::getInputPort(name);
728 OutputPort *LimitNode::getOutputPort(const std::string& name) const
730 if(name==NAME_FOR_SWPORT)
731 return (OutputPort *)&_switchPort;
732 else if(name==NAME_FOR_SWPORT2)
733 return (OutputPort *)&_counterPort;
735 return ElementaryNode::getOutputPort(name);
738 LimitNode::LimitNode(const LimitNode& other, ComposedNode *father):ElementaryNode(other,father),
739 _limit(other._limit),_current(other._limit),
740 _entry(other._entry,this),
741 _switchPort(other._switchPort,this),
742 _counterPort(other._counterPort,this)
746 LimitNode::LimitNode(const string& name):ElementaryNode(name),_limit(0.),_current(0.),
747 _entry(NAME_FOR_SWPORT,this),
748 _switchPort(NAME_FOR_SWPORT,this, Runtime::_tc_bool),
749 _counterPort(NAME_FOR_SWPORT2,this, Runtime::_tc_double)