1 // Copyright (C) 2006-2012 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef _NODEPARSERS_HXX_
21 #define _NODEPARSERS_HXX_
23 #include "parserBase.hxx"
24 #include "containerParsers.hxx"
25 #include "dataParsers.hxx"
26 #include "portParsers.hxx"
27 #include "codeParsers.hxx"
28 #include "propertyParsers.hxx"
31 #include "TypeCode.hxx"
32 #include "InlineNode.hxx"
33 #include "Exception.hxx"
34 #include "Runtime.hxx"
35 #include "Container.hxx"
36 #include "ComponentInstance.hxx"
37 #include "OutputDataStreamPort.hxx"
38 #include "InputDataStreamPort.hxx"
39 #include "ComponentInstance.hxx"
40 #include "factory.hxx"
42 extern YACS::ENGINE::Proc* currentProc;
43 extern YACS::ENGINE::Runtime* theRuntime;
48 /*! \brief Class for node parser.
50 * This class is a base class for other parsers
52 template <class T=YACS::ENGINE::InlineNode*>
53 struct nodetypeParser: parser
55 static nodetypeParser<T> nodeParser;
57 virtual void onStart(const XML_Char* el, const XML_Char** attr)
59 DEBTRACE( "nodetypeParser::onStart: " << el )
60 std::string element(el);
61 parser* pp=&parser::main_parser;
62 this->SetUserDataAndPush(pp);
67 virtual void onEnd(const char *el,parser* child)
69 DEBTRACE( "nodetypeParser::onEnd: " << el )
70 std::string element(el);
72 virtual void buildAttr(const XML_Char** attr)
74 required("name",attr);
75 required("type",attr);
76 for (int i = 0; attr[i]; i += 2)
78 if(std::string(attr[i]) == "name")name(attr[i+1]);
79 if(std::string(attr[i]) == "state")state(attr[i+1]);
80 if(std::string(attr[i]) == "type")type(attr[i+1]);
88 virtual void name (const std::string& name)
90 DEBTRACE( "inline_name: " << name )
93 virtual void state (const std::string& name)
97 virtual void type (const std::string& name)
99 DEBTRACE( "node_type " << name )
102 virtual void property (const myprop& prop);
107 std::string _container;
111 template <class T> nodetypeParser<T> nodetypeParser<T>::nodeParser;
114 void nodetypeParser<T>::property (const myprop& prop)
117 throw YACS::Exception("Node must be completely defined before setting its properties");
118 _node->setProperty(prop._name,prop._value);
122 T nodetypeParser<T>::post()
128 YACS::ENGINE::InlineNode* nodetypeParser<YACS::ENGINE::InlineNode*>::post ()
130 std::string fullname = currentProc->names.back()+_type;
131 if(currentProc->inlineMap.count(_type) != 0)
133 //InlineNode type with absolute name found
134 YACS::ENGINE::InlineNode* n=currentProc->inlineMap[_type];
135 _node=n->cloneNode(_name);
137 else if(currentProc->inlineMap.count(fullname) != 0)
139 //InlineNode type with relative name found
140 YACS::ENGINE::InlineNode* n=currentProc->inlineMap[fullname];
141 _node=n->cloneNode(_name);
145 throw YACS::Exception("Unknown InlineNode type");
147 if(_state == "disabled")_node->exDisabledState();
148 DEBTRACE( "node_post " << _node->getName() )
152 } // end of namespace YACS