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