Salome HOME
Add py2yacs
[modules/yacs.git] / src / py2yacs / py2yacs.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 #ifndef _PY2YACS_H_
20 #define _PY2YACS_H_
21
22 #include <string>
23 #include <list>
24 #include <exception>
25
26 class Py2yacsException: std::exception
27 {
28   public:
29     Py2yacsException(const std::string& what);
30     virtual ~Py2yacsException()throw ();
31     virtual const char *what() const throw ();
32   private:
33     std::string _what;
34 };
35
36 namespace YACS
37 {
38   namespace ENGINE
39   {
40     class Proc;
41   };
42 };
43
44 struct FunctionProperties
45 {
46   public:
47     std::string _name;
48     std::list<std::string> _input_ports;
49     std::list<std::string> _output_ports;
50     std::list<std::string> _errors;
51     std::list<std::string> _imports;
52 };
53
54 /*! \brief Converter of a python script to a yacs schema.
55  *  This class converts a string containing a python script to a yacs schema
56  *  containing a python script node.
57  */
58 class Py2yacs
59 {
60   public:
61     Py2yacs();
62     
63     /*!
64      * This constructor can be used if you want to define your own python parser.
65      * The parser function should be a python function and return a tuple of
66      * two lists.
67      * The first list contains the properties of all the functions in the script
68      * and the second one contains global errors.
69      * \param python_parser_module: name of the parser module
70      * \param python_parser_function: name of the parser function
71      */
72     Py2yacs(const std::string& python_parser_module,
73             const std::string& python_parser_function);
74
75     /*!
76      * \param python_code: contains the python code that will be converted
77      *                     to a yacs schema.
78      */
79     void load(const std::string& python_code);
80
81     /*!
82      * \param file_path: path to the xml file where to save the yacs schema.
83      * \param python_function: function defined in the python code that will be
84      *                         called in the yacs node.
85      */
86     void save(const std::string& file_path,
87               const std::string& python_function)const;
88
89     /*!
90      * A new schema is created.
91      * \param python_function: function defined in the python code that will be
92      *                         called in the yacs node.
93      */
94     YACS::ENGINE::Proc* createProc(const std::string& python_function)const;
95     
96     const std::list<std::string>& getGlobalErrors() const;
97     const std::list<FunctionProperties>& getFunctionProperties()const;
98
99   private:
100     std::string _python_parser_module;
101     std::string _python_parser_function;
102     std::list<FunctionProperties> _functions;
103     std::list<std::string> _global_errors;
104     std::string _python_code;
105 };
106
107 #endif //_PY2YACS_H_