golib  0.5
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
goPython Namespace Reference

Python embedding. Make sure there exists only one python interpreter. Possibly there can be one per thread, but that is not tested. This is all quite new. More...

Functions

bool init ()
 
bool final ()
 
PyObject * getMainMod ()
 
PyObject * getMainNamespace ()
 
bool call (const goString &cmd)
 
bool call (const char *cmd)
 
PyObject * run (const goString &cmd)
 
bool runFile (const char *filename)
 
template<class T >
bool convert (PyObject *obj, goVector< T > &ret)
 Convert object to vector. More...
 
PyObject * getObject (const char *name)
 
void getAllSwigTypes (goList< goString > &ret)
 Get all swig type identifier strings from all swig modules. More...
 
template<class T >
void setSwigPointer (const char *name, T *o, bool own_it, const char *type_str)
 Add a new swig wrapped object to the interpreter. More...
 
template<class T >
T * getSwigPointer (const char *name, bool own_it, const char *type_str)
 Get a swig wrapped object pointer from the python interpreter. More...
 
goFloat getFloat (const char *name)
 
goDouble getDouble (const char *name)
 
void set (const char *name, goFloat value)
 
void set (const char *name, goDouble value)
 
 GOPYTHON_GETSET_DECLARATION (goMath::Vectorf, Vectorf)
 
 GOPYTHON_GETSET_DECLARATION (goMath::Vectord, Vectord)
 
 GOPYTHON_GETSET_DECLARATION (goMath::Matrixf, Matrixf)
 
 GOPYTHON_GETSET_DECLARATION (goMath::Matrixd, Matrixd)
 
 GOPYTHON_GETSET_DECLARATION (goMath::Matrix< goIndex_t >, Matrixi)
 
 GOPYTHON_GETSET_DECLARATION (goSignal3DBase< void >, Signal3DBase)
 
 GOPYTHON_GETSET_DECLARATION (goSignal3D< void >, Signal3D)
 
 GOPYTHON_GETSET_DECLARATION (goString, String)
 

Variables

goMutex mutex
 
PyObject * mainMod = 0
 
PyObject * mainNamespace = 0
 
bool initialised = false
 

Detailed Description

Python embedding. Make sure there exists only one python interpreter. Possibly there can be one per thread, but that is not tested. This is all quite new.

Programs using this must know the path to the python include file Python.h when compiling, else compilation will fail.

There are set/get methods for some golib objects, they all look like
set (const char* name, TYPE o, bool own_it);
TYPE getNAME (const char* name, bool own_it);
Examples are goMath::Vectorf* getVectorf (...) goSignal3D<void>* getSignal3D (...)

All set/get function pairs for swig wrapped objects are created with the macros GOPYTHON_GETSET_DEFINITION and GOPYTHON_GETSET_DECLARATION for definition and declaration, respectively. These macros can also be used to extend this namespace in other libraries / applications. The above macros are just for convenience and create functions the setSwigPointer / getSwigPointer. Functions for simple types should be declared and defined separately.

Function Documentation

◆ convert()

template<class T >
bool goPython::convert ( PyObject *  obj,
goVector< T > &  ret 
)

Convert object to vector.

Converts a list object with numeric values to a goVector object. Since typechecks are performed and numerical python objects must be converted, this function must be considered slow.

Parameters
objPython list object.
retTarget vector. Will be resized.
Returns
True if successful, false otherwise.

◆ getAllSwigTypes()

void goPython::getAllSwigTypes ( goList< goString > &  ret)

Get all swig type identifier strings from all swig modules.

The identifiers can be used e.g. in SWIG_TypeQuery(), so they are the strings you can use in the GOPYTHON_GETSET_DEFINITION macro, for example.

Parameters
retThe list of strings.

◆ getSwigPointer()

template<class T >
T* goPython::getSwigPointer ( const char *  name,
bool  own_it,
const char *  type_str 
)

Get a swig wrapped object pointer from the python interpreter.

All get functions for swig wrapped types are simply using this.

Parameters
nameName of the object in python.
own_itIf true, C++ will own the object. You will then need to deallocate it yourself.
type_strIdentifier used for SWIG_TypeQuery()

◆ setSwigPointer()

template<class T >
void goPython::setSwigPointer ( const char *  name,
T *  o,
bool  own_it,
const char *  type_str 
)

Add a new swig wrapped object to the interpreter.

All set functions for swig wrapped types are simply using this.

Parameters
nameName of the object in python.
oObject to wrap.
own_itIf true, python will own the object.
type_strIdentifier used for SWIG_TypeQuery()