Salome HOME
ab74234f3b9a9941041d7df655b8ef23d80ad6f2
[modules/yacs.git] / src / yacsloader / linkParsers.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 _LINKPARSERS_HXX_
21 #define _LINKPARSERS_HXX_
22
23 #include "parserBase.hxx"
24 #include "dataParsers.hxx"
25 #include "propertyParsers.hxx"
26
27 #include "factory.hxx"
28
29 namespace YACS
30 {
31 template <class T=mycontrol>
32 struct controltypeParser: parser
33 {
34   static controltypeParser<T> controlParser;
35
36   virtual void onStart(const XML_Char* el, const XML_Char** attr)
37     {
38       std::string element(el);
39       parser* pp=&parser::main_parser;
40       this->maxcount("fromnode",1,element);
41       this->maxcount("tonode",1,element);
42       if(element == "fromnode")pp=&stringtypeParser::stringParser;
43       else if(element == "tonode")pp=&stringtypeParser::stringParser;
44       this->SetUserDataAndPush(pp);
45       pp->init();
46       pp->pre();
47       pp->buildAttr(attr);
48     }
49   virtual void onEnd(const char *el,parser* child)
50     {
51       std::string element(el);
52       if(element == "fromnode")fromnode(((stringtypeParser*)child)->post());
53       else if(element == "tonode")tonode(((stringtypeParser*)child)->post());
54     }
55   virtual void pre ()
56     {
57       _link.clear();
58     }
59   virtual void fromnode (const std::string& name)
60     {
61       _link.fromnode(name);
62     }
63   virtual void tonode (const std::string& name)
64     {
65       _link.tonode(name);
66     }
67   virtual void property (const myprop& prop)
68     {
69       DEBTRACE( "property_set: " << prop._name << prop._value )             
70       _link.setProperty(prop._name,prop._value);
71     }
72   virtual T& post()
73     {
74       mincount("fromnode",1);
75       mincount("tonode",1);
76       return _link;
77     }
78     T _link;
79 };
80
81 template <class T=mylink>
82 struct linktypeParser: controltypeParser<T>
83 {
84   static linktypeParser<T> linkParser;
85
86   virtual void onStart(const XML_Char* el, const XML_Char** attr)
87     {
88       std::string element(el);
89       this->maxcount("fromnode",1,element);
90       this->maxcount("tonode",1,element);
91       this->maxcount("fromport",1,element);
92       this->maxcount("toport",1,element);
93       parser* pp=&parser::main_parser;
94       if(element == "fromnode")pp=&stringtypeParser::stringParser;
95       else if(element == "tonode")pp=&stringtypeParser::stringParser;
96       else if(element == "toport")pp=&stringtypeParser::stringParser;
97       else if(element == "fromport")pp=&stringtypeParser::stringParser;
98       else if(element == "property")pp=&propertytypeParser::propertyParser;
99       this->SetUserDataAndPush(pp);
100       pp->init();
101       pp->pre();
102       pp->buildAttr(attr);
103     }
104   virtual void onEnd(const char *el,parser* child)
105     {
106       std::string element(el);
107       if(element == "fromnode")this->fromnode(((stringtypeParser*)child)->post());
108       else if(element == "tonode")this->tonode(((stringtypeParser*)child)->post());
109       else if(element == "toport")toport(((stringtypeParser*)child)->post());
110       else if(element == "fromport")fromport(((stringtypeParser*)child)->post());
111       else if(element == "property")this->property(((propertytypeParser*)child)->post());
112     }
113   virtual void buildAttr(const XML_Char** attr)
114     {
115       for (int i = 0; attr[i]; i += 2) 
116         {
117           if((std::string(attr[i]) == "control")
118              && (std::string(attr[i+1]) == "false"))
119             this->_link._withControl=false;
120         }
121     }
122   virtual void fromport (const std::string& name)
123     {
124       this->_link.fromport(name);
125     }
126   virtual void toport (const std::string& name)
127     {
128       this->_link.toport(name);
129     }
130   virtual T& post()
131     {
132       this->mincount("fromnode",1);
133       this->mincount("tonode",1);
134       this->mincount("fromport",1);
135       this->mincount("toport",1);
136       return this->_link;
137     }
138 };
139
140 template <class T=mystream>
141 struct streamtypeParser: linktypeParser<T>
142 {
143   static streamtypeParser<T> streamParser;
144 };
145
146 template <class T> streamtypeParser<T> streamtypeParser<T>::streamParser;
147 template <class T> controltypeParser<T> controltypeParser<T>::controlParser;
148 template <class T> linktypeParser<T> linktypeParser<T>::linkParser;
149
150 }
151
152 #endif