1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __LOADSTATE_HXX_
21 #define __LOADSTATE_HXX_
23 #include "YACSloaderExport.hxx"
24 #include "xmlParserBase.hxx"
25 #include "InputPort.hxx"
28 #include "Exception.hxx"
42 //! Load state from a file into a Proc
45 * \param xmlStateFile: the file name
47 YACSLOADER_EXPORT void loadState(YACS::ENGINE::Proc *p,const std::string& xmlStateFile);
49 /*! \brief class for parse an xml file, use a dedicated parser, to load a
50 * saved state of a SALOME execution.
53 class YACSLOADER_EXPORT stateLoader: public xmlReader
56 stateLoader(xmlParserBase* parser,
57 YACS::ENGINE::Proc* p);
58 virtual void parse(std::string xmlState);
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
80 class YACSLOADER_EXPORT stateParser: public xmlParserBase
83 static XMLReadState _state;
84 static std::string _what;
86 static void setProc(Proc* p);
87 static void setRuntime(Runtime* runtime);
90 virtual void init(const xmlChar** p, xmlParserBase* father=0);
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);
98 static std::stack<XMLReadState> _stackState;
100 static Runtime* _runtime;
101 static std::map<std::string, YACS::StatesForNode> _nodeStateValue;
102 static std::map<std::string, YACS::StatesForNode> _nodeStates;
106 class YACSLOADER_EXPORT graphParser: public stateParser
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);
115 class loopPortParser;
116 class YACSLOADER_EXPORT nodeParser: public stateParser
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;
126 std::list<loopPortParser*> _loopSamples;
129 class YACSLOADER_EXPORT attrParser: public stateParser
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;
140 class YACSLOADER_EXPORT portParser: public stateParser
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);
149 class YACSLOADER_EXPORT valueParser: public stateParser
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);
158 class YACSLOADER_EXPORT arrayParser: public stateParser
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);
167 class YACSLOADER_EXPORT dataParser: public stateParser
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;
177 class YACSLOADER_EXPORT simpleTypeParser: public stateParser
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);
186 class YACSLOADER_EXPORT loopPortParser: public stateParser
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;
199 std::vector<unsigned int> _ids;
200 std::vector<std::string> _sampleData;
203 class YACSLOADER_EXPORT sampleParser: public stateParser
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);
212 // Any* xmlToAny()throw(ConversionException);
214 loopPortParser* _sampleFather;