Salome HOME
Copyright update 2022
[modules/yacs.git] / src / yacsloader / containerParsers.cxx
1 // Copyright (C) 2006-2022  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 #include "containerParsers.hxx"
21 #include "propertyParsers.hxx"
22 #include "HomogeneousPoolContainer.hxx"
23
24 //#define _DEVDEBUG_
25 #include "YacsTrace.hxx"
26
27 namespace YACS
28 {
29   containertypeParser containertypeParser::containerParser;
30   machinetypeParser machinetypeParser::machineParser;
31   loadtypeParser loadtypeParser::loadParser;
32
33   void machinetypeParser::buildAttr(const XML_Char** attr)
34     {
35       if (!attr)
36         return;
37       required("name",attr);
38       for (int i = 0; attr[i]; i += 2)
39       {
40         if(std::string(attr[i]) == "name")name(attr[i+1]);
41       }
42     }
43   void machinetypeParser::pre (){_mach._name="";}
44   void machinetypeParser::name(const std::string& name){ _mach._name=name; }
45   machine machinetypeParser::post()
46     {
47       return _mach;
48     }
49
50   void containertypeParser::buildAttr(const XML_Char** attr)
51     {
52       if (!attr)
53         return;
54       required("name",attr);
55       for (int i = 0; attr[i]; i += 2)
56       {
57         if(std::string(attr[i]) == "name")name(attr[i+1]);
58       }
59     }
60   void containertypeParser::onStart(const XML_Char* el, const XML_Char** attr)
61     {
62       std::string element(el);
63       parser* pp=&parser::main_parser;
64       if(element == "machine")pp=&machinetypeParser::machineParser;
65       if(element == "property")pp=&propertytypeParser::propertyParser;
66       if(element == "initializescriptkey")pp=&codetypeParser::codeParser;
67       SetUserDataAndPush(pp);
68       pp->init();
69       pp->pre();
70       pp->buildAttr(attr);
71     }
72   void containertypeParser::onEnd(const char *el,parser* child)
73     {
74       std::string element(el);
75       if(element == "machine")machine_(((machinetypeParser*)child)->post());
76       if(element == "property")property(((propertytypeParser*)child)->post());
77       if(element == "initializescriptkey")initializescriptkey(((codetypeParser*)child)->post());
78     }
79   void containertypeParser::pre ()
80     {
81       _container._machs.clear();
82       _container._props.clear();
83     }
84   void containertypeParser::name(const std::string& name){ _container._name=name; }
85   void containertypeParser::machine_(const machine& m)
86     {
87       DEBTRACE( "machine: " << m._name )             
88       _container._machs.push_back(m);
89     }
90   void containertypeParser::property (const myprop& prop)
91     {
92       DEBTRACE( "property_set: " << prop._name << " " << prop._value );
93       _container._props[prop._name]=prop._value;
94     }
95   void containertypeParser::initializescriptkey(const myfunc& f)
96   {
97     _container._props[YACS::ENGINE::HomogeneousPoolContainer::INITIALIZE_SCRIPT_KEY]=f._code;
98   }
99
100   mycontainer containertypeParser::post()
101     {
102       //mincount("machine",1);
103       return _container;
104     }
105
106   void loadtypeParser::buildAttr(const XML_Char** attr)
107     {
108       if (!attr)
109         return;
110       required("container",attr);
111       for (int i = 0; attr[i]; i += 2)
112       {
113         if(std::string(attr[i]) == "container")container(attr[i+1]);
114       }
115     }
116   void loadtypeParser::pre (){_loadon._container="";}
117   void loadtypeParser::container(const std::string& name){ _loadon._container=name; }
118   loadon loadtypeParser::post()
119     {
120       return _loadon;
121     }
122
123 }