pymacros.h File Reference

Defines macros to facilitate the integration of Python with our program. More...

#include <python.h>

Go to the source code of this file.

Defines

#define DECLARE_PYTHON_TYPE(_myClass, _className, _classDescription, _inheritance)
 Declares the Python type object for a given class.
#define DECLARE_PYTHON_MODULE_TYPE(_myModule, _moduleName)
 Declares the Python type object for a given module.
#define DECLARE_PYTHON_OBJECT_METHOD(_className, _methodName)
 Method declaration on the object's header file.
#define START_PYTHON_OBJECT_METHODS(_className)   PyMethodDef _className::m_PyMethods [] = {
 Method block start Begin with this, then add as many python methods as necessary, then end with END_PYTHON_OBJECT_METHODS.
#define ADD_OBJECT_METHOD(_className, _methodName)   {#_methodName, (PyCFunction)PYTHON_METHOD_STCALL(_className,_methodName), METH_VARARGS, _className::_methodName##_doc }
 Declares one object method entry for the object dictionary.
#define END_PYTHON_OBJECT_METHODS()   { NULL, NULL }}
 Method block end.
#define IMPLEMENT_PYTHON_OBJECT_METHOD(_className, _methodName, _desc)
 Declares the actual implementation of a python instance method.
#define DECLARE_PYTHON_MODULE(_moduleName)
 Declares necessary functions for the initialization of a Python module.
#define PYTHON_MODULE_METHOD_NOARGS(_moduleName, _methodName)   static PyObject* PYTHON_MODULE_CALL(_moduleName,_methodName)(PYTHON_MODULE_OBJECT(_moduleName)* self)
 Declares a python method that receives no arguments.
#define PYTHON_MODULE_METHOD_VARARGS(_moduleName, _methodName)   static PyObject* PYTHON_MODULE_CALL(_moduleName,_methodName)(PYTHON_MODULE_OBJECT(_moduleName)* self, PyObject* args, PyObject* kwds)
 Declares a python method that receives arguments.
#define START_PYTHON_MODULE_METHODS(_moduleName)   static PyMethodDef PYTHON_MODULE_METHODS(_moduleName) [] = {
 Starts an inclussion block for adding module methods to the module's dictionary.
#define END_PYTHON_MODULE_METHODS()   {NULL}}
 Ends an inclussion block for module methods.
#define ADD_MODULE_METHOD(_moduleName, _methodName, _description, _methodType)   {#_methodName, (PyCFunction)PYTHON_MODULE_CALL(_moduleName,_methodName), _methodType, _description }
 Declares one module method entry for the module dictionary.
#define DECLARE_PYTHON_MODULE_INITIALIZATION(_moduleName, _moduleNameStr)
 Resolves into the function call that initializes a python module.
#define CREATE_PYTHON_MODULE(_moduleName, _moduleDesc, _newModuleObject)
 Creates a module and assigns it to a given object name.
#define PYTHON_ERROR(_string)   { PyErr_SetString( PyExc_TypeError, _string ); return NULL; }
 Returns an object containing the provided string, and triggers an error event.
#define PYTHON_ADD_ENUMERATION_TO_DICTIONARY(_pyDictionary, _enumValue, _enumName)
 Adds an enumeration into the provided dictionary.

Enumerations

enum  ePythonReturnValue
 Describes a set of predefined python return values.

Functions

PYOBJECT PythonReturnValue (ePythonReturnValue a_returnValue)
 Returns a special predefined python value.


Detailed Description

Defines macros to facilitate the integration of Python with our program.

Author:
Dan Torres

Definition in file pymacros.h.


Define Documentation

#define ADD_MODULE_METHOD ( _moduleName,
_methodName,
_description,
_methodType   )     {#_methodName, (PyCFunction)PYTHON_MODULE_CALL(_moduleName,_methodName), _methodType, _description }

Declares one module method entry for the module dictionary.

Parameters:
_moduleName name of the module
_methodName name of the function as described on the PYTHON_MODULE_METHOD_* macro
_description A string description of the method
_methodType Either METH_VARARGS or METH_NOARGS

Definition at line 224 of file pymacros.h.

#define ADD_OBJECT_METHOD ( _className,
_methodName   )     {#_methodName, (PyCFunction)PYTHON_METHOD_STCALL(_className,_methodName), METH_VARARGS, _className::_methodName##_doc }

Declares one object method entry for the object dictionary.

Parameters:
_className name of the class
_methodName name of the function as described on the DECLARE_PYTHON_OBJECT_METHOD macro

Definition at line 152 of file pymacros.h.

#define CREATE_PYTHON_MODULE ( _moduleName,
_moduleDesc,
_newModuleObject   ) 

Value:

PYTHON_MODULE_TYPE( _moduleName ).ob_type = &PyType_Type;                   \
    if( PyType_Ready(&PYTHON_MODULE_TYPE( _moduleName )) < 0 ){ return NULL; }  \
    PYOBJECT _newModuleObject = Py_InitModule3( #_moduleName, PYTHON_MODULE_METHODS(_moduleName), _moduleDesc ); \
    if( !_newModuleObject ){ return NULL; }
Creates a module and assigns it to a given object name.

Parameters:
_moduleName The name of the module to create
_moduleDesc Brief string description for the module
_newModuleObject (out) Name to use for the creation of the new module

Definition at line 243 of file pymacros.h.

#define DECLARE_PYTHON_MODULE ( _moduleName   ) 

Value:

extern PyTypeObject PYTHON_MODULE_TYPE( _moduleName );          \
    extern PYOBJECT     PYTHON_MODULE_INITIALIZE( _moduleName );    \
    typedef struct{ PyObject_HEAD; } PYTHON_MODULE_OBJECT(_moduleName);
Declares necessary functions for the initialization of a Python module.

This macro defines an 'empty' object that can be used to contain modular functions. If you want a module that contains members, the typedef'ed structure should define them explicitly.

Parameters:
_moduleName Unique name identifier for our module

Definition at line 182 of file pymacros.h.

#define DECLARE_PYTHON_MODULE_INITIALIZATION ( _moduleName,
_moduleNameStr   ) 

