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 _PORTPARSERS_HXX_
21 #define _PORTPARSERS_HXX_
23 #include "parserBase.hxx"
24 #include "propertyParsers.hxx"
26 #include "factory.hxx"
31 /*! \brief Class for Inport parser.
33 * This class is a base class for other inport parsers
37 <xsd:complexType name="InPortType">
39 <xsd:element name="property" type="PropertyType" minOccurs="0"/>
41 <xsd:attribute name="name" type="xsd:string" use="required"/>
42 <xsd:attribute name="type" type="xsd:string" use="required"/>
47 template <class T=myinport>
48 struct inporttypeParser: parser
50 static inporttypeParser<T> inportParser;
51 virtual void onStart(const XML_Char* el, const XML_Char** attr);
52 virtual void onEnd(const char *el,parser* child);
53 virtual void buildAttr(const XML_Char** attr);
55 virtual void name(const std::string& name);
56 virtual void type(const std::string& type);
57 virtual void property (const myprop& prop);
63 /*! \brief Class for Outport parser.
65 * This class is also used for OutputDataStream Port
66 * same XML schema as inporttypeParser
68 template <class T=myoutport>
69 struct outporttypeParser:public inporttypeParser<T>
71 static outporttypeParser<T> outportParser;
74 template <class T> inporttypeParser<T> inporttypeParser<T>::inportParser;
75 template <class T> outporttypeParser<T> outporttypeParser<T>::outportParser;
78 void inporttypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
80 std::string element(el);
81 parser* pp=&parser::main_parser;
82 if(element == "property")pp=&propertytypeParser::propertyParser;
83 this->SetUserDataAndPush(pp);
89 void inporttypeParser<T>::onEnd(const char *el,parser* child)
91 std::string element(el);
92 if(element == "property")property(((propertytypeParser*)child)->post());
95 void inporttypeParser<T>::buildAttr(const XML_Char** attr)
99 required("name",attr);
100 required("type",attr);
101 for (int i = 0; attr[i]; i += 2)
103 if(std::string(attr[i]) == "name")name(attr[i+1]);
104 if(std::string(attr[i]) == "type")type(attr[i+1]);
108 void inporttypeParser<T>::pre ()
115 void inporttypeParser<T>::name(const std::string& name)
120 void inporttypeParser<T>::type(const std::string& type)
125 void inporttypeParser<T>::property (const myprop& prop)
127 DEBTRACE( "property_set: " << prop._name << prop._value )
128 _port.setProperty(prop._name,prop._value);
131 T& inporttypeParser<T>::post()