Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / engine / InlineNode.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 __INLINENODE_HXX__
20 #define __INLINENODE_HXX__
21
22 #include "ElementaryNode.hxx"
23 #include <string>
24
25 namespace YACS
26 {
27   namespace ENGINE
28   {
29 /*! \brief Class for calculation node (script) inlined (and executed) in the schema
30  *
31  * \ingroup Nodes
32  *
33  * This node is like a script. It has no state if it is executed several times.
34  * Each execution the string _script is executed within a clean context.
35  *
36  * \see ServiceNode
37  * \see ElementaryNode
38  */
39     class InlineNode : public ElementaryNode 
40     {
41     protected:
42       InlineNode(const InlineNode& other, ComposedNode *father)
43         :ElementaryNode(other,father),_script(other._script) { }
44       InlineNode(const std::string& name):ElementaryNode(name) { }
45     public:
46 //! Set the script (as a string) to execute
47 /*!
48  * \param script: script to execute
49  */
50       virtual void setScript(const std::string& script) { _script=script; }
51       virtual std::string getScript(){return _script;}
52
53 //! Return a new InlineNode node by making a copy of this node
54 /*!
55  * \param name: name of the new node
56  * \return the new node built by cloning.
57  */
58       virtual InlineNode* cloneNode(const std::string& name)
59       { throw Exception("Not implemented");};
60       virtual void accept(Visitor *visitor);
61       virtual ~InlineNode();
62       virtual std::string typeName() {return "YACS__ENGINE__InlineNode";}
63     protected:
64       std::string _script;
65     };
66
67 /*! \brief Class for calculation node (function) inlined (and executed) in the schema
68  *
69  * \ingroup Nodes
70  *
71  * This node is like a function. It can have a state. The first time the node
72  * is executed, the string _script is executed in a clean context followed by the
73  * execution of the function _fname. Next times, the function _fname is executed 
74  * within the preserved context.
75  *
76  * \see ServiceNode
77  * \see ElementaryNode
78  */
79     class InlineFuncNode : public InlineNode
80     {
81     protected:
82       InlineFuncNode(const InlineFuncNode& other, ComposedNode *father)
83         :InlineNode(other,father),_fname(other._fname) { }
84       InlineFuncNode(const std::string& name):InlineNode(name) { }
85     public:
86 //! Set the function name to use in node execution
87 /*!
88  * \param fname: name of the function contained in the script to execute
89  */
90       virtual void setFname(const std::string& fname) { _fname=fname; }
91       virtual std::string getFname() { return _fname; }
92       void accept(Visitor *visitor);
93       virtual ~InlineFuncNode();
94       virtual std::string typeName() {return "YACS__ENGINE__InlineFuncNode";}
95     protected:
96       std::string _fname;
97     };
98   }
99 }
100
101 #endif