Value:

DECLARE_PYTHON_MODULE_TYPE( _moduleName, _moduleNameStr );              \
    PYOBJECT PYTHON_MODULE_INITIALIZE( _moduleName )
Resolves into the function call that initializes a python module.

The body of this function still has to be written by you, in which you will probably want to call CREATE_PYTHON_MODULE. The function must either return a new module object, or NULL.

Definition at line 233 of file pymacros.h.

#define DECLARE_PYTHON_MODULE_TYPE ( _myModule,
_moduleName   ) 

Value:

static PyTypeObject PYTHON_MODULE_TYPE( _myModule ) = {         \
    PyObject_HEAD_INIT(&PyType_Type)                                \
    0,                                                              \
    _moduleName, sizeof(PYTHON_MODULE_OBJECT(_myModule)), 0,        \
}
Declares the Python type object for a given module.

This macro is automatically called for you on DECLARE_PYTHON_MODULE_INITIALIZATION

Parameters:
_myModule Name of the module
_moduleName Short module name, as a string

Definition at line 116 of file pymacros.h.

#define DECLARE_PYTHON_OBJECT_METHOD ( _className,
_methodName   ) 

Value:

PYOBJECT PYTHON_METHOD_CALL(_className,_methodName)(PYOBJECT a_pSelf, PYOBJECT a_pArgs, PYOBJECT a_pKwds ); \
    static PYOBJECT PYTHON_METHOD_STCALL(_className,_methodName)(PYOBJECT a_pSelf, PYOBJECT a_pArgs, PYOBJECT a_pKwds){ \
    return ((_className*)a_pSelf)->PYTHON_METHOD_CALL(_className,_methodName)(a_pSelf,a_pArgs,a_pKwds); }; \
    static char _methodName##_doc[];\
Method declaration on the object's header file.

Parameters:
_className Name of the class owning the method
_methodName Name reserved for this method

Definition at line 132 of file pymacros.h.

#define DECLARE_PYTHON_TYPE ( _myClass,
_className,
_classDescription,
_inheritance   ) 

Declares the Python type object for a given class.

Parameters:
_myClass Name of the class
_className Short class name, as a string
_classDescription Brief description of the class, as a string
_inheritance Either PYTHON_TYPE_BASE or PYTHON_TYPE_FINAL

Definition at line 72 of file pymacros.h.

#define IMPLEMENT_PYTHON_OBJECT_METHOD ( _className,
_methodName,
_desc   ) 

Value:

char _className::_methodName##_doc[] = _desc;                           \
    PYOBJECT _className::PYTHON_METHOD_CALL(_className,_methodName)(PYOBJECT a_pSelf, PYOBJECT a_pArgs, PYOBJECT a_pKwds )
Declares the actual implementation of a python instance method.

Parameters:
_className Name of the owning class
_methodName Name of this particular method as described on the DECLARE_PYTHON_OBJECT_METHOD macro
_desc A brief string describing what the function does

Definition at line 167 of file pymacros.h.

#define PYTHON_ADD_ENUMERATION_TO_DICTIONARY ( _pyDictionary,
_enumValue,
_enumName   ) 

Value:

{ PYOBJECT pAsInt = PyInt_FromLong( _enumValue );                                   \
      PyDict_SetItemString( _pyDictionary, _enumName, pAsInt );                         \
      Py_DECREF(pAsInt);                                                                \
    }
Adds an enumeration into the provided dictionary.

Parameters:
_pyDictionary The dictionary to add the new enumeration to
_enumValue The enumeration value
_enumName The name to use in Python for this enumeration

Definition at line 269 of file pymacros.h.

#define PYTHON_MODULE_METHOD_NOARGS ( _moduleName,
_methodName   )     static PyObject* PYTHON_MODULE_CALL(_moduleName,_methodName)(PYTHON_MODULE_OBJECT(_moduleName)* self)

Declares a python method that receives no arguments.

Its actual implementation can be defined at a different moment

Parameters:
_moduleName Name of the module that contains this method
_methodName Name of the function for this method

Definition at line 193 of file pymacros.h.

#define PYTHON_MODULE_METHOD_VARARGS ( _moduleName,
_methodName   )     static PyObject* PYTHON_MODULE_CALL(_moduleName,_methodName)(PYTHON_MODULE_OBJECT(_moduleName)* self, PyObject* args, PyObject* kwds)

Declares a python method that receives arguments.

Its actual implementation can be defined at a different moment

Parameters:
_moduleName Name of the module that contains this method
_methodName Name of the function for this method

Definition at line 202 of file pymacros.h.


Function Documentation

PYOBJECT PythonReturnValue ( ePythonReturnValue  a_returnValue  )  [inline]

Returns a special predefined python value.

Parameters:
a_returnValue A member of the ePythonReturnValue enumeration

Definition at line 290 of file pymacros.h.


Generated on Tue Jan 20 17:57:53 2009 for EclipseRay by  doxygen 1.5.7.1