My Project
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
PythonInterpreter Class Reference

This class initializes and finalized the python interpreter. More...

Public Types

typedef int id_type
 

Public Member Functions

 ~PythonInterpreter ()
 

Static Public Member Functions

static void init (id_type num)
 Initialize unique (singleton) python interpreter instance, and set Singular type identifier. More...
 
static id_type id ()
 Get Singular type identitfier. More...
 

Private Member Functions

 PythonInterpreter ()
 Singleton: Only init() is allowed to construct an instance. More...
 
void start_python ()
 
void init_python ()
 
void set_python_defaults ()
 

Static Private Member Functions

static PythonInterpreterinstance ()
 Static initialization - safely takes care of destruction on program termination. More...
 

Private Attributes

id_type m_id
 
bool m_owns_python
 

Detailed Description

This class initializes and finalized the python interpreter.

It also stores the Singular token number, which is assigned to this type on runtime.

Definition at line 45 of file pyobject.cc.

Member Typedef Documentation

◆ id_type

Definition at line 47 of file pyobject.cc.

Constructor & Destructor Documentation

◆ ~PythonInterpreter()

PythonInterpreter::~PythonInterpreter ( )
inline

Definition at line 49 of file pyobject.cc.

49{ if(m_owns_python) Py_Finalize(); }

◆ PythonInterpreter()

PythonInterpreter::PythonInterpreter ( )
inlineprivate

Singleton: Only init() is allowed to construct an instance.

Definition at line 60 of file pyobject.cc.

60 :
61 m_id(0), m_owns_python(false) { start_python(); }
void start_python()
Definition: pyobject.cc:71

Member Function Documentation

◆ id()

static id_type PythonInterpreter::id ( )
inlinestatic

Get Singular type identitfier.

Definition at line 56 of file pyobject.cc.

56{ return instance().m_id; }
static PythonInterpreter & instance()
Static initialization - safely takes care of destruction on program termination.
Definition: pyobject.cc:65

◆ init()

static void PythonInterpreter::init ( id_type  num)
inlinestatic

Initialize unique (singleton) python interpreter instance, and set Singular type identifier.

Definition at line 53 of file pyobject.cc.

53{ instance().m_id = num; }
CanonicalForm num(const CanonicalForm &f)

◆ init_python()

void PythonInterpreter::init_python ( )
inlineprivate

Definition at line 77 of file pyobject.cc.

78 {
79 Py_Initialize();
80 m_owns_python = true;
81 }

◆ instance()

static PythonInterpreter & PythonInterpreter::instance ( )
inlinestaticprivate

Static initialization - safely takes care of destruction on program termination.

Definition at line 65 of file pyobject.cc.

66 {
67 STATIC_INST_VAR PythonInterpreter init_interpreter;
68 return init_interpreter;
69 }
This class initializes and finalized the python interpreter.
Definition: pyobject.cc:45
#define STATIC_INST_VAR
Definition: globaldefs.h:10

◆ set_python_defaults()

void PythonInterpreter::set_python_defaults ( )
inlineprivate

Definition at line 83 of file pyobject.cc.

84 {
85 // Sone python modules needs argc, argv set for some reason
86 char* argv = (char*)"";
87 PySys_SetArgv(1, &argv);
88 PyRun_SimpleString("from sys import path, modules");
89 PyRun_SimpleString("_SINGULAR_IMPORTED = dict()");
90
91 char cmd[MAXPATHLEN + 20];
92 sprintf(cmd, "path.insert(0, '%s')", feGetResource('b'));
93 PyRun_SimpleString(cmd);
94 PyRun_SimpleString("del path"); // cleanup
95 }
char * feGetResource(const char id, int warn)
Definition: feResource.cc:148
#define MAXPATHLEN
Definition: omRet2Info.c:22

◆ start_python()

void PythonInterpreter::start_python ( )
inlineprivate

Definition at line 71 of file pyobject.cc.

72 {
73 if (!Py_IsInitialized()) init_python();
75 }
void init_python()
Definition: pyobject.cc:77
void set_python_defaults()
Definition: pyobject.cc:83

Field Documentation

◆ m_id

id_type PythonInterpreter::m_id
private

Definition at line 97 of file pyobject.cc.

◆ m_owns_python

bool PythonInterpreter::m_owns_python
private

Definition at line 98 of file pyobject.cc.


The documentation for this class was generated from the following file: