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