1 // Copyright (C) 2006-2008 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.
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
19 #include "ToyNode.hxx"
20 #include "TypeCode.hxx"
23 using namespace YACS::ENGINE;
26 char ToyNode::MY_IMPL_NAME[]="TOY";
28 const char ToyNode1S::KIND[]="TESTKIND1";
30 const char ToyNode2S::KIND[]="TESTKIND2";
32 char LimitNode::MY_IMPL_NAME[]="LIMIT";
34 char ToyNode::NAME_FOR_NB[]="NbOfEntries";
36 char SeqToyNode::NAME_NBOFELTS_INSEQ_INPRT[]="NbOfEltsInSeq";
38 char SeqToyNode::NAME_SEQ_OUTPRT[]="MySeq";
40 char Seq2ToyNode::NAME_SEQ_INPRT1[]="SeqIn1";
42 char Seq2ToyNode::NAME_SEQ_INPRT2[]="SeqIn2";
44 char Seq2ToyNode::NAME_SEQ_OUTPRT[]="SeqOut";
46 char Seq3ToyNode::NAME_SEQ_INPRT1[]="SeqIn1";
48 char Seq3ToyNode::NAME_SEQ_INPRT2[]="SeqIn2";
50 char Seq3ToyNode::NAME_SEQ_OUTPRT[]="SeqOut";
52 char LimitNode::NAME_FOR_SWPORT[]="SwitchPort";
54 char LimitNode::NAME_FOR_SWPORT2[]="SwitchPort2";
56 InputToyPort::InputToyPort(const InputToyPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),
60 _data=other._data->clone();
62 _initData=other._initData->clone();
65 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)
69 void InputToyPort::put(const void *data) throw(ConversionException)
74 bool InputToyPort::edIsManuallyInitialized() const
79 void *InputToyPort::get() const throw(Exception)
84 void InputToyPort::edRemoveManInit()
89 InputPort::edRemoveManInit();
92 InputPort *InputToyPort::clone(Node *newHelder) const
94 return new InputToyPort(*this,newHelder);
97 void InputToyPort::put(Any *data)
105 void InputToyPort::exSaveInit()
107 if(_initData) _initData->decrRef();
109 _initData->incrRef();
112 void InputToyPort::exRestoreInit()
114 if(!_initData)return;
115 if(_data) _data->decrRef();
120 InputToyPort::~InputToyPort()
125 _initData->decrRef();
128 OutputToyPort::OutputToyPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
132 OutputToyPort::OutputToyPort(const OutputToyPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),_data(0)
135 _data=other._data->clone();
138 void OutputToyPort::put(const void *data) throw(ConversionException)
141 OutputPort::put(data);
144 OutputPort *OutputToyPort::clone(Node *newHelder) const
146 return new OutputToyPort(*this,newHelder);
149 void OutputToyPort::put(Any *data)
157 OutputToyPort::~OutputToyPort()
163 void OutputToyPort::exInit()
172 ToyNode::ToyNode(const ToyNode& other, ComposedNode *father):ElementaryNode(other,father),_nbOfInputsPort(other._nbOfInputsPort,this)
176 ToyNode::ToyNode(const string& name):ElementaryNode(name),_nbOfInputsPort(NAME_FOR_NB,this,Runtime::_tc_int)
178 _implementation=MY_IMPL_NAME;
181 void ToyNode::execute()
185 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
188 InputToyPort *p=(InputToyPort *) (*iter);
189 d+=p->getAny()->getDoubleValue();
191 int size=_setOfOutputPort.size();
194 Any *tmp=AtomAny::New((int)_setOfInputPort.size());
195 _nbOfInputsPort.put((const void *)tmp);
197 for(list<OutputPort *>::iterator iter2=_setOfOutputPort.begin();iter2!=_setOfOutputPort.end();iter2++)
199 Any *tmp=AtomAny::New(d);
205 std::list<OutputPort *> ToyNode::getSetOfOutputPort() const
207 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
208 ret.push_back((OutputPort *)&_nbOfInputsPort);
212 int ToyNode::getNumberOfOutputPorts() const
214 return ElementaryNode::getNumberOfInputPorts()+1;
217 OutputPort *ToyNode::getOutputPort(const std::string& name) const throw(Exception)
219 if(name==NAME_FOR_NB)
220 return (OutputPort *)&_nbOfInputsPort;
222 return ElementaryNode::getOutputPort(name);
225 Node *ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
227 return new ToyNode(*this,father);
230 ToyNode1S::ToyNode1S(const std::string& name):ServiceNode(name)
234 ToyNode1S::ToyNode1S(const ToyNode1S& other, ComposedNode *father):ServiceNode(other,father)
238 void ToyNode1S::execute()
240 //nothing only to test deployment calculation not for running.
243 std::string ToyNode1S::getKind() const
248 ServiceNode *ToyNode1S::createNode(const std::string& name)
250 ToyNode1S* node=new ToyNode1S(name);
251 node->setComponent(_component);
255 Node *ToyNode1S::simpleClone(ComposedNode *father, bool editionOnly) const
257 return new ToyNode1S(*this,father);
260 ToyNode2S::ToyNode2S(const std::string& name):ServiceNode(name)
264 ToyNode2S::ToyNode2S(const ToyNode2S& other, ComposedNode *father):ServiceNode(other,father)
268 void ToyNode2S::execute()
270 //nothing only to test deployment calculation not for running.
273 std::string ToyNode2S::getKind() const
278 ServiceNode *ToyNode2S::createNode(const std::string& name)
280 ToyNode2S* node=new ToyNode2S(name);
281 node->setComponent(_component);
285 Node *ToyNode2S::simpleClone(ComposedNode *father, bool editionOnly) const
287 return new ToyNode2S(*this,father);
290 void SeqToyNode::execute()
292 int val=_inIntValue.getIntValue();
293 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_double,val);
294 double d=(double) val;
295 for(int i=0;i<val;i++)
297 Any *tmp2=AtomAny::New(d);
298 tmp->setEltAtRank(i,tmp2);
302 _seqOut.put((const void *)tmp);
306 SeqToyNode::SeqToyNode(const SeqToyNode& other, ComposedNode *father):ElementaryNode(other,father),
307 _seqOut(other._seqOut,this),
308 _inIntValue(other._inIntValue,this)
312 SeqToyNode::SeqToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
313 _inIntValue(NAME_NBOFELTS_INSEQ_INPRT,this,Runtime::_tc_int)
315 _implementation=ToyNode::MY_IMPL_NAME;
316 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
317 _seqOut.edSetType(tc);
321 int SeqToyNode::getNumberOfInputPorts() const
323 return ElementaryNode::getNumberOfInputPorts()+1;
326 std::list<InputPort *> SeqToyNode::getSetOfInputPort() const
328 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
329 ret.push_back((InputPort *)&_inIntValue);
333 InputPort *SeqToyNode::getInputPort(const std::string& name) const throw(Exception)
335 if(name==NAME_NBOFELTS_INSEQ_INPRT)
336 return (InputPort *)&_inIntValue;
338 return ElementaryNode::getInputPort(name);
341 int SeqToyNode::getNumberOfOutputPorts() const
343 return ElementaryNode::getNumberOfOutputPorts()+1;
346 std::list<OutputPort *> SeqToyNode::getSetOfOutputPort() const
348 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
349 ret.push_back((OutputPort *)&_seqOut);
353 OutputPort *SeqToyNode::getOutputPort(const std::string& name) const throw(Exception)
355 if(name==NAME_SEQ_OUTPRT)
356 return (OutputPort *)&_seqOut;
358 return ElementaryNode::getOutputPort(name);
361 Node *SeqToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
363 return new SeqToyNode(*this,father);
366 void Seq2ToyNode::execute()
368 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
369 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
370 int val=vals1->size();
371 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_int,val);
372 for(int i=0;i<val;i++)
374 Any *tmp2=AtomAny::New((int)((*vals1)[i]->getDoubleValue()+(*vals2)[i]->getDoubleValue()));
375 tmp->setEltAtRank(i,tmp2);
378 _seqOut.put((const void *)tmp);
382 Seq2ToyNode::Seq2ToyNode(const Seq2ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
383 _seqOut(other._seqOut,this),
384 _inValue1(other._inValue1,this),
385 _inValue2(other._inValue1,this)
389 Seq2ToyNode::Seq2ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
390 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
391 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
393 _implementation=ToyNode::MY_IMPL_NAME;
394 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
395 _inValue1.edSetType(tc);
396 _inValue2.edSetType(tc);
398 tc=new TypeCodeSeq("","",Runtime::_tc_int);
399 _seqOut.edSetType(tc);
403 int Seq2ToyNode::getNumberOfInputPorts() const
405 return ElementaryNode::getNumberOfOutputPorts()+2;
408 std::list<InputPort *> Seq2ToyNode::getSetOfInputPort() const
410 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
411 ret.push_back((InputPort *)&_inValue1);
412 ret.push_back((InputPort *)&_inValue2);
416 InputPort *Seq2ToyNode::getInputPort(const std::string& name) const throw(Exception)
418 if(name==NAME_SEQ_INPRT1)
419 return (InputPort *)&_inValue1;
420 else if(name==NAME_SEQ_INPRT2)
421 return (InputPort *)&_inValue2;
423 return ElementaryNode::getInputPort(name);
426 int Seq2ToyNode::getNumberOfOutputPorts() const
428 return ElementaryNode::getNumberOfOutputPorts()+1;
431 std::list<OutputPort *> Seq2ToyNode::getSetOfOutputPort() const
433 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
434 ret.push_back((OutputPort *)&_seqOut);
438 OutputPort *Seq2ToyNode::getOutputPort(const std::string& name) const throw(Exception)
440 if(name==NAME_SEQ_OUTPRT)
441 return (OutputPort *)&_seqOut;
443 return ElementaryNode::getOutputPort(name);
446 Node *Seq2ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
448 return new Seq2ToyNode(*this,father);
451 void Seq3ToyNode::execute()
453 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
454 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
455 int val=vals1->size();
456 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_int);
457 SequenceAny *tmp=SequenceAny::New(tc1,val);
459 for(int i=0;i<val;i++)
461 Any *anyTemp=(Any *)(*vals1)[i];
462 SequenceAny *anyTemp2=(SequenceAny *)anyTemp;
463 int val2=anyTemp2->size();
464 SequenceAny *tmp2=SequenceAny::New(Runtime::_tc_int,val2);
465 for(int j=0;j<val2;j++)
467 Any *tmp3=AtomAny::New((int)((*vals1)[i][j]->getDoubleValue()+(*vals2)[i][j]->getDoubleValue()));
468 tmp2->setEltAtRank(j,tmp3);
471 tmp->setEltAtRank(i,tmp2);
474 _seqOut.put((const void *)tmp);
478 Seq3ToyNode::Seq3ToyNode(const Seq3ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
479 _seqOut(other._seqOut,this),
480 _inValue1(other._inValue1,this),
481 _inValue2(other._inValue1,this)
485 Seq3ToyNode::Seq3ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
486 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
487 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
489 _implementation=ToyNode::MY_IMPL_NAME;
490 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_double);
491 TypeCodeSeq *tc2=new TypeCodeSeq("","",tc1);
493 _inValue1.edSetType(tc2);
494 _inValue2.edSetType(tc2);
496 tc1=new TypeCodeSeq("","",Runtime::_tc_int);
497 tc2=new TypeCodeSeq("","",tc1);
499 _seqOut.edSetType(tc2);
503 int Seq3ToyNode::getNumberOfInputPorts() const
505 return ElementaryNode::getNumberOfOutputPorts()+2;
508 std::list<InputPort *> Seq3ToyNode::getSetOfInputPort() const
510 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
511 ret.push_back((InputPort *)&_inValue1);
512 ret.push_back((InputPort *)&_inValue2);
516 InputPort *Seq3ToyNode::getInputPort(const std::string& name) const throw(Exception)
518 if(name==NAME_SEQ_INPRT1)
519 return (InputPort *)&_inValue1;
520 else if(name==NAME_SEQ_INPRT2)
521 return (InputPort *)&_inValue2;
523 return ElementaryNode::getInputPort(name);
526 int Seq3ToyNode::getNumberOfOutputPorts() const
528 return ElementaryNode::getNumberOfOutputPorts()+1;
531 std::list<OutputPort *> Seq3ToyNode::getSetOfOutputPort() const
533 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
534 ret.push_back((OutputPort *)&_seqOut);
538 OutputPort *Seq3ToyNode::getOutputPort(const std::string& name) const throw(Exception)
540 if(name==NAME_SEQ_OUTPRT)
541 return (OutputPort *)&_seqOut;
543 return ElementaryNode::getOutputPort(name);
546 Node *Seq3ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
548 return new Seq3ToyNode(*this,father);
551 InputLimitPort::InputLimitPort(const InputLimitPort& other, Node *newHelder):InputPort(other,newHelder),
552 DataPort(other,newHelder),Port(other,newHelder),
553 _data(0),_initData(0)
556 _data=other._data->clone();
558 _initData=other._initData->clone();
561 InputLimitPort::InputLimitPort(const string& name, Node *node)
562 :InputPort(name, node, Runtime::_tc_double),
563 DataPort(name, node, Runtime::_tc_double),
564 Port(node),_data(0),_initData(0)
568 void InputLimitPort::put(const void *data) throw(ConversionException)
573 InputPort *InputLimitPort::clone(Node *newHelder) const
575 return new InputLimitPort(*this,newHelder);
578 bool InputLimitPort::edIsManuallyInitialized() const
583 void *InputLimitPort::get() const throw(Exception)
587 string what="InputLimitPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
588 throw Exception(what);
590 return (void *)_data;
593 void InputLimitPort::edRemoveManInit()
596 _initData->decrRef();
598 InputPort::edRemoveManInit();
601 void InputLimitPort::put(Any *data)
609 void InputLimitPort::exSaveInit()
611 if(_initData) _initData->decrRef();
613 _initData->incrRef();
616 void InputLimitPort::exRestoreInit()
618 if(!_initData)return;
619 if(_data) _data->decrRef();
624 InputLimitPort::~InputLimitPort()
629 _initData->decrRef();
632 OutputLimitPort::OutputLimitPort(const OutputLimitPort& other, Node *newHelder):OutputPort(other,newHelder),
633 DataPort(other,newHelder),Port(other,newHelder),_data(0)
636 _data=other._data->clone();
639 OutputLimitPort::OutputLimitPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
643 void OutputLimitPort::put(const void *data) throw(ConversionException)
646 OutputPort::put(data);
649 OutputPort *OutputLimitPort::clone(Node *newHelder) const
651 return new OutputLimitPort(*this,newHelder);
654 void OutputLimitPort::put(Any *data)
662 OutputLimitPort::~OutputLimitPort()
668 void LimitNode::init(bool start)
675 void LimitNode::execute()
677 _current+=_entry.getAny()->getDoubleValue();
678 Any *tmp=AtomAny::New(_current);
679 _counterPort.put((const void *)tmp);
681 bool verdict=(_current<_limit);
682 tmp=AtomAny::New(verdict);
683 _switchPort.put((const void *)tmp);
687 Node *LimitNode::simpleClone(ComposedNode *father, bool editionOnly) const
689 return new LimitNode(*this,father);
692 std::list<InputPort *> LimitNode::getSetOfInputPort() const
694 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
695 ret.push_back((InputPort *)&_entry);
699 std::list<OutputPort *> LimitNode::getSetOfOutputPort() const
701 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
702 ret.push_back((OutputPort *)&_switchPort);
703 ret.push_back((OutputPort *)&_counterPort);
707 InputPort *LimitNode::getInputPort(const std::string& name) const throw(Exception)
709 if(name==NAME_FOR_SWPORT)
710 return (InputPort *)&_entry;
712 return ElementaryNode::getInputPort(name);
715 OutputPort *LimitNode::getOutputPort(const std::string& name) const throw(Exception)
717 if(name==NAME_FOR_SWPORT)
718 return (OutputPort *)&_switchPort;
719 else if(name==NAME_FOR_SWPORT2)
720 return (OutputPort *)&_counterPort;
722 return ElementaryNode::getOutputPort(name);
725 LimitNode::LimitNode(const LimitNode& other, ComposedNode *father):ElementaryNode(other,father),
726 _limit(other._limit),_current(other._limit),
727 _entry(other._entry,this),
728 _switchPort(other._switchPort,this),
729 _counterPort(other._counterPort,this)
733 LimitNode::LimitNode(const string& name):ElementaryNode(name),_limit(0.),_current(0.),
734 _entry(NAME_FOR_SWPORT,this),
735 _switchPort(NAME_FOR_SWPORT,this, Runtime::_tc_bool),
736 _counterPort(NAME_FOR_SWPORT2,this, Runtime::_tc_double)