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