Version: 9.16.0
remoteParsers.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 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
27
28namespace YACS
29{
30
31template <class T=YACS::ENGINE::InlineNode*>
33{
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 )
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 )
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
104template <class T>
105void remotetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
106{
107 DEBTRACE( "remotetypeParser::onStart: " << el )
108 std::string element(el);
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
130template <class T> remotetypeParser<T> remotetypeParser<T>::remoteParser; // instanciate static class attribute
131
132} // end of namespace YACS
133
134#endif
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
void setWeight(double elementaryWeight)
Class for calculation node (function) inlined (and executed) in the schema.
Definition: InlineNode.hxx:93
virtual void setFname(const std::string &fname)
Set the function name to use in node execution.
Definition: InlineNode.cxx:69
Class for calculation node (script) inlined (and executed) in the schema.
Definition: InlineNode.hxx:44
virtual void setScript(const std::string &script)
Set the script (as a string) to execute.
Definition: InlineNode.cxx:50
virtual void setContainer(Container *container)
Definition: InlineNode.cxx:105
virtual void setExecutionMode(const std::string &mode)
Definition: InlineNode.cxx:85
const std::string & getName() const
Definition: Node.hxx:125
virtual void exDisabledState()
Notify this node that it has been disabled.
Definition: Node.cxx:232
Base class for all schema objects.
Definition: Proc.hxx:44
std::map< std::string, Container * > containerMap
Definition: Proc.hxx:91
virtual InlineFuncNode * createFuncNode(const std::string &kind, const std::string &name)
Definition: Runtime.cxx:190
virtual InlineNode * createScriptNode(const std::string &kind, const std::string &name)
Definition: Runtime.cxx:195
static std::string t1[]
char XML_Char
Definition: parserBase.hxx:37
YACS::ENGINE::Runtime * theRuntime
Definition: parsers.cxx:40
YACS::ENGINE::Proc * currentProc
Definition: parserBase.cxx:30
Class for code parser in inline nodes.
Definition: codeParsers.hxx:35
static codetypeParser codeParser
Definition: codeParsers.hxx:36
Class for function parser in inline nodes.
Definition: codeParsers.hxx:74
static functypeParser funcParser
Definition: codeParsers.hxx:75
virtual void kind(const std::string &name)
Class for Inport parser.
Definition: portParsers.hxx:49
Class for loading parser.
static loadtypeParser loadParser
virtual void property(const myprop &prop)
Class for Outport parser.
Definition: portParsers.hxx:70
virtual void init()
Definition: parserBase.cxx:86
virtual void pre()
Definition: parserBase.hxx:61
virtual void buildAttr(const XML_Char **attr)
Definition: parserBase.cxx:195
static parser main_parser
Definition: parserBase.hxx:41
Class for property parser.
static propertytypeParser propertyParser
static remotetypeParser< T > remoteParser
virtual void onStart(const XML_Char *el, const XML_Char **attr)
void function(const myfunc &f)
virtual void load(const loadon &l)
virtual void onEnd(const char *el, parser *child)
void script(const myfunc &f)
Class for string parser.
Definition: dataParsers.hxx:32
static stringtypeParser stringParser
Definition: dataParsers.hxx:33
std::string _container
Definition: factory.hxx:122