Salome HOME
b0a778d66e7492fd764161c6cdf2768ca02fb165
[modules/yacs.git] / src / yacsloader / componentinstanceParsers.cxx
1 // Copyright (C) 2006-2023  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 "componentinstanceParsers.hxx"
21 #include "containerParsers.hxx"
22 #include "dataParsers.hxx"
23 #include "propertyParsers.hxx"
24
25 //#define _DEVDEBUG_
26 #include "YacsTrace.hxx"
27
28 namespace YACS
29 {
30   componentinstancetypeParser componentinstancetypeParser::componentinstanceParser;
31
32   void componentinstancetypeParser::buildAttr(const XML_Char** attr)
33     {
34       if (!attr)
35         return;
36       required("name",attr);
37       for (int i = 0; attr[i]; i += 2)
38       {
39         if(std::string(attr[i]) == "name")name(attr[i+1]);
40         if(std::string(attr[i]) == "kind")kind(attr[i+1]);
41       }
42     }
43   void componentinstancetypeParser::onStart(const XML_Char* el, const XML_Char** attr)
44     {
45       std::string element(el);
46       parser* pp=&parser::main_parser;
47       this->maxcount("component",1,element);
48       this->maxcount("load",1,element);
49       if(element == "property")pp=&propertytypeParser::propertyParser;
50       else if(element == "component")pp=&stringtypeParser::stringParser;
51       else if(element == "load")pp=&loadtypeParser::loadParser;
52       SetUserDataAndPush(pp);
53       pp->init();
54       pp->pre();
55       pp->buildAttr(attr);
56     }
57   void componentinstancetypeParser::onEnd(const char *el,parser* child)
58     {
59       std::string element(el);
60       if(element == "property")property(((propertytypeParser*)child)->post());
61       else if(element == "component") component(((stringtypeParser*)child)->post());
62       else if(element == "load") load(((loadtypeParser*)child)->post());
63     }
64
65   void componentinstancetypeParser::pre ()
66     {
67       _componentinstance._props.clear();
68     }
69
70   void componentinstancetypeParser::name(const std::string& name)
71     { _componentinstance._name=name; }
72
73   void componentinstancetypeParser::kind(const std::string& kind)
74     { _componentinstance._kind=kind; }
75
76   void componentinstancetypeParser::property (const myprop& prop)
77     {
78       DEBTRACE("property_set: "<<prop._name<<" "<<prop._value);
79       _componentinstance._props[prop._name]=prop._value;
80     }
81
82   void componentinstancetypeParser::component (const std::string& name)
83     {
84       DEBTRACE( "component_set: " << name )
85       _componentinstance._component=name;
86     }
87
88   void componentinstancetypeParser::load (const loadon& l)
89     {
90       DEBTRACE( "load: " )
91       _componentinstance._container=l._container;
92     }
93
94   mycomponentinstance componentinstancetypeParser::post()
95     {
96       this->mincount("component",1);
97       return _componentinstance;
98     }
99 }