2 #include "TypeCode.hxx"
5 using namespace YACS::ENGINE;
8 char ToyNode::MY_IMPL_NAME[]="TOY";
10 const char ToyNode1S::KIND[]="TESTKIND1";
12 const char ToyNode2S::KIND[]="TESTKIND2";
14 char LimitNode::MY_IMPL_NAME[]="LIMIT";
16 char ToyNode::NAME_FOR_NB[]="NbOfEntries";
18 char SeqToyNode::NAME_NBOFELTS_INSEQ_INPRT[]="NbOfEltsInSeq";
20 char SeqToyNode::NAME_SEQ_OUTPRT[]="MySeq";
22 char Seq2ToyNode::NAME_SEQ_INPRT1[]="SeqIn1";
24 char Seq2ToyNode::NAME_SEQ_INPRT2[]="SeqIn2";
26 char Seq2ToyNode::NAME_SEQ_OUTPRT[]="SeqOut";
28 char Seq3ToyNode::NAME_SEQ_INPRT1[]="SeqIn1";
30 char Seq3ToyNode::NAME_SEQ_INPRT2[]="SeqIn2";
32 char Seq3ToyNode::NAME_SEQ_OUTPRT[]="SeqOut";
34 char LimitNode::NAME_FOR_SWPORT[]="SwitchPort";
36 char LimitNode::NAME_FOR_SWPORT2[]="SwitchPort2";
38 InputToyPort::InputToyPort(const InputToyPort& other, Node *newHelder):InputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),
42 _data=other._data->clone();
44 _initData=other._initData->clone();
47 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)
51 void InputToyPort::put(const void *data) throw(ConversionException)
56 bool InputToyPort::edIsManuallyInitialized() const
61 void *InputToyPort::get() const throw(Exception)
66 void InputToyPort::edRemoveManInit()
71 InputPort::edRemoveManInit();
74 InputPort *InputToyPort::clone(Node *newHelder) const
76 return new InputToyPort(*this,newHelder);
79 void InputToyPort::put(Any *data)
87 void InputToyPort::exSaveInit()
89 if(_initData) _initData->decrRef();
94 void InputToyPort::exRestoreInit()
97 if(_data) _data->decrRef();
102 InputToyPort::~InputToyPort()
107 _initData->decrRef();
110 OutputToyPort::OutputToyPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
114 OutputToyPort::OutputToyPort(const OutputToyPort& other, Node *newHelder):OutputPort(other,newHelder),DataPort(other,newHelder),Port(other,newHelder),_data(0)
117 _data=other._data->clone();
120 void OutputToyPort::put(const void *data) throw(ConversionException)
123 OutputPort::put(data);
126 OutputPort *OutputToyPort::clone(Node *newHelder) const
128 return new OutputToyPort(*this,newHelder);
131 void OutputToyPort::put(Any *data)
139 OutputToyPort::~OutputToyPort()
145 void OutputToyPort::exInit()
154 ToyNode::ToyNode(const ToyNode& other, ComposedNode *father):ElementaryNode(other,father),_nbOfInputsPort(other._nbOfInputsPort,this)
158 ToyNode::ToyNode(const string& name):ElementaryNode(name),_nbOfInputsPort(NAME_FOR_NB,this,Runtime::_tc_int)
160 _implementation=MY_IMPL_NAME;
163 void ToyNode::execute()
167 for(list<InputPort *>::iterator iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
170 InputToyPort *p=(InputToyPort *) (*iter);
171 d+=p->getAny()->getDoubleValue();
173 int size=_setOfOutputPort.size();
176 Any *tmp=AtomAny::New((int)_setOfInputPort.size());
177 _nbOfInputsPort.put((const void *)tmp);
179 for(list<OutputPort *>::iterator iter2=_setOfOutputPort.begin();iter2!=_setOfOutputPort.end();iter2++)
181 Any *tmp=AtomAny::New(d);
187 std::list<OutputPort *> ToyNode::getSetOfOutputPort() const
189 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
190 ret.push_back((OutputPort *)&_nbOfInputsPort);
194 int ToyNode::getNumberOfOutputPorts() const
196 return ElementaryNode::getNumberOfInputPorts()+1;
199 OutputPort *ToyNode::getOutputPort(const std::string& name) const throw(Exception)
201 if(name==NAME_FOR_NB)
202 return (OutputPort *)&_nbOfInputsPort;
204 return ElementaryNode::getOutputPort(name);
207 Node *ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
209 return new ToyNode(*this,father);
212 ToyNode1S::ToyNode1S(const std::string& name):ServiceNode(name)
216 ToyNode1S::ToyNode1S(const ToyNode1S& other, ComposedNode *father):ServiceNode(other,father)
220 void ToyNode1S::execute()
222 //nothing only to test deployment calculation not for running.
225 std::string ToyNode1S::getKind() const
230 ServiceNode *ToyNode1S::createNode(const std::string& name)
232 ToyNode1S* node=new ToyNode1S(name);
233 node->setComponent(_component);
237 Node *ToyNode1S::simpleClone(ComposedNode *father, bool editionOnly) const
239 return new ToyNode1S(*this,father);
242 ToyNode2S::ToyNode2S(const std::string& name):ServiceNode(name)
246 ToyNode2S::ToyNode2S(const ToyNode2S& other, ComposedNode *father):ServiceNode(other,father)
250 void ToyNode2S::execute()
252 //nothing only to test deployment calculation not for running.
255 std::string ToyNode2S::getKind() const
260 ServiceNode *ToyNode2S::createNode(const std::string& name)
262 ToyNode2S* node=new ToyNode2S(name);
263 node->setComponent(_component);
267 Node *ToyNode2S::simpleClone(ComposedNode *father, bool editionOnly) const
269 return new ToyNode2S(*this,father);
272 void SeqToyNode::execute()
274 int val=_inIntValue.getIntValue();
275 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_double,val);
276 double d=(double) val;
277 for(int i=0;i<val;i++)
279 Any *tmp2=AtomAny::New(d);
280 tmp->setEltAtRank(i,tmp2);
284 _seqOut.put((const void *)tmp);
288 SeqToyNode::SeqToyNode(const SeqToyNode& other, ComposedNode *father):ElementaryNode(other,father),
289 _seqOut(other._seqOut,this),
290 _inIntValue(other._inIntValue,this)
294 SeqToyNode::SeqToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
295 _inIntValue(NAME_NBOFELTS_INSEQ_INPRT,this,Runtime::_tc_int)
297 _implementation=ToyNode::MY_IMPL_NAME;
298 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
299 _seqOut.edSetType(tc);
303 int SeqToyNode::getNumberOfInputPorts() const
305 return ElementaryNode::getNumberOfInputPorts()+1;
308 std::list<InputPort *> SeqToyNode::getSetOfInputPort() const
310 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
311 ret.push_back((InputPort *)&_inIntValue);
315 InputPort *SeqToyNode::getInputPort(const std::string& name) const throw(Exception)
317 if(name==NAME_NBOFELTS_INSEQ_INPRT)
318 return (InputPort *)&_inIntValue;
320 return ElementaryNode::getInputPort(name);
323 int SeqToyNode::getNumberOfOutputPorts() const
325 return ElementaryNode::getNumberOfOutputPorts()+1;
328 std::list<OutputPort *> SeqToyNode::getSetOfOutputPort() const
330 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
331 ret.push_back((OutputPort *)&_seqOut);
335 OutputPort *SeqToyNode::getOutputPort(const std::string& name) const throw(Exception)
337 if(name==NAME_SEQ_OUTPRT)
338 return (OutputPort *)&_seqOut;
340 return ElementaryNode::getOutputPort(name);
343 Node *SeqToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
345 return new SeqToyNode(*this,father);
348 void Seq2ToyNode::execute()
350 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
351 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
352 int val=vals1->size();
353 SequenceAny *tmp=SequenceAny::New(Runtime::_tc_int,val);
354 for(int i=0;i<val;i++)
356 Any *tmp2=AtomAny::New((int)((*vals1)[i]->getDoubleValue()+(*vals2)[i]->getDoubleValue()));
357 tmp->setEltAtRank(i,tmp2);
360 _seqOut.put((const void *)tmp);
364 Seq2ToyNode::Seq2ToyNode(const Seq2ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
365 _seqOut(other._seqOut,this),
366 _inValue1(other._inValue1,this),
367 _inValue2(other._inValue1,this)
371 Seq2ToyNode::Seq2ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
372 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
373 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
375 _implementation=ToyNode::MY_IMPL_NAME;
376 TypeCodeSeq *tc=new TypeCodeSeq("","",Runtime::_tc_double);
377 _inValue1.edSetType(tc);
378 _inValue2.edSetType(tc);
380 tc=new TypeCodeSeq("","",Runtime::_tc_int);
381 _seqOut.edSetType(tc);
385 int Seq2ToyNode::getNumberOfInputPorts() const
387 return ElementaryNode::getNumberOfOutputPorts()+2;
390 std::list<InputPort *> Seq2ToyNode::getSetOfInputPort() const
392 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
393 ret.push_back((InputPort *)&_inValue1);
394 ret.push_back((InputPort *)&_inValue2);
398 InputPort *Seq2ToyNode::getInputPort(const std::string& name) const throw(Exception)
400 if(name==NAME_SEQ_INPRT1)
401 return (InputPort *)&_inValue1;
402 else if(name==NAME_SEQ_INPRT2)
403 return (InputPort *)&_inValue2;
405 return ElementaryNode::getInputPort(name);
408 int Seq2ToyNode::getNumberOfOutputPorts() const
410 return ElementaryNode::getNumberOfOutputPorts()+1;
413 std::list<OutputPort *> Seq2ToyNode::getSetOfOutputPort() const
415 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
416 ret.push_back((OutputPort *)&_seqOut);
420 OutputPort *Seq2ToyNode::getOutputPort(const std::string& name) const throw(Exception)
422 if(name==NAME_SEQ_OUTPRT)
423 return (OutputPort *)&_seqOut;
425 return ElementaryNode::getOutputPort(name);
428 Node *Seq2ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
430 return new Seq2ToyNode(*this,father);
433 void Seq3ToyNode::execute()
435 SequenceAny *vals1=(SequenceAny *)_inValue1.getValue();
436 SequenceAny *vals2=(SequenceAny *)_inValue2.getValue();
437 int val=vals1->size();
438 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_int);
439 SequenceAny *tmp=SequenceAny::New(tc1,val);
441 for(int i=0;i<val;i++)
443 Any *anyTemp=(Any *)(*vals1)[i];
444 SequenceAny *anyTemp2=(SequenceAny *)anyTemp;
445 int val2=anyTemp2->size();
446 SequenceAny *tmp2=SequenceAny::New(Runtime::_tc_int,val2);
447 for(int j=0;j<val2;j++)
449 Any *tmp3=AtomAny::New((int)((*vals1)[i][j]->getDoubleValue()+(*vals2)[i][j]->getDoubleValue()));
450 tmp2->setEltAtRank(j,tmp3);
453 tmp->setEltAtRank(i,tmp2);
456 _seqOut.put((const void *)tmp);
460 Seq3ToyNode::Seq3ToyNode(const Seq3ToyNode& other, ComposedNode *father):ElementaryNode(other,father),
461 _seqOut(other._seqOut,this),
462 _inValue1(other._inValue1,this),
463 _inValue2(other._inValue1,this)
467 Seq3ToyNode::Seq3ToyNode(const std::string& name):ElementaryNode(name),_seqOut(NAME_SEQ_OUTPRT,this,Runtime::_tc_double),
468 _inValue1(NAME_SEQ_INPRT1,this,Runtime::_tc_int),
469 _inValue2(NAME_SEQ_INPRT2,this,Runtime::_tc_int)
471 _implementation=ToyNode::MY_IMPL_NAME;
472 TypeCodeSeq *tc1=new TypeCodeSeq("","",Runtime::_tc_double);
473 TypeCodeSeq *tc2=new TypeCodeSeq("","",tc1);
475 _inValue1.edSetType(tc2);
476 _inValue2.edSetType(tc2);
478 tc1=new TypeCodeSeq("","",Runtime::_tc_int);
479 tc2=new TypeCodeSeq("","",tc1);
481 _seqOut.edSetType(tc2);
485 int Seq3ToyNode::getNumberOfInputPorts() const
487 return ElementaryNode::getNumberOfOutputPorts()+2;
490 std::list<InputPort *> Seq3ToyNode::getSetOfInputPort() const
492 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
493 ret.push_back((InputPort *)&_inValue1);
494 ret.push_back((InputPort *)&_inValue2);
498 InputPort *Seq3ToyNode::getInputPort(const std::string& name) const throw(Exception)
500 if(name==NAME_SEQ_INPRT1)
501 return (InputPort *)&_inValue1;
502 else if(name==NAME_SEQ_INPRT2)
503 return (InputPort *)&_inValue2;
505 return ElementaryNode::getInputPort(name);
508 int Seq3ToyNode::getNumberOfOutputPorts() const
510 return ElementaryNode::getNumberOfOutputPorts()+1;
513 std::list<OutputPort *> Seq3ToyNode::getSetOfOutputPort() const
515 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
516 ret.push_back((OutputPort *)&_seqOut);
520 OutputPort *Seq3ToyNode::getOutputPort(const std::string& name) const throw(Exception)
522 if(name==NAME_SEQ_OUTPRT)
523 return (OutputPort *)&_seqOut;
525 return ElementaryNode::getOutputPort(name);
528 Node *Seq3ToyNode::simpleClone(ComposedNode *father, bool editionOnly) const
530 return new Seq3ToyNode(*this,father);
533 InputLimitPort::InputLimitPort(const InputLimitPort& other, Node *newHelder):InputPort(other,newHelder),
534 DataPort(other,newHelder),Port(other,newHelder),
535 _data(0),_initData(0)
538 _data=other._data->clone();
540 _initData=other._initData->clone();
543 InputLimitPort::InputLimitPort(const string& name, Node *node)
544 :InputPort(name, node, Runtime::_tc_double),
545 DataPort(name, node, Runtime::_tc_double),
546 Port(node),_data(0),_initData(0)
550 void InputLimitPort::put(const void *data) throw(ConversionException)
555 InputPort *InputLimitPort::clone(Node *newHelder) const
557 return new InputLimitPort(*this,newHelder);
560 bool InputLimitPort::edIsManuallyInitialized() const
565 void *InputLimitPort::get() const throw(Exception)
569 string what="InputLimitPort::get : no value currently in input whith name \""; what+=_name; what+="\"";
570 throw Exception(what);
572 return (void *)_data;
575 void InputLimitPort::edRemoveManInit()
578 _initData->decrRef();
580 InputPort::edRemoveManInit();
583 void InputLimitPort::put(Any *data)
591 void InputLimitPort::exSaveInit()
593 if(_initData) _initData->decrRef();
595 _initData->incrRef();
598 void InputLimitPort::exRestoreInit()
600 if(!_initData)return;
601 if(_data) _data->decrRef();
606 InputLimitPort::~InputLimitPort()
611 _initData->decrRef();
614 OutputLimitPort::OutputLimitPort(const OutputLimitPort& other, Node *newHelder):OutputPort(other,newHelder),
615 DataPort(other,newHelder),Port(other,newHelder),_data(0)
618 _data=other._data->clone();
621 OutputLimitPort::OutputLimitPort(const string& name, Node *node, TypeCode *type):OutputPort(name, node, type),DataPort(name, node, type),Port(node),_data(0)
625 void OutputLimitPort::put(const void *data) throw(ConversionException)
628 OutputPort::put(data);
631 OutputPort *OutputLimitPort::clone(Node *newHelder) const
633 return new OutputLimitPort(*this,newHelder);
636 void OutputLimitPort::put(Any *data)
644 OutputLimitPort::~OutputLimitPort()
650 void LimitNode::init(bool start)
657 void LimitNode::execute()
659 _current+=_entry.getAny()->getDoubleValue();
660 Any *tmp=AtomAny::New(_current);
661 _counterPort.put((const void *)tmp);
663 bool verdict=(_current<_limit);
664 tmp=AtomAny::New(verdict);
665 _switchPort.put((const void *)tmp);
669 Node *LimitNode::simpleClone(ComposedNode *father, bool editionOnly) const
671 return new LimitNode(*this,father);
674 std::list<InputPort *> LimitNode::getSetOfInputPort() const
676 list<InputPort *> ret=ElementaryNode::getSetOfInputPort();
677 ret.push_back((InputPort *)&_entry);
681 std::list<OutputPort *> LimitNode::getSetOfOutputPort() const
683 list<OutputPort *> ret=ElementaryNode::getSetOfOutputPort();
684 ret.push_back((OutputPort *)&_switchPort);
685 ret.push_back((OutputPort *)&_counterPort);
689 InputPort *LimitNode::getInputPort(const std::string& name) const throw(Exception)
691 if(name==NAME_FOR_SWPORT)
692 return (InputPort *)&_entry;
694 return ElementaryNode::getInputPort(name);
697 OutputPort *LimitNode::getOutputPort(const std::string& name) const throw(Exception)
699 if(name==NAME_FOR_SWPORT)
700 return (OutputPort *)&_switchPort;
701 else if(name==NAME_FOR_SWPORT2)
702 return (OutputPort *)&_counterPort;
704 return ElementaryNode::getOutputPort(name);
707 LimitNode::LimitNode(const LimitNode& other, ComposedNode *father):ElementaryNode(other,father),
708 _limit(other._limit),_current(other._limit),
709 _entry(other._entry,this),
710 _switchPort(other._switchPort,this),
711 _counterPort(other._counterPort,this)
715 LimitNode::LimitNode(const string& name):ElementaryNode(name),_limit(0.),_current(0.),
716 _entry(NAME_FOR_SWPORT,this),
717 _switchPort(NAME_FOR_SWPORT,this, Runtime::_tc_bool),
718 _counterPort(NAME_FOR_SWPORT2,this, Runtime::_tc_double)