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