]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader/procParsers.hxx
Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / yacsloader / procParsers.hxx
1 //  Copyright (C) 2006-2008  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.
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 #ifndef _PROCPARSER_HXX_
20 #define _PROCPARSER_HXX_
21
22 #include "blocParsers.hxx"
23 #include "typeParsers.hxx"
24 #include "containerParsers.hxx"
25 #include "nodeParsers.hxx"
26
27 #include "Proc.hxx"
28 #include "Container.hxx"
29 #include "TypeCode.hxx"
30
31 extern YACS::ENGINE::Proc* currentProc;
32
33 namespace YACS
34 {
35
36 template <class T=YACS::ENGINE::Proc*>
37 struct proctypeParser: bloctypeParser<T>
38 {
39
40   static proctypeParser<T> procParser;
41
42   proctypeParser():bloctypeParser<T>()
43   {
44     this->_orders["type"]=1;
45     this->_orders["sequence"]=1;
46     this->_orders["objref"]=1;
47   }
48   void onStart(const XML_Char* el, const XML_Char** attr);
49   virtual void onEnd(const char *el,parser* child);
50   virtual void buildAttr(const XML_Char** attr)
51     {
52       for (int i = 0; attr[i]; i += 2) 
53         {
54           if(std::string(attr[i]) == "state")this->state(attr[i+1]);
55         }
56     }
57   virtual void pre ()
58     {
59         std::string name("proc");
60         currentProc=theRuntime->createProc(name);
61         this->_bloc=currentProc;
62         currentProc->names.push_back("");
63     }
64   virtual void type (const mytype& t)
65     {
66         DEBTRACE( "type_set" );
67         YACS::ENGINE::TypeCode* tt=currentProc->createType(t._name,t._kind);
68         tt->decrRef();
69     }
70   virtual void sequence (ENGINE::TypeCode* const& t)
71     {
72         DEBTRACE( "sequence_set" );
73         t->decrRef();
74     }
75   virtual void objref (ENGINE::TypeCode* const& t)
76     {
77         DEBTRACE( "objref_set" );
78         t->decrRef();
79     }
80   virtual void struct_ (ENGINE::TypeCode* const& t)
81     {
82         DEBTRACE( "struct_set" );
83         t->decrRef();
84     }
85   virtual void container (const mycontainer& t)
86     {
87       DEBTRACE( "container_set: " << t._name )             
88       std::vector<machine>::const_iterator iter;
89       for(iter=t._machs.begin();iter!=t._machs.end();iter++)
90         {
91           DEBTRACE( "machine name: " << (*iter)._name )             
92         }
93
94       if(currentProc->containerMap.count(t._name) == 0)
95         {
96           YACS::ENGINE::Container* cont=theRuntime->createContainer();
97           cont->setName(t._name);
98           // Set all properties for this container
99           std::map<std::string, std::string>::const_iterator pt;
100           for(pt=t._props.begin();pt!=t._props.end();pt++)
101             cont->setProperty((*pt).first,(*pt).second);
102           currentProc->containerMap[t._name]=cont;
103         }
104       else
105         {
106           std::cerr << "Warning: container " << t._name << " already defined. It will be ignored" << std::endl;
107         }
108     }
109
110   T post(){return this->_bloc;}
111 };
112
113 template <class T> proctypeParser<T> proctypeParser<T>::procParser;
114
115 }
116
117 namespace YACS
118 {
119 template <class T>
120 void proctypeParser<T>::onStart(const XML_Char* el, const XML_Char** attr)
121   {
122     DEBTRACE( "proctypeParser::onStart: " << el )
123     std::string element(el);
124     this->checkOrder(element);
125     parser* pp=&parser::main_parser;
126     if(element == "property")pp=&propertytypeParser::propertyParser;
127     else if(element == "type")pp=&typetypeParser::typeParser;
128     else if(element == "sequence")pp=&seqtypeParser::seqParser;
129     else if(element == "objref")pp=&objtypeParser::objParser;
130     else if(element == "struct")pp=&structtypeParser::structParser;
131     else if(element == "container")pp=&containertypeParser::containerParser;
132
133     else if(element == "inline")pp=&inlinetypeParser<>::inlineParser;
134     else if(element == "sinline")pp=&sinlinetypeParser<>::sinlineParser;
135     else if(element == "service")pp=&servicetypeParser<>::serviceParser;
136     else if(element == "node")pp=&nodetypeParser<>::nodeParser;
137     else if(element == "datanode")pp=&presettypeParser<>::presetParser;
138     else if(element == "outnode")pp=&outnodetypeParser<>::outnodeParser;
139
140     else if(element == "bloc")pp=&bloctypeParser<>::blocParser;
141     else if(element == "forloop")pp=&forlooptypeParser<>::forloopParser;
142     else if(element == "foreach")pp=&foreachlooptypeParser<>::foreachloopParser;
143     else if(element == "while")pp=&whilelooptypeParser<>::whileloopParser;
144     else if(element == "switch")pp=&switchtypeParser::switchParser;
145
146     else if(element == "control")pp=&controltypeParser<>::controlParser;
147     else if(element == "datalink")pp=&linktypeParser<>::linkParser;
148     else if(element == "stream")pp=&streamtypeParser<>::streamParser;
149     else if(element == "parameter")pp=&parametertypeParser::parameterParser;
150     else
151       {
152         // OCC: san -- Allow external parsers for handling of unknown elements
153         // and attributes. This capability is used by YACS GUI to read
154         // graph presentation data
155         if ( this->_defaultParsersMap )
156           {
157             if((this->_defaultParsersMap)->count(element) != 0)
158               {
159                 pp=(*(this->_defaultParsersMap))[element];
160               }
161             else
162               {
163                 std::cerr << "There is no parser for this element type. It will be ignored!" << std::endl;
164               }
165           }
166       }
167     this->SetUserDataAndPush(pp);
168     pp->init();
169     pp->pre();
170     pp->buildAttr(attr);
171   }
172
173 template <class T>
174 void proctypeParser<T>::onEnd(const char *el,parser* child)
175     {
176       DEBTRACE( "proctypeParser::onEnd: " << el )
177       std::string element(el);
178       if(element == "property")this->property(((propertytypeParser*)child)->post());
179       else if(element == "type")type(((typetypeParser*)child)->post());
180       else if(element == "sequence")sequence(((seqtypeParser*)child)->post());
181       else if(element == "objref")objref(((objtypeParser*)child)->post());
182       else if(element == "struct")struct_(((structtypeParser*)child)->post());
183       else if(element == "container")container(((containertypeParser*)child)->post());
184
185       else if(element == "inline")this->inline_(((inlinetypeParser<>*)child)->post());
186       else if(element == "sinline")this->sinline(((sinlinetypeParser<>*)child)->post());
187       else if(element == "service")this->service(((servicetypeParser<>*)child)->post());
188       else if(element == "node")this->node(((nodetypeParser<>*)child)->post());
189       else if(element == "datanode")this->preset(((presettypeParser<>*)child)->post());
190       else if(element == "outnode")this->outnode(((outnodetypeParser<>*)child)->post());
191
192       else if(element == "bloc")this->bloc(((bloctypeParser<>*)child)->post());
193       else if(element == "forloop")this->forloop(((forlooptypeParser<>*)child)->post());
194       else if(element == "foreach")this->foreach(((foreachlooptypeParser<>*)child)->post());
195       else if(element == "while")this->while_(((whilelooptypeParser<>*)child)->post());
196       else if(element == "switch")this->switch_(((switchtypeParser*)child)->post());
197  
198       else if(element == "control") this->control(((controltypeParser<>*)child)->post());
199       else if(element == "datalink") this->datalink(((linktypeParser<>*)child)->post());
200       else if(element == "stream") this->stream(((streamtypeParser<>*)child)->post());
201       else if(element == "parameter") this->parameter(((parametertypeParser*)child)->post());
202     }
203
204 }
205
206 #endif