This class is used to maintain the Python interpreter. More...
#include <utils.h>
Static Public Member Functions | |
static void | addThread () |
static void | deleteThread () |
static void | execute (const char *) |
static void | executeFile (string) |
static void | finalize () |
static PyObject * | getModule () |
static const char * | getPythonEncoding () |
static void | initialize () |
static void | registerGlobalMethod (const char *, PyCFunction, int, const char *, bool=true) |
static void | registerGlobalMethod (const char *, PyCFunctionWithKeywords, int, const char *, bool=true) |
Detailed Description
This class is used to maintain the Python interpreter.
A single interpreter is used throughout the lifetime of the application.
The implementation is implemented in a thread-safe way (within the limitations of the Python threading model, of course).
During the initialization the code checks for a file 'init.py' in its search path and, if it does exist, the statements in the file will be executed. In this way a library of globally available functions can easily be initialized.
The stderr and stdout streams of Python are redirected by default to the frePPLe log stream.
The following frePPLe functions are available from within Python.
All of these are in the module called frePPLe.
- The following classes and their attributes are accessible for reading and writing.
Each object has a toXML() method that returns its XML representation as a string, or writes it to a file is a file is passed as argument.- buffer
- buffer_default
- buffer_infinite
- buffer_procure
- calendar
- calendarBucket
- calendar_boolean
- calendar_double
- calendar_void
- customer
- customer_default
- demand
- demand_default
- flow
- flowplan
- item
- item_default
- load
- loadplan
- location
- location_default
- operation
- operation_alternate
- addAlternate(operation=x, priority=y, effective_start=z1, effective_end=z2)
- operation_fixed_time
- operation_routing
- addStep(tuple of operations)
- operation_time_per
- operationplan
- parameters
- problem (read-only)
- resource
- resource_default
- resource_infinite
- setup_matrix
- setup_matrix_default
- solver
- solve()
- solver_mrp
- The following functions or attributes return iterators over the frePPLe objects:
- buffers()
- buffer.flows
- buffer.flowplans
- calendar.buckets
- calendars()
- customers()
- demands()
- demand.operationplans
- demand.pegging
- operation.flows
- operation.loads
- items()
- locations()
- operations()
- operation.operationplans
- problems()
- resources()
- resource.loads
- resource.loadplans
- setup_matrices()
- solvers()
- printsize():
Prints information about the memory consumption. - loadmodule(string [,parameter=value, ...]):
Dynamically load a module in memory. - readXMLdata(string [,bool] [,bool]):
Processes an XML string passed as argument. - log(string):
Prints a string to the frePPLe log file.
This is used for redirecting the stdout and stderr of Python. - readXMLfile(string [,bool] [,bool]):
Read an XML-file. - saveXMLfile(string):
Save the model to an XML-file. - saveplan(string):
Save the main plan information to a file. - erase(boolean):
Erase the model (arg true) or only the plan (arg false, default). - version:
A string variable with the version number.
The technical implementation is inspired by and inherited from the following article: "Embedding Python in Multi-Threaded C/C++ Applications", see http://www.linuxjournal.com/article/3641
Member Function Documentation
void frepple::utils::PythonInterpreter::addThread | ( | ) | [static] |
Create a new Python thread state.
Each OS-level thread needs to initialize a Python thread state as well. When a new thread is created in the OS, this method should be called to create a Python thread state as well.
See the Python PyGILState_Ensure API.
Definition at line 152 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::deleteThread | ( | ) | [static] |
Delete a Python thread state.
Each OS-level thread has a Python thread state. When an OS thread is deleted, this method should be called to delete the Python thread state as well.
See the Python PyGILState_Release API.
Definition at line 168 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::execute | ( | const char * | cmd | ) | [static] |
Execute some python code.
Definition at line 181 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::executeFile | ( | string | filename | ) | [static] |
Execute a file with Python code.
Definition at line 221 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::finalize | ( | ) | [static] |
Finalizes the interpreter.
Definition at line 140 of file pythonutils.cpp.
static PyObject* frepple::utils::PythonInterpreter::getModule | ( | ) | [inline, static] |
static const char* frepple::utils::PythonInterpreter::getPythonEncoding | ( | ) | [inline, static] |
void frepple::utils::PythonInterpreter::initialize | ( | ) | [static] |
Initializes the interpreter.
Definition at line 53 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::registerGlobalMethod | ( | const char * | name, |
PyCFunction | method, | ||
int | flags, | ||
const char * | doc, | ||
bool | lock = true |
||
) | [static] |
Register a new method to Python.
Arguments:
- The name of the built-in function/method
- The function that implements it.
- Combination of METH_* flags, which mostly describe the args expected by the C func.
- The __doc__ attribute, or NULL.
Definition at line 241 of file pythonutils.cpp.
void frepple::utils::PythonInterpreter::registerGlobalMethod | ( | const char * | c, |
PyCFunctionWithKeywords | f, | ||
int | i, | ||
const char * | d, | ||
bool | b = true |
||
) | [static] |
Register a new method to Python.
Definition at line 297 of file pythonutils.cpp.
The documentation for this class was generated from the following files:
Documentation generated for frePPLe by
