Store Sequence sequence location in a shared_ptr class
[mussa.git] / py / python.hpp
1 #ifndef _MUSSA_PYTHON_HPP_
2 #define _MUSSA_PYTHON_HPP_
3 #include <boost/python.hpp>
4 #include <string>
5 #include <list>
6 #include <utility>
7
8 //! Create a singleton class to manage our reference to the python interpreter
9 class MussaPython {
10   public:
11     typedef void (*python_module_init)(void);
12     MussaPython();
13
14     //! initalize interpreter
15     void init_interpreter();
16     //! add a python module that was statically compiled into this executable
17     void add_module(const std::string& name, python_module_init); 
18     //! return main python namespace(initializing the interpreter if needed)
19     boost::python::object get_namespace();
20     //! pass multi-statement code block to the python interpreter
21     void run(std::string);
22     //! pass single expression to the python interpreter and return the result
23     boost::python::object eval(std::string);
24     //! use InteractiveConsole for readloop
25     void interpreter();
26     //! launch fgets based read-eval-print loop tied to the provided FILE pointer
27     void simple_interpreter(FILE *fp=stdin);
28     //! return an object in the python namespace
29     boost::python::object operator[](std::string);
30   protected:
31     typedef std::pair<std::string, python_module_init> module_item;
32     typedef std::list<module_item> module_list;
33     module_list python_modules;
34     boost::python::object main_namespace;
35     
36     static void AppendInittab(const module_item &item);
37 };
38
39 //! return a reference to a single mussa python interpreter
40 MussaPython *get_py_ptr();
41 MussaPython &get_py();
42
43 #endif // _MUSSA_PYTHON_HPP_