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 _PRESETPARSERS_HXX_
20 #define _PRESETPARSERS_HXX_
22 #include "nodeParsers.hxx"
24 #include "factory.hxx"
26 #include "DataNode.hxx"
31 /*! \brief Class for presetdata parser.
35 <xsd:complexType name="PresetType">
36 <xsd:attribute name="name" type="xsd:string" use="required"/>
37 <xsd:attribute name="type" type="xsd:string" use="required"/>
38 <xsd:element name="value" type="ValueType" minOccurs="1" maxOccurs="1"/>
42 struct presetdatatypeParser: parser
44 static presetdatatypeParser presetdataParser;
46 virtual void onStart(const XML_Char* el, const XML_Char** attr)
48 DEBTRACE("presetdatatypeParser::onStart");
49 std::string element(el);
50 this->maxcount("value",1,element);
51 parser* pp=&parser::main_parser;
52 if(element == "value")pp=&valuetypeParser::valueParser;
53 SetUserDataAndPush(pp);
58 virtual void onEnd(const char *el,parser* child)
60 DEBTRACE("presetdatatypeParser::onEnd");
61 std::string element(el);
62 if(element == "value")value(((valuetypeParser*)child)->post());
64 virtual void buildAttr(const XML_Char** attr)
66 DEBTRACE("presetdatatypeParser::buildAttr");
67 required("name",attr);
68 required("type",attr);
69 for (int i = 0; attr[i]; i += 2)
71 if(std::string(attr[i]) == "name")name(attr[i+1]);
72 if(std::string(attr[i]) == "type")type(attr[i+1]);
73 if(std::string(attr[i]) == "ref")ref(attr[i+1]);
76 virtual void name (const std::string& name)
78 DEBTRACE("presetdatatypeParser::name");
82 virtual void type (const std::string& type)
84 DEBTRACE("presetdatatypeParser::type");
89 virtual void ref (const std::string& ref)
96 DEBTRACE("presetdatatypeParser::pre");
100 virtual void value (const std::string& value)
102 DEBTRACE("presetdatatypeParser::value " << value);
103 _param.setProperty("value",value);
105 virtual myoutport& post()
107 DEBTRACE("presetdatatypeParser::post");
108 //a parameter can have a ref attribute OR one value element
112 _param.setProperty("value",_ref);
121 /*! \brief Class for PresetNode parser.
125 <xsd:complexType name="PresetType">
126 <xsd:attribute name="name" type="xsd:string" use="required"/>
127 <xsd:element name="parameter" type="ParameterType"/>
131 template <class T=ENGINE::DataNode*>
132 struct presettypeParser:public nodetypeParser<T>
134 static presettypeParser<T> presetParser;
135 virtual void onStart(const XML_Char* el, const XML_Char** attr);
136 virtual void onEnd(const char *el,parser* child);
137 virtual void buildAttr(const XML_Char** attr);
138 virtual void create ();
140 virtual void name (const std::string& name);
141 virtual void kind (const std::string& kind);
142 virtual void parameter (myoutport& p);
147 template <class T> presettypeParser<T> presettypeParser<T>::presetParser;
151 void presettypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
153 DEBTRACE("presettypeParser::onStart");
154 std::string element(el);
155 parser* pp=&parser::main_parser;
156 if(element == "parameter")pp=&presetdatatypeParser::presetdataParser;
157 if(element == "property")pp=&propertytypeParser::propertyParser;
158 this->SetUserDataAndPush(pp);
165 void presettypeParser<T>::onEnd(const char *el,parser* child)
167 DEBTRACE("presettypeParser::onEnd");
168 std::string element(el);
169 if(element == "parameter")parameter(((presetdatatypeParser*)child)->post());
170 if(element == "property")this->property(((propertytypeParser*)child)->post());
174 void presettypeParser<T>::buildAttr(const XML_Char** attr)
176 DEBTRACE("presettypeParser::buildAttr");
177 this->required("name",attr);
178 for (int i = 0; attr[i]; i += 2)
180 if(std::string(attr[i]) == "name")name(attr[i+1]);
181 if(std::string(attr[i]) == "kind")kind(attr[i+1]);
187 void presettypeParser<T>::pre ()
193 void presettypeParser<T>::name (const std::string& name)
199 void presettypeParser<T>::kind (const std::string& kind)
205 void presettypeParser<T>::create ()
207 this->_node = theRuntime->createInDataNode(_kind,_name);
211 void presettypeParser<T>::parameter (myoutport& p)
213 DEBTRACE("presettypeParser::parameter");
214 if(currentProc->typeMap.count(p._type)==0)
216 //Check if the typecode is defined in the runtime
217 YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type);
220 std::string msg="Unknown Type: ";
221 msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
227 currentProc->typeMap[p._type]=t;
231 ENGINE::OutputPort *port = this->_node->edAddOutputPort(p._name,currentProc->typeMap[p._type]);
232 this->_node->setData(port,p._props["value"]);