Salome HOME
Updated copyright comment
[modules/yacs.git] / src / yacsloader / remoteParsers.hxx
1 // Copyright (C) 2006-2024  CEA, EDF
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 _REMOTEPARSERS_HXX_
21 #define _REMOTEPARSERS_HXX_
22
23 #include "inlineParsers.hxx"
24
25 extern YACS::ENGINE::Proc* currentProc;
26 extern YACS::ENGINE::Runtime* theRuntime;
27
28 namespace YACS
29 {
30
31 template <class T=YACS::ENGINE::InlineNode*>
32 struct remotetypeParser:public inlinetypeParser<T>
33 {
34   static remotetypeParser<T> remoteParser;
35
36   virtual void onStart(const XML_Char* el, const XML_Char** attr);
37   virtual void onEnd(const char *el,parser* child)
38     {
39       DEBTRACE( "remotetypeParser::onEnd: " << el )             
40       std::string element(el);
41       if(element == "kind")this->kind(((stringtypeParser*)child)->post()); // inherited
42       else if(element == "function")this->function(((functypeParser*)child)->post());
43       else if(element == "script")this->script(((codetypeParser*)child)->post());
44       else if(element == "load") this->load(((loadtypeParser*)child)->post());
45       else if(element == "property")this->property(((propertytypeParser*)child)->post());
46       else if(element == "inport") this->inport(((inporttypeParser<myinport>*)child)->post());
47       else if(element == "outport") this->outport(((outporttypeParser<myoutport>*)child)->post());
48     }
49
50   virtual void load (const loadon& l)
51     {
52       DEBTRACE( "remotenode_load: " << l._container);
53       this->_container=l._container;
54     }
55
56   void function (const myfunc& f)
57     {
58       DEBTRACE( "remote_function: " << f._code )
59       YACS::ENGINE::InlineFuncNode *fnode;
60       fnode=theRuntime->createFuncNode(this->_kind,this->_name);
61       fnode->setScript(f._code);
62       fnode->setFname(f._name);
63       fnode->setExecutionMode("remote");
64       if (this->_weight>0)fnode->setWeight(this->_weight);
65       this->_node=fnode;
66     }
67
68   void script (const myfunc& f)
69     {
70       DEBTRACE( "remote_script: " << f._code )
71       YACS::ENGINE::InlineNode *node;
72       node=theRuntime->createScriptNode(this->_kind,this->_name);
73       node->setScript(f._code);
74       node->setExecutionMode("remote");
75       if (this->_weight>0)node->setWeight(this->_weight);
76       this->_node=node;
77     }
78
79   virtual T post()
80     {
81       DEBTRACE( "remote_post " << this->_node->getName() )
82       if(this->_state == "disabled")this->_node->exDisabledState();
83
84       //set the container
85       if(currentProc->containerMap.count(this->_container) != 0)
86         {
87           // a container with name (this->_container) exists. Use it
88           this->_node->setContainer(currentProc->containerMap[this->_container]);
89         }
90       else if(this->_container == "" && currentProc->containerMap.count("DefaultContainer") != 0)
91         {
92           // a container with name (this->_container) does not exist
93           //a default container is defined : use it
94           this->_node->setContainer(currentProc->containerMap["DefaultContainer"]);
95         }
96       else
97         std::cerr << "WARNING: Unknown container and no DefaultContainer " << this->_container << " will be ignored" << std::endl;
98
99       return this->_node;
100     }
101
102 };
103
104 template <class T>
105 void remotetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
106 {
107   DEBTRACE( "remotetypeParser::onStart: " << el )
108   std::string element(el);
109   parser* pp=&parser::main_parser;
110   this->maxcount("kind",1,element);
111   this->maxcount("function",1,element);
112   this->maxcount("script",1,element);
113   this->maxcount("load",1,element);
114   this->maxchoice(t1,1,element);
115
116   if(element == "kind")pp=&stringtypeParser::stringParser;
117   else if(element == "load")pp=&loadtypeParser::loadParser;
118   else if(element == "function")pp=&functypeParser::funcParser;
119   else if(element == "script")pp=&codetypeParser::codeParser;
120   else if(element == "property")pp=&propertytypeParser::propertyParser;
121   else if(element == "inport")pp=&inporttypeParser<>::inportParser;
122   else if(element == "outport")pp=&outporttypeParser<>::outportParser;
123
124   this->SetUserDataAndPush(pp);
125   pp->init();
126   pp->pre();
127   pp->buildAttr(attr);
128 }
129
130 template <class T> remotetypeParser<T> remotetypeParser<T>::remoteParser; // instanciate static class attribute
131
132 } // end of namespace YACS
133
134 #endif