1 // Copyright (C) 2006-2008 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.
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
19 #ifndef _OUTPUTPARSERS_HXX_
20 #define _OUTPUTPARSERS_HXX_
22 #include "nodeParsers.hxx"
24 #include "factory.hxx"
26 #include "DataNode.hxx"
31 /*! \brief Class for outputdata parser.
35 <xsd:complexType name="OutputDataType">
36 <xsd:attribute name="name" type="xsd:string" use="required"/>
37 <xsd:attribute name="type" type="xsd:string" use="required"/>
38 <xsd:attribute name="ref" type="xsd::string" />
42 struct outputdatatypeParser: parser
44 static outputdatatypeParser outputdataParser;
46 virtual void onStart(const XML_Char* el, const XML_Char** attr)
48 DEBTRACE("outputdatatypeParser::onStart");
49 std::string element(el);
50 parser* pp=&parser::main_parser;
51 SetUserDataAndPush(pp);
56 virtual void onEnd(const char *el,parser* child)
59 virtual void buildAttr(const XML_Char** attr)
61 DEBTRACE("outputdatatypeParser::buildAttr");
62 required("name",attr);
63 required("type",attr);
64 for (int i = 0; attr[i]; i += 2)
66 if(std::string(attr[i]) == "name")name(attr[i+1]);
67 if(std::string(attr[i]) == "type")type(attr[i+1]);
68 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
71 virtual void name (const std::string& name)
73 DEBTRACE("outputdatatypeParser::name");
76 virtual void type (const std::string& type)
78 DEBTRACE("outputdatatypeParser::type");
81 virtual void ref (const std::string& ref)
83 _param.setProperty("ref",ref);
88 DEBTRACE("outputdatatypeParser::pre");
91 virtual myoutport& post()
98 /*! \brief Class for OutNode parser.
102 <xsd:complexType name="OutNodeType">
103 <xsd:attribute name="name" type="xsd:string" use="required"/>
104 <xsd:attribute name="kind" type="xsd:string" />
105 <xsd:attribute name="ref" type="xsd:string" />
106 <xsd:element name="parameter" type="OutputDataType"/>
110 template <class T=ENGINE::DataNode*>
111 struct outnodetypeParser:public nodetypeParser<T>
113 static outnodetypeParser<T> outnodeParser;
114 virtual void onStart(const XML_Char* el, const XML_Char** attr);
115 virtual void onEnd(const char *el,parser* child);
116 virtual void buildAttr(const XML_Char** attr);
118 virtual void name (const std::string& name);
119 virtual void kind (const std::string& kind);
120 virtual void ref (const std::string& ref);
121 virtual void create ();
122 virtual void parameter (myoutport& p);
129 template <class T> outnodetypeParser<T> outnodetypeParser<T>::outnodeParser;
133 void outnodetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
135 DEBTRACE("outnodetypeParser::onStart");
136 std::string element(el);
137 parser* pp=&parser::main_parser;
138 if(element == "parameter")pp=&outputdatatypeParser::outputdataParser;
139 if(element == "property")pp=&propertytypeParser::propertyParser;
140 this->SetUserDataAndPush(pp);
147 void outnodetypeParser<T>::onEnd(const char *el,parser* child)
149 DEBTRACE("outnodetypeParser::onEnd");
150 std::string element(el);
151 if(element == "parameter")parameter(((outputdatatypeParser*)child)->post());
152 if(element == "property")this->property(((propertytypeParser*)child)->post());
156 void outnodetypeParser<T>::buildAttr(const XML_Char** attr)
158 DEBTRACE("outnodetypeParser::buildAttr");
159 this->required("name",attr);
160 for (int i = 0; attr[i]; i += 2)
162 if(std::string(attr[i]) == "name")name(attr[i+1]);
163 if(std::string(attr[i]) == "kind")kind(attr[i+1]);
164 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
170 void outnodetypeParser<T>::pre ()
178 void outnodetypeParser<T>::name (const std::string& name)
183 void outnodetypeParser<T>::kind (const std::string& kind)
188 void outnodetypeParser<T>::ref (const std::string& ref)
194 void outnodetypeParser<T>::create ()
196 this->_node = theRuntime->createOutDataNode(_kind,_name);
200 void outnodetypeParser<T>::parameter (myoutport& p)
202 DEBTRACE("outnodetypeParser::parameter");
203 if(currentProc->typeMap.count(p._type)==0)
205 //Check if the typecode is defined in the runtime
206 YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type);
209 std::string msg="Unknown Type: ";
210 msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
216 currentProc->typeMap[p._type]=t;
220 ENGINE::InputPort *port = this->_node->edAddInputPort(p._name,currentProc->typeMap[p._type]);
221 this->_node->setData(port,p._props["ref"]);
225 T outnodetypeParser<T>::post()
227 this->_node->setRef(_ref);