Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / yacsloader / codeParsers.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 _CODEPARSERS_HXX_
20 #define _CODEPARSERS_HXX_
21
22 #include "parserBase.hxx"
23 #include "dataParsers.hxx"
24
25 #include "factory.hxx"
26
27 namespace YACS
28 {
29
30 /*! \brief Class for code parser in inline nodes.
31  *
32  */
33 struct codetypeParser: parser
34 {
35   static codetypeParser codeParser;
36   virtual void onStart(const XML_Char* el, const XML_Char** attr)
37     {
38       std::string element(el);
39       parser* pp=&parser::main_parser;
40       if(element == "code")pp=&stringtypeParser::stringParser;
41       this->SetUserDataAndPush(pp);
42       pp->init();
43       pp->pre();
44       pp->buildAttr(attr);
45     }
46   virtual void onEnd(const char *el,parser* child)
47     {
48       std::string element(el);
49       if(element == "code")code(((stringtypeParser*)child)->post());
50     }
51   virtual void pre (){_code="";}
52   virtual void code (const std::string& s)
53     {
54       if(_code == "")
55         _code=s;
56       else 
57         _code=_code + '\n' + s;
58     }
59   virtual myfunc post ()
60     {
61       _func._name="script";
62       _func._code=_code;
63       return _func;
64     }
65     std::string _code;
66     myfunc _func;
67 };
68
69 /*! \brief Class for function parser in inline nodes.
70  *
71  */
72 struct functypeParser: codetypeParser
73 {
74   static functypeParser funcParser;
75   virtual void buildAttr(const XML_Char** attr)
76     {
77       required("name",attr);
78       for (int i = 0; attr[i]; i += 2) 
79       {
80         if(std::string(attr[i]) == "name")name(attr[i+1]);
81       }
82     }
83   virtual void name (const std::string& name)
84     {
85       _func._name=name;
86     }
87   virtual myfunc post ()
88     {
89       _func._code=_code;
90       return _func;
91     }
92 };
93
94 }
95
96 #endif