Salome HOME
Revert "Synchronize adm files"
[modules/yacs.git] / src / yacsloader / outputParsers.hxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef _OUTPUTPARSERS_HXX_
21 #define _OUTPUTPARSERS_HXX_
22
23 #include "nodeParsers.hxx"
24
25 #include "factory.hxx"
26
27 #include "DataNode.hxx"
28
29 namespace YACS
30 {
31
32 /*! \brief Class for outputdata parser.
33  *
34  *  Its XML schema is:
35  \verbatim
36      <xsd:complexType name="OutputDataType">
37        <xsd:attribute name="name" type="xsd:string" use="required"/>
38        <xsd:attribute name="type" type="xsd:string" use="required"/>
39        <xsd:attribute name="ref" type="xsd::string" />
40      </xsd:complexType>
41  \endverbatim
42  */
43 struct outputdatatypeParser: parser
44 {
45   static outputdatatypeParser outputdataParser;
46
47   virtual void onStart(const XML_Char* el, const XML_Char** attr)
48     {
49       DEBTRACE("outputdatatypeParser::onStart");
50       std::string element(el);
51       parser* pp=&parser::main_parser;
52       SetUserDataAndPush(pp);
53       pp->init();
54       pp->pre();
55       pp->buildAttr(attr);
56     }
57   virtual void onEnd(const char *el,parser* child)
58     {
59     }
60   virtual void buildAttr(const XML_Char** attr)
61     {
62       DEBTRACE("outputdatatypeParser::buildAttr");
63       required("name",attr);
64       required("type",attr);
65       for (int i = 0; attr[i]; i += 2)
66       {
67         if(std::string(attr[i]) == "name")name(attr[i+1]);
68         if(std::string(attr[i]) == "type")type(attr[i+1]);
69         if(std::string(attr[i]) == "ref")ref(attr[i+1]);
70       }
71     }
72   virtual void name (const std::string& name)
73     {
74       DEBTRACE("outputdatatypeParser::name");
75       _param._name=name;
76     }
77   virtual void type (const std::string& type)
78     {
79       DEBTRACE("outputdatatypeParser::type");
80       _param._type=type;
81     }
82   virtual void ref (const std::string& ref)
83     {
84       _param.setProperty("ref",ref);
85     }
86
87   virtual void pre ()
88     {
89       DEBTRACE("outputdatatypeParser::pre");
90       _param.clear();
91     }
92   virtual myoutport& post()
93     {
94       return _param;
95     }
96   myoutport _param;
97 };
98
99 /*! \brief Class for OutNode parser.
100  *
101  *  Its XML schema is:
102  \verbatim
103      <xsd:complexType name="OutNodeType">
104        <xsd:attribute name="name" type="xsd:string" use="required"/>
105        <xsd:attribute name="kind" type="xsd:string" />
106        <xsd:attribute name="ref" type="xsd:string" />
107        <xsd:element name="parameter" type="OutputDataType"/>
108      </xsd:complexType>
109  \endverbatim
110  */
111 template <class T=ENGINE::DataNode*>
112 struct outnodetypeParser:public nodetypeParser<T>
113 {
114   static outnodetypeParser<T> outnodeParser;
115   virtual void onStart(const XML_Char* el, const XML_Char** attr);
116   virtual void onEnd(const char *el,parser* child);
117   virtual void buildAttr(const XML_Char** attr);
118   virtual void pre ();
119   virtual void name (const std::string& name);
120   virtual void kind (const std::string& kind);
121   virtual void ref (const std::string& ref);
122   virtual void create ();
123   virtual void parameter (myoutport& p);
124   virtual T post();
125   std::string _name;
126   std::string _kind;
127   std::string _ref;
128 };
129
130 template <class T> outnodetypeParser<T> outnodetypeParser<T>::outnodeParser;
131
132
133 template <class T>
134 void outnodetypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
135     {
136       DEBTRACE("outnodetypeParser::onStart");
137       std::string element(el);
138       parser* pp=&parser::main_parser;
139       if(element == "parameter")pp=&outputdatatypeParser::outputdataParser;
140       if(element == "property")pp=&propertytypeParser::propertyParser;
141       this->SetUserDataAndPush(pp);
142       pp->init();
143       pp->pre();
144       pp->buildAttr(attr);
145     }
146
147 template <class T>
148 void outnodetypeParser<T>::onEnd(const char *el,parser* child)
149     {
150       DEBTRACE("outnodetypeParser::onEnd");
151       std::string element(el);
152       if(element == "parameter")parameter(((outputdatatypeParser*)child)->post());
153       if(element == "property")this->property(((propertytypeParser*)child)->post());
154     }
155
156 template <class T>
157 void outnodetypeParser<T>::buildAttr(const XML_Char** attr)
158     {
159       DEBTRACE("outnodetypeParser::buildAttr");
160       this->required("name",attr);
161       for (int i = 0; attr[i]; i += 2)
162         {
163           if(std::string(attr[i]) == "name")name(attr[i+1]);
164           if(std::string(attr[i]) == "kind")kind(attr[i+1]);
165           if(std::string(attr[i]) == "ref")ref(attr[i+1]);
166         }
167       create();
168     }
169
170 template <class T>
171 void outnodetypeParser<T>::pre ()
172 {
173   this->_node=0;
174   _kind="";
175   _ref="";
176 }
177
178 template <class T>
179 void outnodetypeParser<T>::name (const std::string& name)
180 {
181   _name=name;
182 }
183 template <class T>
184 void outnodetypeParser<T>::kind (const std::string& kind)
185 {
186   _kind=kind;
187 }
188 template <class T>
189 void outnodetypeParser<T>::ref (const std::string& ref)
190 {
191   _ref=ref;
192 }
193
194 template <class T>
195 void outnodetypeParser<T>::create ()
196 {
197   this->_node = theRuntime->createOutDataNode(_kind,_name);
198 }
199
200 template <class T>
201 void outnodetypeParser<T>::parameter (myoutport& p)
202 {
203   DEBTRACE("outnodetypeParser::parameter");
204   if(currentProc->typeMap.count(p._type)==0)
205     {
206       //Check if the typecode is defined in the runtime
207       YACS::ENGINE::TypeCode* t=theRuntime->getTypeCode(p._type);
208       if(t==0)
209       {
210         std::string msg="Unknown Type: ";
211         msg=msg+p._type+" for node: "+this->_node->getName()+" port name: "+p._name;
212         this->logError(msg);
213         return;
214       }
215       else
216       {
217         currentProc->typeMap[p._type]=t;
218         t->incrRef();
219       }
220     }
221   ENGINE::InputPort *port = this->_node->edAddInputPort(p._name,currentProc->typeMap[p._type]);
222   this->_node->setData(port,p._props["ref"]);
223 }
224
225 template <class T>
226 T outnodetypeParser<T>::post()
227 {
228   this->_node->setRef(_ref);
229   return this->_node;
230 }
231
232 }
233 #endif