1 // Copyright (C) 2006-2012 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
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)
67 DEBTRACE("presetdatatypeParser::buildAttr");
68 required("name",attr);
69 required("type",attr);
70 for (int i = 0; attr[i]; i += 2)
72 if(std::string(attr[i]) == "name")name(attr[i+1]);
73 if(std::string(attr[i]) == "type")type(attr[i+1]);
74 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
77 virtual void name (const std::string& name)
79 DEBTRACE("presetdatatypeParser::name");
83 virtual void type (const std::string& type)
85 DEBTRACE("presetdatatypeParser::type");
90 virtual void ref (const std::string& ref)
97 DEBTRACE("presetdatatypeParser::pre");
101 virtual void value (const std::string& value)
103 DEBTRACE("presetdatatypeParser::value " << value);
104 _param.setProperty("value",value);
106 virtual myoutport& post()
108 DEBTRACE("presetdatatypeParser::post");
109 //a parameter can have a ref attribute OR one value element
113 _param.setProperty("value",_ref);
122 /*! \brief Class for PresetNode parser.
126 <xsd:complexType name="PresetType">
127 <xsd:attribute name="name" type="xsd:string" use="required"/>
128 <xsd:element name="parameter" type="ParameterType"/>
132 template <class T=ENGINE::DataNode*>
133 struct presettypeParser:public nodetypeParser<T>
135 static presettypeParser<T> presetParser;
136 virtual void onStart(const XML_Char* el, const XML_Char** attr);
137 virtual void onEnd(const char *el,parser* child);
138 virtual void buildAttr(const XML_Char** attr);
139 virtual void create ();
141 virtual void name (const std::string& name);
142 virtual void kind (const std::string& kind);
143 virtual void parameter (myoutport& p);
148 template <class T> presettypeParser<T> presettypeParser<T>::presetParser;
152 void presettypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
154 DEBTRACE("presettypeParser::onStart");
155 std::string element(el);
156 parser* pp=&parser::main_parser;
157 if(element == "parameter")pp=&presetdatatypeParser::presetdataParser;
158 if(element == "property")pp=&propertytypeParser::propertyParser;
159 this->SetUserDataAndPush(pp);
166 void presettypeParser<T>::onEnd(const char *el,parser* child)
168 DEBTRACE("presettypeParser::onEnd");
169 std::string element(el);
170 if(element == "parameter")parameter(((presetdatatypeParser*)child)->post());
171 if(element == "property")this->property(((propertytypeParser*)child)->post());
175 void presettypeParser<T>::buildAttr(const XML_Char** attr)
177 DEBTRACE("presettypeParser::buildAttr");
178 this->required("name",attr);
179 for (int i = 0; attr[i]; i += 2)
181 if(std::string(attr[i]) == "name")name(attr[i+1]);
182 if(std::string(attr[i]) == "kind")kind(attr[i+1]);
188 void presettypeParser<T>::pre ()
194 void presettypeParser<T>::name (const std::string& name)
200 void presettypeParser<T>::kind (const std::string& kind)
206 void presettypeParser<T>::create ()
208 this->_node = theRuntime->createInDataNode(_kind,_name);
212 void presettypeParser<T>::parameter (myoutport& p)
214 DEBTRACE("presettypeParser::parameter");
215 if(currentProc->typeMap.count(p._type)==0)
217 //Check if the typecode is defined in the runtime
218 YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type);
221 std::string msg="Unknown Type: ";
222 msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
228 currentProc->typeMap[p._type]=t;
232 ENGINE::OutputPort *port = this->_node->edAddOutputPort(p._name,currentProc->typeMap[p._type]);
233 this->_node->setData(port,p._props["value"]);