Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
G3D::PythonInterpreter Class Reference

This class implements the Singleton design pattern. More...

Public Member Functions

 PythonInterpreter (PythonInterpreter const &copy)=delete
 Stop the compiler generating methods of copying the object. More...
 
virtual ~PythonInterpreter ()
 
template<typename Out , typename In >
void call (const String &name, Out &output, const In &input)
 
void finishPython ()
 Close python interpreter. More...
 
void importFunctionFromModule (const String &function, const String &module)
 
void importModule (const String &module)
 
PythonInterpreteroperator= (PythonInterpreter const &copy)=delete
 
void startPython (const String &pythonHome)
 
Initialize Python interpreter. More...
 

Static Public Member Functions

static const char * assertPythonOk (const char *variable)
 Examine python error state. More...
 
static shared_ptr< PythonInterpreter > & interpreterHandle ()
 

Protected Member Functions

template<typename T >
convertToCObject (PyObject *input)
 
template<typename T >
PyObjectconvertToPythonArgument (const std::vector< size_t > &dimensions, T *data)
 
template<typename T >
PyObjectconvertToPythonArgument (const T &input)
 

Protected Attributes

Table< String, PyObject * > m_functions
 
Table< String, PyObject * > m_modules
 
bool m_pythonRunning = false
 
Table< int, int > test
 

Detailed Description

This class implements the Singleton design pattern.

It is not thread-safe. For more, see: https://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf (Scott Meyer's paper on the thread safety of singletons, where he argues that making a Singleton truly thread-safe in a portable way is (nearly?) impossible.) Even so, we choose Singleton for the following reasons:

Constructor & Destructor Documentation

◆ PythonInterpreter()

G3D::PythonInterpreter::PythonInterpreter ( PythonInterpreter const &  copy)
delete

Stop the compiler generating methods of copying the object.

Make these deleted functions public for more useful error messages.

◆ ~PythonInterpreter()

virtual G3D::PythonInterpreter::~PythonInterpreter ( )
inlinevirtual

Member Function Documentation

◆ assertPythonOk()

static const char* G3D::PythonInterpreter::assertPythonOk ( const char *  variable)
static

Examine python error state.

variable is the name of the most recent python object ptr that was intialized by a call to the Python API.

◆ call()

template<typename Out , typename In >
void G3D::PythonInterpreter::call ( const String name,
Out &  output,
const In &  input 
)

◆ convertToCObject()

template<typename T >
T G3D::PythonInterpreter::convertToCObject ( PyObject input)
inlineprotected

◆ convertToPythonArgument() [1/2]

template<typename T >
PyObject* G3D::PythonInterpreter::convertToPythonArgument ( const std::vector< size_t > &  dimensions,
T *  data 
)
protected

◆ convertToPythonArgument() [2/2]

template<typename T >
PyObject* G3D::PythonInterpreter::convertToPythonArgument ( const T &  input)
inlineprotected

◆ finishPython()

void G3D::PythonInterpreter::finishPython ( )

Close python interpreter.

All resources should be released with Py_DECREF at this point.

Referenced by ~PythonInterpreter().

◆ importFunctionFromModule()

void G3D::PythonInterpreter::importFunctionFromModule ( const String function,
const String module 
)

◆ importModule()

void G3D::PythonInterpreter::importModule ( const String module)

◆ interpreterHandle()

static shared_ptr<PythonInterpreter>& G3D::PythonInterpreter::interpreterHandle ( )
inlinestatic

◆ operator=()

PythonInterpreter& G3D::PythonInterpreter::operator= ( PythonInterpreter const &  copy)
delete

◆ startPython()

void G3D::PythonInterpreter::startPython ( const String pythonHome)


Initialize Python interpreter.

Member Data Documentation

◆ m_functions

Table<String, PyObject*> G3D::PythonInterpreter::m_functions
protected

◆ m_modules

Table<String, PyObject*> G3D::PythonInterpreter::m_modules
protected

◆ m_pythonRunning

bool G3D::PythonInterpreter::m_pythonRunning = false
protected

Referenced by ~PythonInterpreter().

◆ test

Table<int, int> G3D::PythonInterpreter::test
protected

documentation generated on Wed Nov 24 2021 08:01:59 using doxygen 1.8.15