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