Version: 9.16.0
sinlineParsers.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 _SINLINEPARSERS_HXX_
21#define _SINLINEPARSERS_HXX_
22
23#include "Proc.hxx"
24#include "ServiceInlineNode.hxx"
25#include "Runtime.hxx"
26
29
30namespace YACS
31{
32
37template <class T=YACS::ENGINE::ServiceInlineNode*>
39{
41
42 virtual void onStart(const XML_Char* el, const XML_Char** attr);
43 virtual void onEnd(const char *el,parser* child)
44 {
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());
53 }
54 //virtual void service (const myfunc& f) {}
55 virtual void load (const loadon& l)
56 {
57 DEBTRACE( "sinline_load: " )
58 this->_container=l._container;
59 }
60 virtual T post()
61 {
62 DEBTRACE( "sinline_post " << this->_node->getName() );
63 if(this->_state == "disabled")this->_node->exDisabledState();
64
65 if(!this->_node->getComponent())
66 throw YACS::Exception("A service inline node must have a component instance");
67
68 // If the component instance has already a container don't go further
69 if(this->_node->getComponent()->getContainer())
70 return this->_node;
71
72 // Only for anonymous component instance set a container
73 if(this->_node->getComponent()->isAnonymous())
74 {
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)
78 {
79 //a default container is defined : use it if supported
80 try
81 {
82 currentProc->containerMap["DefaultContainer"]->checkCapabilityToDealWith(this->_node->getComponent());
83 this->_node->getComponent()->setContainer(currentProc->containerMap["DefaultContainer"]);
84 }
85 catch(YACS::Exception){}
86 }
87 else
88 std::cerr << "WARNING: Unknown container " << this->_container << " ignored" << std::endl;
89 }
90
91 return this->_node;
92 }
93};
94template <class T> sinlinetypeParser<T> sinlinetypeParser<T>::sinlineParser;
95
96// sinline ????
97template <>
99{
100 DEBTRACE( "sinline_function: " << f._code )
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"));
107 _node=fnode;
108}
109
110template <class T>
112 {
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);
126 pp->init();
127 pp->pre();
128 pp->buildAttr(attr);
129 }
130
131} // end of namespace YACS
132
133#endif
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
virtual bool setContainer(Container *cont)
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 ServiceInlineNode * createSInlineNode(const std::string &kind, const std::string &name)
Definition: Runtime.cxx:210
virtual ComponentInstance * createComponentInstance(const std::string &name, const std::string &kind="")
Definition: Runtime.cxx:215
void setScript(const std::string &script)
virtual void setMethod(const std::string &method)
Definition: ServiceNode.hxx:50
virtual void setComponent(ComponentInstance *compo)
Associate an existing component instance to this service node AND check the consistency regarding the...
virtual ComponentInstance * getComponent()
Return the associated component instance.
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 function parser in inline nodes.
Definition: codeParsers.hxx:74
Class for Inport parser.
Definition: portParsers.hxx:49
Class for loading parser.
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
Class for property parser.
Class for parsing ServiceInlineNode description.
virtual void onStart(const XML_Char *el, const XML_Char **attr)
virtual void load(const loadon &l)
virtual void onEnd(const char *el, parser *child)
static sinlinetypeParser< T > sinlineParser
Class for string parser.
Definition: dataParsers.hxx:32
std::string _container
Definition: factory.hxx:122