interpreter.hh 1.89 KB
Newer Older
1
2
3
// -*- mode: c++ -*-
// Copyright 2011, Florent Lamiraux, CNRS.

Guilhem Saurel's avatar
Guilhem Saurel committed
4
5
6
#ifndef DYNAMIC_GRAPH_PYTHON_INTERPRETER_H
#define DYNAMIC_GRAPH_PYTHON_INTERPRETER_H

7
8
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
Florent Lamiraux's avatar
Florent Lamiraux committed
9
#include <dynamic-graph/python/fwd.hh>
10
11
#include "dynamic-graph/python/api.hh"

12
#include "dynamic-graph/python/python-compat.hh"
13
14
#include "dynamic-graph/python/api.hh"

15
namespace dynamicgraph {
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
16
17
18
19
20
21
22
23
24
25
26
27
28
namespace python {
///
/// This class implements a basis python interpreter.
///
/// String sent to method python are interpreted by an onboard python
/// interpreter.
class DYNAMIC_GRAPH_PYTHON_DLLAPI Interpreter {
 public:
  Interpreter();
  ~Interpreter();
  /// \brief Method to start python interperter.
  /// \param command string to execute
  /// Method deprecated, you *SHOULD* handle error messages.
Guilhem Saurel's avatar
Guilhem Saurel committed
29
  [[deprecated("you *SHOULD* handle error messages")]] std::string python(const std::string& command);
30

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
31
32
33
  /// \brief Method to start python interperter.
  /// \param command string to execute, result, stdout, stderr strings
  void python(const std::string& command, std::string& result, std::string& out, std::string& err);
34

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
35
36
37
38
39
  /// \brief Method to exectue a python script.
  /// \param filename the filename
  void runPythonFile(std::string filename);
  void runPythonFile(std::string filename, std::string& err);
  void runMain(void);
40

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
41
42
43
  /// \brief Process input stream to send relevant blocks to python
  /// \param stream input stream
  std::string processStream(std::istream& stream, std::ostream& os);
44

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
45
46
  /// \brief Return a pointer to the dictionary of global variables
  PyObject* globals();
47

Guilhem Saurel's avatar
format    
Guilhem Saurel committed
48
 private:
49
  /// The Python thread state
Guilhem Saurel's avatar
format    
Guilhem Saurel committed
50
51
52
53
54
55
56
57
58
59
  PyThreadState* _pyState;
  /// Pointer to the dictionary of global variables
  PyObject* globals_;
  /// Pointer to the dictionary of local variables
  PyObject* locals_;
  PyObject* mainmod_;
};
}  // namespace python
}  // namespace dynamicgraph
#endif  // DYNAMIC_GRAPH_PYTHON_INTERPRETER_H