Salome HOME
updated copyright message
[modules/yacs.git] / src / yacsloader / LoadState.hxx
1 // Copyright (C) 2006-2023  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 #include "InputPort.hxx"
26
27 #include "define.hxx"
28 #include "Exception.hxx"
29 #include <vector>
30 #include <list>
31
32 namespace YACS
33 {
34   namespace ENGINE
35   {
36     class Proc;
37     class Runtime;
38     class SequenceAny;
39     class Any;
40     class TypeCode;
41
42     //! Load state from a file into a Proc
43     /*!
44      * \param p: the Proc
45      * \param xmlStateFile: the file name
46      */
47     YACSLOADER_EXPORT void loadState(YACS::ENGINE::Proc *p,const std::string& xmlStateFile);
48
49     /*! \brief class for parse an xml file, use a dedicated parser, to load a
50      *  saved state of a SALOME execution.
51      */
52
53     class YACSLOADER_EXPORT stateLoader: public xmlReader
54     {
55     public:
56       stateLoader(xmlParserBase* parser,
57                   YACS::ENGINE::Proc* p);
58       virtual void parse(std::string xmlState);
59     protected:
60       Proc* _p;
61       Runtime* _runtime;
62     };
63
64     typedef enum
65       {
66         XMLNOCONTEXT  = 0,
67         XMLINGRAPH    = 1,
68         XMLINNODE     = 2,
69         XMLINPORT     = 3,
70         XMLINVALUE    = 4,
71         XMLDONE       = 5,
72         XMLFATALERROR = 6
73       } XMLReadState;
74
75     //! \brief specialized parser to load SALOME execution saved states.
76     /*! this base class must be derived to build specific parsers for each tag
77      *  defined in the xml file
78      */
79
80     class YACSLOADER_EXPORT stateParser: public xmlParserBase
81     {
82     public:
83       static XMLReadState _state;
84       static std::string _what;
85
86       static void setProc(Proc* p);
87       static void setRuntime(Runtime* runtime);
88
89     public:
90       virtual void init(const xmlChar** p, xmlParserBase* father=0);
91
92     protected:
93       virtual void onStart (const XML_Char* elem, const xmlChar** p);
94       virtual void onEnd   (const XML_Char* name);
95       virtual void charData(std::string data);
96
97     protected:
98       static std::stack<XMLReadState> _stackState;
99       static Proc* _p;
100       static Runtime* _runtime;
101       static std::map<std::string, YACS::StatesForNode> _nodeStateValue;
102       static std::map<std::string, YACS::StatesForNode> _nodeStates;
103     };
104
105 #ifndef SWIG
106     class YACSLOADER_EXPORT graphParser: 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     };
113
114
115     class loopPortParser;
116     class YACSLOADER_EXPORT nodeParser: 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 onEnd   (const XML_Char* name);
122       Any* xmlToAny(const std::string& data, const TypeCode* tc)const;
123       std::string _nodeName;
124       std::string _nodeState;
125     private:
126       std::list<loopPortParser*> _loopSamples;
127     };
128
129     class YACSLOADER_EXPORT attrParser: 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 charData(std::string data);
135       virtual void onEnd   (const XML_Char* name);
136       std::string _attrValue;
137     };
138
139
140     class YACSLOADER_EXPORT portParser: public stateParser
141     {
142     public:
143       virtual void init(const xmlChar** p, xmlParserBase* father=0);
144       virtual void onStart (const XML_Char* elem, const xmlChar** p);
145       virtual void onEnd   (const XML_Char* name);
146       virtual void addData(std::string value);
147     };
148
149     class YACSLOADER_EXPORT valueParser: public stateParser
150     {
151     public:
152       virtual void init(const xmlChar** p, xmlParserBase* father=0);
153       virtual void onStart (const XML_Char* elem, const xmlChar** p);
154       virtual void onEnd   (const XML_Char* name);
155       virtual void addData(std::string value);
156     };
157
158     class YACSLOADER_EXPORT arrayParser: public stateParser
159     {
160     public:
161       virtual void init(const xmlChar** p, xmlParserBase* father=0);
162       virtual void onStart (const XML_Char* elem, const xmlChar** p);
163       virtual void onEnd   (const XML_Char* name);
164       virtual void addData(std::string value);
165     };
166
167     class YACSLOADER_EXPORT dataParser: public stateParser
168     {
169     public:
170       virtual void init(const xmlChar** p, xmlParserBase* father=0);
171       virtual void onStart (const XML_Char* elem, const xmlChar** p);
172       virtual void onEnd   (const XML_Char* name);
173       virtual void addData(std::string value);
174       std::list<std::string> _dataList;
175     };
176
177     class YACSLOADER_EXPORT simpleTypeParser: public stateParser
178     {
179     public:
180       virtual void init(const xmlChar** p, xmlParserBase* father=0);
181       virtual void onStart (const XML_Char* elem, const xmlChar** p);
182       virtual void onEnd   (const XML_Char* name);
183       virtual void charData(std::string data);
184     };
185
186     class YACSLOADER_EXPORT loopPortParser: public stateParser
187     {
188     public:
189       virtual void init(const xmlChar** p, xmlParserBase* father=0);
190       virtual void onStart (const XML_Char* elem, const xmlChar** p);
191       virtual void onEnd   (const XML_Char* name);
192       virtual void charData(std::string data);
193       void addSample(int index, const std::string data);
194       unsigned int getNbSamples()const;
195       unsigned int getSampleId(unsigned int i)const;
196       const std::string& getSampleData(unsigned int i)const;
197       const std::string& getPortName()const;
198     private:
199       std::vector<unsigned int> _ids;
200       std::vector<std::string> _sampleData;
201     };
202
203     class YACSLOADER_EXPORT sampleParser: public stateParser
204     {
205     public:
206       sampleParser(loopPortParser* father);
207       virtual void init(const xmlChar** p, xmlParserBase* father=0);
208       virtual void onStart (const XML_Char* elem, const xmlChar** p);
209       virtual void onEnd   (const XML_Char* name);
210       virtual void charData(std::string data);
211     //protected:
212     //  Any* xmlToAny()throw(ConversionException);
213     private:
214       loopPortParser* _sampleFather;
215     };
216 #endif
217   }
218 }
219 #endif