1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _SINLINEPARSERS_HXX_
21 #define _SINLINEPARSERS_HXX_
24 #include "ServiceInlineNode.hxx"
25 #include "Runtime.hxx"
27 extern YACS::ENGINE::Proc* currentProc;
28 extern YACS::ENGINE::Runtime* theRuntime;
33 /*! \brief Class for parsing ServiceInlineNode description
37 template <class T=YACS::ENGINE::ServiceInlineNode*>
38 struct sinlinetypeParser:public inlinetypeParser<T>
40 static sinlinetypeParser<T> sinlineParser;
42 virtual void onStart(const XML_Char* el, const XML_Char** attr);
43 virtual void onEnd(const char *el,parser* child)
45 DEBTRACE( "sinlinetypeParser::onEnd: " << el )
46 std::string element(el);
47 if(element == "kind")this->kind(((stringtypeParser*)child)->post());
48 else if(element == "function")this->function(((functypeParser*)child)->post());
49 else if(element == "load") load(((loadtypeParser*)child)->post());
50 else if(element == "property")this->property(((propertytypeParser*)child)->post());
51 else if(element == "inport") this->inport(((inporttypeParser<myinport>*)child)->post());
52 else if(element == "outport") this->outport(((outporttypeParser<myoutport>*)child)->post());
54 //virtual void service (const myfunc& f) {}
55 virtual void load (const loadon& l)
57 DEBTRACE( "sinline_load: " )
58 this->_container=l._container;
62 DEBTRACE( "sinline_post " << this->_node->getName() );
63 if(this->_state == "disabled")this->_node->exDisabledState();
65 if(!this->_node->getComponent())
66 throw YACS::Exception("A service inline node must have a component instance");
68 // If the component instance has already a container don't go further
69 if(this->_node->getComponent()->getContainer())
72 // Only for anonymous component instance set a container
73 if(this->_node->getComponent()->isAnonymous())
75 if(currentProc->containerMap.count(this->_container) != 0)
76 this->_node->getComponent()->setContainer(currentProc->containerMap[this->_container]);
77 else if(this->_container == "" && currentProc->containerMap.count("DefaultContainer") != 0)
79 //a default container is defined : use it if supported
82 currentProc->containerMap["DefaultContainer"]->checkCapabilityToDealWith(this->_node->getComponent());
83 this->_node->getComponent()->setContainer(currentProc->containerMap["DefaultContainer"]);
85 catch(YACS::Exception){}
88 std::cerr << "WARNING: Unknown container " << this->_container << " ignored" << std::endl;
94 template <class T> sinlinetypeParser<T> sinlinetypeParser<T>::sinlineParser;
98 void inlinetypeParser<YACS::ENGINE::ServiceInlineNode*>::function (const myfunc& f)
100 DEBTRACE( "sinline_function: " << f._code )
101 YACS::ENGINE::ServiceInlineNode *fnode;
102 fnode=theRuntime->createSInlineNode(_kind,_name);
103 fnode->setScript(f._code);
104 fnode->setMethod(f._name);
105 // TODO: update with currentProc->createComponentInstance() method
106 fnode->setComponent(theRuntime->createComponentInstance("PyCompo","SalomePy"));
111 void sinlinetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
113 DEBTRACE( "sinlinetypeParser::onStart: " << el )
114 std::string element(el);
115 parser* pp=&parser::main_parser;
116 this->maxcount("kind",1,element);
117 this->maxcount("function",1,element);
118 this->maxcount("load",1,element);
119 if(element == "kind")pp=&stringtypeParser::stringParser;
120 else if(element == "function")pp=&functypeParser::funcParser;
121 else if(element == "load")pp=&loadtypeParser::loadParser;
122 else if(element == "property")pp=&propertytypeParser::propertyParser;
123 else if(element == "inport")pp=&inporttypeParser<>::inportParser;
124 else if(element == "outport")pp=&outporttypeParser<>::outportParser;
125 this->SetUserDataAndPush(pp);
131 } // end of namespace YACS