Version: 8.3.0
remoteParsers.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 _REMOTEPARSERS_HXX_
21 #define _REMOTEPARSERS_HXX_
22 
23 #include "inlineParsers.hxx"
24 
27 
28 namespace YACS
29 {
30 
31 template <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  this->_node=fnode;
65  }
66 
67  void script (const myfunc& f)
68  {
69  DEBTRACE( "remote_script: " << f._code )
71  node=theRuntime->createScriptNode(this->_kind,this->_name);
72  node->setScript(f._code);
73  node->setExecutionMode("remote");
74  this->_node=node;
75  }
76 
77  virtual T post()
78  {
79  DEBTRACE( "remote_post " << this->_node->getName() )
80  if(this->_state == "disabled")this->_node->exDisabledState();
81 
82  //set the container
83  if(currentProc->containerMap.count(this->_container) != 0)
84  {
85  // a container with name (this->_container) exists. Use it
86  this->_node->setContainer(currentProc->containerMap[this->_container]);
87  }
88  else if(this->_container == "" && currentProc->containerMap.count("DefaultContainer") != 0)
89  {
90  // a container with name (this->_container) does not exist
91  //a default container is defined : use it
92  this->_node->setContainer(currentProc->containerMap["DefaultContainer"]);
93  }
94  else
95  std::cerr << "WARNING: Unknown container and no DefaultContainer " << this->_container << " will be ignored" << std::endl;
96 
97  return this->_node;
98  }
99 
100 };
101 
102 template <class T>
103 void remotetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
104 {
105  DEBTRACE( "remotetypeParser::onStart: " << el )
106  std::string element(el);
108  this->maxcount("kind",1,element);
109  this->maxcount("function",1,element);
110  this->maxcount("script",1,element);
111  this->maxcount("load",1,element);
112  this->maxchoice(t1,1,element);
113 
114  if(element == "kind")pp=&stringtypeParser::stringParser;
115  else if(element == "load")pp=&loadtypeParser::loadParser;
116  else if(element == "function")pp=&functypeParser::funcParser;
117  else if(element == "script")pp=&codetypeParser::codeParser;
118  else if(element == "property")pp=&propertytypeParser::propertyParser;
119  else if(element == "inport")pp=&inporttypeParser<>::inportParser;
120  else if(element == "outport")pp=&outporttypeParser<>::outportParser;
121 
122  this->SetUserDataAndPush(pp);
123  pp->init();
124  pp->pre();
125  pp->buildAttr(attr);
126 }
127 
128 template <class T> remotetypeParser<T> remotetypeParser<T>::remoteParser; // instanciate static class attribute
129 
130 } // end of namespace YACS
131 
132 #endif