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