Salome HOME
865256c32ebe84d98600c317e7a3ec40a8fe01e6
[modules/yacs.git] / src / yacsloader / LoadState.hxx
1 // Copyright (C) 2006-2014  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 #ifndef __LOADSTATE_HXX_
21 #define __LOADSTATE_HXX_
22
23 #include "YACSloaderExport.hxx"
24 #include "xmlParserBase.hxx"
25
26 #include "define.hxx"
27 #include "Exception.hxx"
28
29 namespace YACS
30 {
31   namespace ENGINE
32   {
33     class Proc;
34     class Runtime;
35
36     //! Load state from a file into a Proc
37     /*!
38      * \param p: the Proc
39      * \param xmlStateFile: the file name
40      */
41     YACSLOADER_EXPORT void loadState(YACS::ENGINE::Proc *p,const std::string& xmlStateFile);
42
43     /*! \brief class for parse an xml file, use a dedicated parser, to load a
44      *  saved state of a SALOME execution.
45      */
46
47     class YACSLOADER_EXPORT stateLoader: public xmlReader
48     {
49     public:
50       stateLoader(xmlParserBase* parser,
51                   YACS::ENGINE::Proc* p);
52       virtual void parse(std::string xmlState);
53     protected:
54       Proc* _p;
55       Runtime* _runtime;
56     };
57
58     typedef enum
59       {
60         XMLNOCONTEXT  = 0,
61         XMLINGRAPH    = 1,
62         XMLINNODE     = 2,
63         XMLINPORT     = 3,
64         XMLINVALUE    = 4,
65         XMLDONE       = 5,
66         XMLFATALERROR = 6
67       } XMLReadState;
68
69     //! \brief specialized parser to load SALOME execution saved states.
70     /*! this base class must be derived to build specific parsers for each tag
71      *  defined in the xml file
72      */
73
74     class YACSLOADER_EXPORT stateParser: public xmlParserBase
75     {
76     public:
77       static XMLReadState _state;
78       static std::string _what;
79
80       static void setProc(Proc* p);
81       static void setRuntime(Runtime* runtime);
82
83     public:
84       virtual void init(const xmlChar** p, xmlParserBase* father=0);
85
86     protected:
87       virtual void onStart (const XML_Char* elem, const xmlChar** p);
88       virtual void onEnd   (const XML_Char* name);
89       virtual void charData(std::string data);
90
91     protected:
92       static std::stack<XMLReadState> _stackState;
93       static Proc* _p;
94       static Runtime* _runtime;
95       static std::map<std::string, YACS::StatesForNode> _nodeStateValue;
96       static std::map<std::string, YACS::StatesForNode> _nodeStates;
97     };
98
99     class YACSLOADER_EXPORT graphParser: public stateParser
100     {
101     public:
102       virtual void init(const xmlChar** p, xmlParserBase* father=0);
103       virtual void onStart (const XML_Char* elem, const xmlChar** p);
104       virtual void onEnd   (const XML_Char* name);
105     };
106
107
108     class YACSLOADER_EXPORT nodeParser: public stateParser
109     {
110     public:
111       virtual void init(const xmlChar** p, xmlParserBase* father=0);
112       virtual void onStart (const XML_Char* elem, const xmlChar** p);
113       virtual void onEnd   (const XML_Char* name);
114       std::string _nodeName;
115       std::string _nodeState;
116     };
117
118     class YACSLOADER_EXPORT attrParser: public stateParser
119     {
120     public:
121       virtual void init(const xmlChar** p, xmlParserBase* father=0);
122       virtual void onStart (const XML_Char* elem, const xmlChar** p);
123       virtual void charData(std::string data);
124       virtual void onEnd   (const XML_Char* name);
125       std::string _attrValue;
126     };
127
128
129     class YACSLOADER_EXPORT portParser: public stateParser
130     {
131     public:
132       virtual void init(const xmlChar** p, xmlParserBase* father=0);
133       virtual void onStart (const XML_Char* elem, const xmlChar** p);
134       virtual void onEnd   (const XML_Char* name);
135       virtual void addData(std::string value);
136     };
137
138     class YACSLOADER_EXPORT valueParser: public stateParser
139     {
140     public:
141       virtual void init(const xmlChar** p, xmlParserBase* father=0);
142       virtual void onStart (const XML_Char* elem, const xmlChar** p);
143       virtual void onEnd   (const XML_Char* name);
144       virtual void addData(std::string value);
145     };
146
147     class YACSLOADER_EXPORT arrayParser: public stateParser
148     {
149     public:
150       virtual void init(const xmlChar** p, xmlParserBase* father=0);
151       virtual void onStart (const XML_Char* elem, const xmlChar** p);
152       virtual void onEnd   (const XML_Char* name);
153       virtual void addData(std::string value);
154     };
155
156     class YACSLOADER_EXPORT dataParser: public stateParser
157     {
158     public:
159       virtual void init(const xmlChar** p, xmlParserBase* father=0);
160       virtual void onStart (const XML_Char* elem, const xmlChar** p);
161       virtual void onEnd   (const XML_Char* name);
162       virtual void addData(std::string value);
163       std::list<std::string> _dataList;
164     };
165
166     class YACSLOADER_EXPORT simpleTypeParser: public stateParser
167     {
168     public:
169       virtual void init(const xmlChar** p, xmlParserBase* father=0);
170       virtual void onStart (const XML_Char* elem, const xmlChar** p);
171       virtual void onEnd   (const XML_Char* name);
172       virtual void charData(std::string data);
173     };
174
175   }
176 }
177 #endif