Salome HOME
6102e0b3f72407f3fc770a1919f019da7cf17c81
[modules/yacs.git] / src / yacsloader / LoadState.hxx
1 // Copyright (C) 2006-2016  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     class YACSLOADER_EXPORT graphParser: public stateParser
106     {
107     public:
108       virtual void init(const xmlChar** p, xmlParserBase* father=0);
109       virtual void onStart (const XML_Char* elem, const xmlChar** p);
110       virtual void onEnd   (const XML_Char* name);
111     };
112
113
114     class loopPortParser;
115     class YACSLOADER_EXPORT nodeParser: public stateParser
116     {
117     public:
118       virtual void init(const xmlChar** p, xmlParserBase* father=0);
119       virtual void onStart (const XML_Char* elem, const xmlChar** p);
120       virtual void onEnd   (const XML_Char* name);
121       Any* xmlToAny(const std::string& data, const TypeCode* tc)const;
122       std::string _nodeName;
123       std::string _nodeState;
124     private:
125       std::list<loopPortParser*> _loopSamples;
126     };
127
128     class YACSLOADER_EXPORT attrParser: public stateParser
129     {
130     public:
131       virtual void init(const xmlChar** p, xmlParserBase* father=0);
132       virtual void onStart (const XML_Char* elem, const xmlChar** p);
133       virtual void charData(std::string data);
134       virtual void onEnd   (const XML_Char* name);
135       std::string _attrValue;
136     };
137
138
139     class YACSLOADER_EXPORT portParser: public stateParser
140     {
141     public:
142       virtual void init(const xmlChar** p, xmlParserBase* father=0);
143       virtual void onStart (const XML_Char* elem, const xmlChar** p);
144       virtual void onEnd   (const XML_Char* name);
145       virtual void addData(std::string value);
146     };
147
148     class YACSLOADER_EXPORT valueParser: public stateParser
149     {
150     public:
151       virtual void init(const xmlChar** p, xmlParserBase* father=0);
152       virtual void onStart (const XML_Char* elem, const xmlChar** p);
153       virtual void onEnd   (const XML_Char* name);
154       virtual void addData(std::string value);
155     };
156
157     class YACSLOADER_EXPORT arrayParser: public stateParser
158     {
159     public:
160       virtual void init(const xmlChar** p, xmlParserBase* father=0);
161       virtual void onStart (const XML_Char* elem, const xmlChar** p);
162       virtual void onEnd   (const XML_Char* name);
163       virtual void addData(std::string value);
164     };
165
166     class YACSLOADER_EXPORT dataParser: 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 addData(std::string value);
173       std::list<std::string> _dataList;
174     };
175
176     class YACSLOADER_EXPORT simpleTypeParser: public stateParser
177     {
178     public:
179       virtual void init(const xmlChar** p, xmlParserBase* father=0);
180       virtual void onStart (const XML_Char* elem, const xmlChar** p);
181       virtual void onEnd   (const XML_Char* name);
182       virtual void charData(std::string data);
183     };
184
185     class YACSLOADER_EXPORT loopPortParser: public stateParser
186     {
187     public:
188       virtual void init(const xmlChar** p, xmlParserBase* father=0);
189       virtual void onStart (const XML_Char* elem, const xmlChar** p);
190       virtual void onEnd   (const XML_Char* name);
191       virtual void charData(std::string data);
192       void addSample(int index, const std::string data);
193       unsigned int getNbSamples()const;
194       unsigned int getSampleId(unsigned int i)const;
195       const std::string& getSampleData(unsigned int i)const;
196       const std::string& getPortName()const;
197     private:
198       std::vector<unsigned int> _ids;
199       std::vector<std::string> _sampleData;
200     };
201
202     class YACSLOADER_EXPORT sampleParser: public stateParser
203     {
204     public:
205       sampleParser(loopPortParser* father);
206       virtual void init(const xmlChar** p, xmlParserBase* father=0);
207       virtual void onStart (const XML_Char* elem, const xmlChar** p);
208       virtual void onEnd   (const XML_Char* name);
209       virtual void charData(std::string data);
210     //protected:
211     //  Any* xmlToAny()throw(ConversionException);
212     private:
213       loopPortParser* _sampleFather;
214     };
215
216   }
217 }
218 #endif