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 _OUTPUTPARSERS_HXX_
21 #define _OUTPUTPARSERS_HXX_
23 #include "nodeParsers.hxx"
25 #include "factory.hxx"
27 #include "DataNode.hxx"
32 /*! \brief Class for outputdata parser.
36 <xsd:complexType name="OutputDataType">
37 <xsd:attribute name="name" type="xsd:string" use="required"/>
38 <xsd:attribute name="type" type="xsd:string" use="required"/>
39 <xsd:attribute name="ref" type="xsd::string" />
43 struct outputdatatypeParser: parser
45 static outputdatatypeParser outputdataParser;
47 virtual void onStart(const XML_Char* el, const XML_Char** attr)
49 DEBTRACE("outputdatatypeParser::onStart");
50 std::string element(el);
51 parser* pp=&parser::main_parser;
52 SetUserDataAndPush(pp);
57 virtual void onEnd(const char *el,parser* child)
60 virtual void buildAttr(const XML_Char** attr)
64 DEBTRACE("outputdatatypeParser::buildAttr");
65 required("name",attr);
66 required("type",attr);
67 for (int i = 0; attr[i]; i += 2)
69 if(std::string(attr[i]) == "name")name(attr[i+1]);
70 if(std::string(attr[i]) == "type")type(attr[i+1]);
71 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
74 virtual void name (const std::string& name)
76 DEBTRACE("outputdatatypeParser::name");
79 virtual void type (const std::string& type)
81 DEBTRACE("outputdatatypeParser::type");
84 virtual void ref (const std::string& ref)
86 _param.setProperty("ref",ref);
91 DEBTRACE("outputdatatypeParser::pre");
94 virtual myoutport& post()
101 /*! \brief Class for OutNode parser.
105 <xsd:complexType name="OutNodeType">
106 <xsd:attribute name="name" type="xsd:string" use="required"/>
107 <xsd:attribute name="kind" type="xsd:string" />
108 <xsd:attribute name="ref" type="xsd:string" />
109 <xsd:element name="parameter" type="OutputDataType"/>
113 template <class T=ENGINE::DataNode*>
114 struct outnodetypeParser:public nodetypeParser<T>
116 static outnodetypeParser<T> outnodeParser;
117 virtual void onStart(const XML_Char* el, const XML_Char** attr);
118 virtual void onEnd(const char *el,parser* child);
119 virtual void buildAttr(const XML_Char** attr);
121 virtual void name (const std::string& name);
122 virtual void kind (const std::string& kind);
123 virtual void ref (const std::string& ref);
124 virtual void create ();
125 virtual void parameter (myoutport& p);
132 template <class T> outnodetypeParser<T> outnodetypeParser<T>::outnodeParser;
136 void outnodetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
138 DEBTRACE("outnodetypeParser::onStart");
139 std::string element(el);
140 parser* pp=&parser::main_parser;
141 if(element == "parameter")pp=&outputdatatypeParser::outputdataParser;
142 if(element == "property")pp=&propertytypeParser::propertyParser;
143 this->SetUserDataAndPush(pp);
150 void outnodetypeParser<T>::onEnd(const char *el,parser* child)
152 DEBTRACE("outnodetypeParser::onEnd");
153 std::string element(el);
154 if(element == "parameter")parameter(((outputdatatypeParser*)child)->post());
155 if(element == "property")this->property(((propertytypeParser*)child)->post());
159 void outnodetypeParser<T>::buildAttr(const XML_Char** attr)
163 DEBTRACE("outnodetypeParser::buildAttr");
164 this->required("name",attr);
165 for (int i = 0; attr[i]; i += 2)
167 if(std::string(attr[i]) == "name")name(attr[i+1]);
168 if(std::string(attr[i]) == "kind")kind(attr[i+1]);
169 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
175 void outnodetypeParser<T>::pre ()
183 void outnodetypeParser<T>::name (const std::string& name)
188 void outnodetypeParser<T>::kind (const std::string& kind)
193 void outnodetypeParser<T>::ref (const std::string& ref)
199 void outnodetypeParser<T>::create ()
201 this->_node = theRuntime->createOutDataNode(_kind,_name);
205 void outnodetypeParser<T>::parameter (myoutport& p)
207 DEBTRACE("outnodetypeParser::parameter");
208 if(currentProc->typeMap.count(p._type)==0)
210 //Check if the typecode is defined in the runtime
211 YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type);
214 std::string msg="Unknown Type: ";
215 msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
221 currentProc->typeMap[p._type]=t;
225 ENGINE::InputPort *port = this->_node->edAddInputPort(p._name,currentProc->typeMap[p._type]);
226 this->_node->setData(port,p._props["ref"]);
230 T outnodetypeParser<T>::post()
232 this->_node->setRef(_ref);