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 _PRESETPARSERS_HXX_
21 #define _PRESETPARSERS_HXX_
23 #include "nodeParsers.hxx"
25 #include "factory.hxx"
27 #include "DataNode.hxx"
32 /*! \brief Class for presetdata parser.
36 <xsd:complexType name="PresetType">
37 <xsd:attribute name="name" type="xsd:string" use="required"/>
38 <xsd:attribute name="type" type="xsd:string" use="required"/>
39 <xsd:element name="value" type="ValueType" minOccurs="1" maxOccurs="1"/>
43 struct presetdatatypeParser: parser
45 static presetdatatypeParser presetdataParser;
47 virtual void onStart(const XML_Char* el, const XML_Char** attr)
49 DEBTRACE("presetdatatypeParser::onStart");
50 std::string element(el);
51 this->maxcount("value",1,element);
52 parser* pp=&parser::main_parser;
53 if(element == "value")pp=&valuetypeParser::valueParser;
54 SetUserDataAndPush(pp);
59 virtual void onEnd(const char *el,parser* child)
61 DEBTRACE("presetdatatypeParser::onEnd");
62 std::string element(el);
63 if(element == "value")value(((valuetypeParser*)child)->post());
65 virtual void buildAttr(const XML_Char** attr)
69 DEBTRACE("presetdatatypeParser::buildAttr");
70 required("name",attr);
71 required("type",attr);
72 for (int i = 0; attr[i]; i += 2)
74 if(std::string(attr[i]) == "name")name(attr[i+1]);
75 if(std::string(attr[i]) == "type")type(attr[i+1]);
76 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
79 virtual void name (const std::string& name)
81 DEBTRACE("presetdatatypeParser::name");
85 virtual void type (const std::string& type)
87 DEBTRACE("presetdatatypeParser::type");
92 virtual void ref (const std::string& ref)
99 DEBTRACE("presetdatatypeParser::pre");
103 virtual void value (const std::string& value)
105 DEBTRACE("presetdatatypeParser::value " << value);
106 _param.setProperty("value",value);
108 virtual myoutport& post()
110 DEBTRACE("presetdatatypeParser::post");
111 //a parameter can have a ref attribute OR one value element
115 _param.setProperty("value",_ref);
124 /*! \brief Class for PresetNode parser.
128 <xsd:complexType name="PresetType">
129 <xsd:attribute name="name" type="xsd:string" use="required"/>
130 <xsd:element name="parameter" type="ParameterType"/>
134 template <class T=ENGINE::DataNode*>
135 struct presettypeParser:public nodetypeParser<T>
137 static presettypeParser<T> presetParser;
138 virtual void onStart(const XML_Char* el, const XML_Char** attr);
139 virtual void onEnd(const char *el,parser* child);
140 virtual void buildAttr(const XML_Char** attr);
141 virtual void create ();
143 virtual void name (const std::string& name);
144 virtual void kind (const std::string& kind);
145 virtual void parameter (myoutport& p);
150 template <class T> presettypeParser<T> presettypeParser<T>::presetParser;
154 void presettypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
156 DEBTRACE("presettypeParser::onStart");
157 std::string element(el);
158 parser* pp=&parser::main_parser;
159 if(element == "parameter")pp=&presetdatatypeParser::presetdataParser;
160 if(element == "property")pp=&propertytypeParser::propertyParser;
161 this->SetUserDataAndPush(pp);
168 void presettypeParser<T>::onEnd(const char *el,parser* child)
170 DEBTRACE("presettypeParser::onEnd");
171 std::string element(el);
172 if(element == "parameter")parameter(((presetdatatypeParser*)child)->post());
173 if(element == "property")this->property(((propertytypeParser*)child)->post());
177 void presettypeParser<T>::buildAttr(const XML_Char** attr)
181 DEBTRACE("presettypeParser::buildAttr");
182 this->required("name",attr);
183 for (int i = 0; attr[i]; i += 2)
185 if(std::string(attr[i]) == "name")name(attr[i+1]);
186 if(std::string(attr[i]) == "kind")kind(attr[i+1]);
192 void presettypeParser<T>::pre ()
198 void presettypeParser<T>::name (const std::string& name)
204 void presettypeParser<T>::kind (const std::string& kind)
210 void presettypeParser<T>::create ()
212 this->_node = theRuntime->createInDataNode(_kind,_name);
216 void presettypeParser<T>::parameter (myoutport& p)
218 DEBTRACE("presettypeParser::parameter");
219 if(currentProc->typeMap.count(p._type)==0)
221 //Check if the typecode is defined in the runtime
222 YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type);
225 std::string msg="Unknown Type: ";
226 msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
232 currentProc->typeMap[p._type]=t;
236 ENGINE::OutputPort *port = this->_node->edAddOutputPort(p._name,currentProc->typeMap[p._type]);
237 this->_node->setData(port,p._props["value"]);