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