1 // Copyright (C) 2006-2016 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;
105 class YACSLOADER_EXPORT graphParser: public stateParser
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);
114 class loopPortParser;
115 class YACSLOADER_EXPORT nodeParser: public stateParser
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;
125 std::list<loopPortParser*> _loopSamples;
128 class YACSLOADER_EXPORT attrParser: public stateParser
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;
139 class YACSLOADER_EXPORT portParser: public stateParser
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);
148 class YACSLOADER_EXPORT valueParser: public stateParser
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);
157 class YACSLOADER_EXPORT arrayParser: public stateParser
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);
166 class YACSLOADER_EXPORT dataParser: public stateParser
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;
176 class YACSLOADER_EXPORT simpleTypeParser: public stateParser
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);
185 class YACSLOADER_EXPORT loopPortParser: public stateParser
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;
198 std::vector<unsigned int> _ids;
199 std::vector<std::string> _sampleData;
202 class YACSLOADER_EXPORT sampleParser: public stateParser
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);
211 // Any* xmlToAny()throw(ConversionException);
213 loopPortParser* _sampleFather;