X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fyacsloader%2FnodeParsers.hxx;h=6449b592afaba3c3ca3d4237f14ddb972634f4fb;hb=91945d98482a02a05a3f5df7511a4e5760db2a94;hp=0db06ee45274060dc0078b703525c581fe0f21bd;hpb=313a04631c63078d01c2f643a53500ec549d034e;p=modules%2Fyacs.git diff --git a/src/yacsloader/nodeParsers.hxx b/src/yacsloader/nodeParsers.hxx index 0db06ee45..6449b592a 100644 --- a/src/yacsloader/nodeParsers.hxx +++ b/src/yacsloader/nodeParsers.hxx @@ -1,3 +1,21 @@ +// Copyright (C) 2006-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #ifndef _NODEPARSERS_HXX_ #define _NODEPARSERS_HXX_ @@ -12,10 +30,10 @@ #include "Proc.hxx" #include "TypeCode.hxx" #include "InlineNode.hxx" -#include "ServiceNode.hxx" -#include "ServiceInlineNode.hxx" #include "Exception.hxx" #include "Runtime.hxx" +#include "Container.hxx" +#include "ComponentInstance.hxx" #include "OutputDataStreamPort.hxx" #include "InputDataStreamPort.hxx" #include "ComponentInstance.hxx" @@ -53,6 +71,8 @@ struct nodetypeParser: parser } virtual void buildAttr(const XML_Char** attr) { + if (!attr) + return; required("name",attr); required("type",attr); for (int i = 0; attr[i]; i += 2) @@ -95,6 +115,8 @@ template nodetypeParser nodetypeParser::nodeParser; template void nodetypeParser::property (const myprop& prop) { + if(this->_node==0) + throw YACS::Exception("Node must be completely defined before setting its properties"); _node->setProperty(prop._name,prop._value); } @@ -129,452 +151,6 @@ YACS::ENGINE::InlineNode* nodetypeParser::post () return _node; } -static std::string t1[]={"script","function",""}; - -template -struct inlinetypeParser:public nodetypeParser -{ - static inlinetypeParser inlineParser; - - virtual void onStart(const XML_Char* el, const XML_Char** attr); - virtual void onEnd(const char *el,parser* child) - { - DEBTRACE( "inlinetypeParser::onEnd: " << el ) - std::string element(el); - if(element == "kind")kind(((stringtypeParser*)child)->post()); - else if(element == "script")script(((codetypeParser*)child)->post()); - else if(element == "function")function(((functypeParser*)child)->post()); - else if(element == "property")this->property(((propertytypeParser*)child)->post()); - else if(element == "inport") inport(((inporttypeParser*)child)->post()); - else if(element == "outport") outport(((outporttypeParser*)child)->post()); - } - virtual void buildAttr(const XML_Char** attr) - { - this->required("name",attr); - for (int i = 0; attr[i]; i += 2) - { - if(std::string(attr[i]) == "name")this->name(attr[i+1]); - if(std::string(attr[i]) == "state")this->state(attr[i+1]); - } - } - virtual void pre () - { - this->_node=0; - _kind=""; - this->_state=""; - this->_container=""; - } - virtual void kind (const std::string& name) - { - DEBTRACE( "inline_kind " << name ) - _kind=name; - } - - virtual void script (const myfunc& f){} - virtual void function (const myfunc& f) {} - - virtual void inport (const myinport& p) - { - DEBTRACE( "inline_inport: " << p._name <<":"<_node==0) - throw YACS::Exception("Node must be completely defined before defining its ports"); - - if(currentProc->typeMap.count(p._type)==0) - { - //Check if the typecode is defined in the runtime - YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type); - if(t==0) - { - std::string msg="Unknown InPort Type: "; - msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name; - throw YACS::Exception(msg); - } - else - { - currentProc->typeMap[p._type]=t; - t->incrRef(); - } - } - this->_node->edAddInputPort(p._name,currentProc->typeMap[p._type]); - } - virtual void outport (const myoutport& p) - { - DEBTRACE( "inline_outport: " << p._name <<":"<_node==0) - throw YACS::Exception("Node must be completely defined before defining its ports"); - - if(currentProc->typeMap.count(p._type)==0) - { - YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type); - if(t==0) - { - std::string msg="Unknown OutPort Type: "; - msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name; - throw YACS::Exception(msg); - } - else - { - currentProc->typeMap[p._type]=t; - t->incrRef(); - } - } - this->_node->edAddOutputPort(p._name,currentProc->typeMap[p._type]); - } - virtual T post() - { - DEBTRACE( "inline_post " << this->_node->getName() ) - if(this->_state == "disabled")this->_node->exDisabledState(); - /* - std::list::iterator iter; - std::list s=_node->getSetOfOutputPort(); - for(iter=s.begin();iter!=s.end();iter++) - { - std::cerr << "port name: " << (*iter)->getName() << std::endl; - std::cerr << "port kind: " << (*iter)->edGetType()->kind() << std::endl; - } - */ - return this->_node; - } - std::string _kind; -}; - -template inlinetypeParser inlinetypeParser::inlineParser; - -template <> -void inlinetypeParser::script (const myfunc& f) -{ - DEBTRACE( "inline_script: " << f._code ) - _node=theRuntime->createScriptNode(_kind,_name); - _node->setScript(f._code); -} - -template <> -void inlinetypeParser::function (const myfunc& f) -{ - DEBTRACE( "inline_function: " << f._code ) - YACS::ENGINE::InlineFuncNode *fnode; - fnode=theRuntime->createFuncNode(_kind,_name); - fnode->setScript(f._code); - fnode->setFname(f._name); - _node=fnode; -} - -/*! \brief Class for parsing ServiceInlineNode description - * - * - */ -template -struct sinlinetypeParser:public inlinetypeParser -{ - static sinlinetypeParser sinlineParser; - - virtual void onStart(const XML_Char* el, const XML_Char** attr); - virtual void onEnd(const char *el,parser* child) - { - DEBTRACE( "sinlinetypeParser::onEnd: " << el ) - std::string element(el); - if(element == "kind")this->kind(((stringtypeParser*)child)->post()); - else if(element == "function")this->function(((functypeParser*)child)->post()); - else if(element == "load") load(((loadtypeParser*)child)->post()); - else if(element == "property")this->property(((propertytypeParser*)child)->post()); - else if(element == "inport") this->inport(((inporttypeParser*)child)->post()); - else if(element == "outport") this->outport(((outporttypeParser*)child)->post()); - } - //virtual void service (const myfunc& f) {} - virtual void load (const loadon& l) - { - DEBTRACE( "sinline_load: " ) - this->_container=l._container; - } - virtual T post() - { - DEBTRACE( "sinline_post " << this->_node->getName() ); - if(this->_state == "disabled")this->_node->exDisabledState(); - - if(currentProc->containerMap.count(this->_container) != 0) - { - this->_node->getComponent()->setContainer(currentProc->containerMap[this->_container]); - } - else if(this->_container == "") - { - if(currentProc->containerMap.count("DefaultContainer") != 0) - { - //a default container is defined : use it - this->_node->getComponent()->setContainer(currentProc->containerMap["DefaultContainer"]); - } - } - else - { - std::cerr << "WARNING: Unknown container " << this->_container << " ignored" << std::endl; - } - - return this->_node; - } -}; -template sinlinetypeParser sinlinetypeParser::sinlineParser; - -// sinline ???? -template <> -void inlinetypeParser::function (const myfunc& f) -{ - DEBTRACE( "sinline_function: " << f._code ) - YACS::ENGINE::ServiceInlineNode *fnode; - fnode=theRuntime->createSInlineNode(_kind,_name); - fnode->setScript(f._code); - fnode->setMethod(f._name); - fnode->setComponent(theRuntime->createComponentInstance("PyCompo","SalomePy")); - //fnode->setRef("PyCompo"); - _node=fnode; -} - -static std::string t2[]={"ref","node","component",""}; - -template -struct servicetypeParser:public inlinetypeParser -{ - static servicetypeParser serviceParser; - - virtual void onStart(const XML_Char* el, const XML_Char** attr); - virtual void onEnd(const char *el,parser* child) - { - DEBTRACE( "servicetypeParser::onEnd: " << el ) - std::string element(el); - if(element == "kind")this->kind(((stringtypeParser*)child)->post()); - else if(element == "ref") ref(((stringtypeParser*)child)->post()); - else if(element == "component") component(((stringtypeParser*)child)->post()); - else if(element == "node") node(((stringtypeParser*)child)->post()); - else if(element == "method") method(((stringtypeParser*)child)->post()); - else if(element == "load") load(((loadtypeParser*)child)->post()); - else if(element == "property")this->property(((propertytypeParser*)child)->post()); - else if(element == "inport") this->inport(((inporttypeParser*)child)->post()); - else if(element == "outport") this->outport(((outporttypeParser*)child)->post()); - else if(element == "instream") instream(((inporttypeParser*)child)->post()); - else if(element == "outstream") outstream(((outporttypeParser*)child)->post()); - } - virtual void ref (const std::string& name) - { - DEBTRACE( "service_ref: " << name ) - this->_node=theRuntime->createRefNode(this->_kind,this->_name); - this->_node->setRef(name); - } - virtual void component (const std::string& name) - { - DEBTRACE( "service_component: " << name ) - this->_node=theRuntime->createCompoNode(this->_kind,this->_name); - this->_node->setRef(name); - } - virtual void node (const std::string& name) - { - DEBTRACE( "service_node: " << name ) - std::string fullname = currentProc->names.back()+name; - if(currentProc->serviceMap.count(name) != 0) - { - //ServiceNode with absolute name found - YACS::ENGINE::ServiceNode* n=currentProc->serviceMap[name]; - this->_node =n->createNode(this->_name); - } - else if(currentProc->serviceMap.count(fullname) != 0) - { - //ServiceNode with relative name found - //TODO: must be a short name (possible only in the same context) - YACS::ENGINE::ServiceNode* n=currentProc->serviceMap[fullname]; - this->_node =n->createNode(this->_name); - } - else - { - throw YACS::Exception("Unknown ServiceNode"); - } - } - - virtual void method (const std::string& name) - { - DEBTRACE( "service_method: " << name ) - if(this->_node==0) - throw YACS::Exception("ServiceNode must be completely defined before defining its method"); - if(name == "") - { - this->logError("a service name must be a non empty string"); - return; - } - this->_node->setMethod(name); - } - - virtual void load (const loadon& l) - { - DEBTRACE( "service_load: " ); - this->_container=l._container; - } - - virtual void instream (const myinport& p) - { - DEBTRACE( "service_instream" ) - DEBTRACE( p._type ) - DEBTRACE( p._name ) - if(this->_node==0) - throw YACS::Exception("ServiceNode must be completely defined before defining its ports"); - - if(currentProc->typeMap.count(p._type)==0) - { - YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type); - if(t==0) - { - std::string msg="Unknown InStreamPort Type: "; - msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name; - throw YACS::Exception(msg); - } - else - { - currentProc->typeMap[p._type]=t; - t->incrRef(); - } - } - YACS::ENGINE::InputDataStreamPort* port; - port=this->_node->edAddInputDataStreamPort(p._name,currentProc->typeMap[p._type]); - // Set all properties for this port - std::map::const_iterator pt; - for(pt=p._props.begin();pt!=p._props.end();pt++) - port->setProperty((*pt).first,(*pt).second); - } - virtual void outstream (const myoutport& p) - { - DEBTRACE( "service_outstream" ) - DEBTRACE( p._type ) - DEBTRACE( p._name ) - if(this->_node==0) - throw YACS::Exception("ServiceNode must be completely defined before defining its ports"); - - if(currentProc->typeMap.count(p._type)==0) - { - YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type); - if(t==0) - { - std::string msg="Unknown OutStreamPort Type: "; - msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name; - throw YACS::Exception(msg); - } - else - { - currentProc->typeMap[p._type]=t; - t->incrRef(); - } - } - YACS::ENGINE::OutputDataStreamPort* port; - port=this->_node->edAddOutputDataStreamPort(p._name,currentProc->typeMap[p._type]); - // Set all properties for this port - std::map::const_iterator pt; - for(pt=p._props.begin();pt!=p._props.end();pt++) - port->setProperty((*pt).first,(*pt).second); - } - virtual T post() - { - DEBTRACE( "service_post " << this->_node->getName() ) - this->mincount("method",1); - if(this->_state == "disabled")this->_node->exDisabledState(); - - if(currentProc->containerMap.count(this->_container) != 0) - { - this->_node->getComponent()->setContainer(currentProc->containerMap[this->_container]); - } - else if(this->_container == "") - { - if(currentProc->containerMap.count("DefaultContainer") != 0) - { - //a default container is defined : use it - this->_node->getComponent()->setContainer(currentProc->containerMap["DefaultContainer"]); - } - } - else - { - std::cerr << "WARNING: Unknown container " << this->_container << " ignored" << std::endl; - } - return this->_node; - } -}; - -template servicetypeParser servicetypeParser::serviceParser; - -} - - -namespace YACS -{ -template -void inlinetypeParser::onStart(const XML_Char* el, const XML_Char** attr) - - { - DEBTRACE( "inlinetypeParser::onStart: " << el ) - std::string element(el); - parser* pp=&parser::main_parser; - this->maxcount("kind",1,element); - this->maxcount("script",1,element); - this->maxcount("function",1,element); - this->maxchoice(t1,1,element); - if(element == "kind")pp=&stringtypeParser::stringParser; - else if(element == "script")pp=&codetypeParser::codeParser; - else if(element == "function")pp=&functypeParser::funcParser; - else if(element == "property")pp=&propertytypeParser::propertyParser; - else if(element == "inport")pp=&inporttypeParser<>::inportParser; - else if(element == "outport")pp=&outporttypeParser<>::outportParser; - this->SetUserDataAndPush(pp); - pp->init(); - pp->pre(); - pp->buildAttr(attr); - } - -template -void sinlinetypeParser::onStart(const XML_Char* el, const XML_Char** attr) - { - DEBTRACE( "sinlinetypeParser::onStart: " << el ) - std::string element(el); - parser* pp=&parser::main_parser; - this->maxcount("kind",1,element); - this->maxcount("function",1,element); - this->maxcount("load",1,element); - if(element == "kind")pp=&stringtypeParser::stringParser; - else if(element == "function")pp=&functypeParser::funcParser; - else if(element == "load")pp=&loadtypeParser::loadParser; - else if(element == "property")pp=&propertytypeParser::propertyParser; - else if(element == "inport")pp=&inporttypeParser<>::inportParser; - else if(element == "outport")pp=&outporttypeParser<>::outportParser; - this->SetUserDataAndPush(pp); - pp->init(); - pp->pre(); - pp->buildAttr(attr); - } - -template -void servicetypeParser::onStart(const XML_Char* el, const XML_Char** attr) - { - DEBTRACE( "servicetypeParser::onStart: " << el ) - std::string element(el); - parser* pp=&parser::main_parser; - this->maxcount("kind",1,element); - this->maxcount("ref",1,element); - this->maxcount("node",1,element); - this->maxcount("component",1,element); - this->maxcount("method",1,element); - this->maxcount("load",1,element); - this->maxchoice(t2,1,element); - if(element == "kind")pp=&stringtypeParser::stringParser; - else if(element == "ref")pp=&stringtypeParser::stringParser; - else if(element == "component")pp=&stringtypeParser::stringParser; - else if(element == "node")pp=&stringtypeParser::stringParser; - else if(element == "method")pp=&stringtypeParser::stringParser; - else if(element == "load")pp=&loadtypeParser::loadParser; - else if(element == "property")pp=&propertytypeParser::propertyParser; - else if(element == "inport")pp=&inporttypeParser<>::inportParser; - else if(element == "outport")pp=&outporttypeParser<>::outportParser; - else if(element == "instream")pp=&inporttypeParser<>::inportParser; - else if(element == "outstream")pp=&outporttypeParser<>::outportParser; - this->SetUserDataAndPush(pp); - pp->init(); - pp->pre(); - pp->buildAttr(attr); - } - - - - -} +} // end of namespace YACS #endif