Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / engine / Test / ToyNode.hxx
1 #ifndef __TOYNODE_HXX__
2 #define __TOYNODE_HXX__
3
4 #include "ServiceNode.hxx"
5 #include "AnyInputPort.hxx"
6 #include "OutputPort.hxx"
7 #include "InputPort.hxx"
8 #include "Any.hxx"
9
10 namespace YACS
11 {
12   namespace ENGINE
13   {
14     class InputToyPort : public InputPort
15     {
16     public:
17       InputToyPort(const InputToyPort& other, Node *newHelder);
18       InputToyPort(const std::string& name, Node *node);
19       void put(const void *data) throw(ConversionException);
20       InputPort *clone(Node *newHelder) const;
21       bool edIsManuallyInitialized() const;
22       void *get() const throw(Exception);
23       void edRemoveManInit();
24       void put(Any *data);
25       ~InputToyPort();
26       Any *getAny() { return _data; }
27       void exSaveInit();
28       void exRestoreInit();
29     protected:
30       Any *_data;
31       Any *_initData;
32     };
33
34     class OutputToyPort : public OutputPort
35     {
36     public:
37       OutputToyPort(const std::string& name, Node *node, TypeCode *type);
38       OutputToyPort(const OutputToyPort& other, Node *newHelder);
39       void put(const void *data) throw(ConversionException);
40       OutputPort *clone(Node *newHelder) const;
41       void put(Any *data);
42       ~OutputToyPort();
43       void exInit();
44       Any *get() { return _data; }
45     protected:
46       Any *_data;
47     };
48
49     class ToyNode : public ElementaryNode 
50     {
51     private:
52       OutputToyPort _nbOfInputsPort;
53     public:
54       void execute();
55       ToyNode(const ToyNode& other, ComposedNode *father);
56       ToyNode(const std::string& name);
57       OutputPort *edGetNbOfInputsOutputPort() { return &_nbOfInputsPort; }
58       std::list<OutputPort *> getSetOfOutputPort() const;
59       int getNumberOfOutputPorts()const;
60       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
61     protected:
62       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
63     public:
64       static char NAME_FOR_NB[];
65       static char MY_IMPL_NAME[];
66     };
67
68     class ToyNode1S : public ServiceNode
69     {
70     public:
71       ToyNode1S(const std::string& name);
72       ToyNode1S(const ToyNode1S& other, ComposedNode *father);
73       void execute();
74       std::string getKind() const;
75       ServiceNode *createNode(const std::string& name);
76     protected:
77       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
78     public:
79       static const char KIND[];
80     };
81     
82     class ToyNode2S : public ServiceNode
83     {
84     public:
85       ToyNode2S(const std::string& name);
86       ToyNode2S(const ToyNode2S& other, ComposedNode *father);
87       void execute();
88       std::string getKind() const;
89       ServiceNode *createNode(const std::string& name);
90     protected:
91       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
92     public:
93       static const char KIND[];
94     };
95
96     class SeqToyNode : public ElementaryNode
97     {
98     private:
99       OutputToyPort _seqOut;
100       AnyInputPort _inIntValue;
101     public:
102       void execute();
103       SeqToyNode(const SeqToyNode& other, ComposedNode *father);
104       SeqToyNode(const std::string& name);
105       OutputPort *edGetSeqOut() const { return (OutputPort *)&_seqOut; }
106       InputPort *edGetInIntValue() const { return (InputPort *)&_inIntValue; }
107       int getNumberOfInputPorts() const;
108       std::list<InputPort *> getSetOfInputPort() const;
109       InputPort *getInputPort(const std::string& name) const throw(Exception);
110       int getNumberOfOutputPorts() const;
111       std::list<OutputPort *> getSetOfOutputPort() const;
112       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
113     protected:
114       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
115     public:
116       static char NAME_NBOFELTS_INSEQ_INPRT[];
117       static char NAME_SEQ_OUTPRT[];
118     };
119
120     class Seq2ToyNode : public ElementaryNode
121     {
122       private:
123       OutputToyPort _seqOut;
124       AnyInputPort _inValue1;
125       AnyInputPort _inValue2;
126     public:
127       void execute();
128       Seq2ToyNode(const Seq2ToyNode& other, ComposedNode *father);
129       Seq2ToyNode(const std::string& name);
130       OutputToyPort *edGetSeqOut() const { return (OutputToyPort *)&_seqOut; }
131       InputPort *edGetInValue1() const { return (InputPort *)&_inValue1; }
132       InputPort *edGetInValue2() const { return (InputPort *)&_inValue2; }
133       int getNumberOfInputPorts() const;
134       std::list<InputPort *> getSetOfInputPort() const;
135       InputPort *getInputPort(const std::string& name) const throw(Exception);
136       int getNumberOfOutputPorts() const;
137       std::list<OutputPort *> getSetOfOutputPort() const;
138       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
139     protected:
140       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
141     public:
142       static char NAME_SEQ_INPRT1[];
143       static char NAME_SEQ_INPRT2[];
144       static char NAME_SEQ_OUTPRT[];
145     };
146
147     class Seq3ToyNode : public ElementaryNode
148     {
149       private:
150       OutputToyPort _seqOut;
151       AnyInputPort _inValue1;
152       AnyInputPort _inValue2;
153     public:
154       void execute();
155       Seq3ToyNode(const Seq3ToyNode& other, ComposedNode *father);
156       Seq3ToyNode(const std::string& name);
157       OutputToyPort *edGetSeqOut() const { return (OutputToyPort *)&_seqOut; }
158       InputPort *edGetInValue1() const { return (InputPort *)&_inValue1; }
159       InputPort *edGetInValue2() const { return (InputPort *)&_inValue2; }
160       int getNumberOfInputPorts() const;
161       std::list<InputPort *> getSetOfInputPort() const;
162       InputPort *getInputPort(const std::string& name) const throw(Exception);
163       int getNumberOfOutputPorts() const;
164       std::list<OutputPort *> getSetOfOutputPort() const;
165       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
166     protected:
167       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
168     public:
169       static char NAME_SEQ_INPRT1[];
170       static char NAME_SEQ_INPRT2[];
171       static char NAME_SEQ_OUTPRT[];
172     };
173     
174     class LimitNode;
175
176     class InputLimitPort : public InputPort
177     {
178       friend class LimitNode;
179     public:
180       void put(const void *data) throw(ConversionException);
181       InputPort *clone(Node *newHelder) const;
182       bool edIsManuallyInitialized() const;
183       void *get() const throw(Exception);
184       void edRemoveManInit();
185       void put(Any *data);
186       ~InputLimitPort();
187       Any *getAny() { return _data; }
188       void exSaveInit();
189       void exRestoreInit();
190     private:
191       InputLimitPort(const InputLimitPort& other, Node *newHelder);
192       InputLimitPort(const std::string& name, Node *node);
193     protected:
194       Any *_data;
195       Any *_initData;
196     };
197
198     class OutputLimitPort : public OutputPort
199     {
200       friend class LimitNode;
201     public:
202       void put(const void *data) throw(ConversionException);
203       OutputPort *clone(Node *newHelder) const;
204       void put(Any *data);
205       ~OutputLimitPort();
206       Any *get() { return _data; }
207     private:
208       OutputLimitPort(const OutputLimitPort& other, Node *newHelder);
209       OutputLimitPort(const std::string& name, Node *node, TypeCode *type);
210     protected:
211       Any *_data;
212     };
213
214     class LimitNode : public ElementaryNode
215     {
216     private:
217       double _limit;
218       double _current;
219       InputLimitPort _entry;
220       OutputLimitPort _switchPort;
221       OutputLimitPort _counterPort;
222     public:
223       void init(bool start=true);
224       void execute();
225       void setLimit(double limit) { _limit=limit; }
226       InputPort *getEntry() { return &_entry; }
227       OutputPort *getSwitchPort() { return &_switchPort; }
228       OutputPort *getCounterPort() { return &_counterPort; }
229       std::list<InputPort *> getSetOfInputPort() const;
230       std::list<OutputPort *> getSetOfOutputPort() const;
231       InputPort *getInputPort(const std::string& name) const throw(Exception);
232       OutputPort *getOutputPort(const std::string& name) const throw(Exception);
233       LimitNode(const LimitNode& other, ComposedNode *father);
234       LimitNode(const std::string& name);
235     protected:
236       Node *simpleClone(ComposedNode *father, bool editionOnly) const;
237     public:
238       static char MY_IMPL_NAME[];
239       static char NAME_FOR_SWPORT[];
240       static char NAME_FOR_SWPORT2[];
241     };
242   }
243 }
244
245 #endif