Python2/Extensions.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef __CXX_Extensions__h
00039 #define __CXX_Extensions__h
00040
00041
00042 #ifdef _MSC_VER
00043
00044
00045 #pragma warning( disable: 4786 )
00046 #endif
00047
00048 #include "CXX/WrapPython.h"
00049 #include "CXX/Version.hxx"
00050 #include "CXX/Python2/Config.hxx"
00051 #include "CXX/Python2/CxxDebug.hxx"
00052 #include "CXX/Python2/Objects.hxx"
00053
00054 extern "C" { extern PyObject py_object_initializer; }
00055
00056 #include <vector>
00057 #include <map>
00058
00059
00060
00061 namespace Py
00062 {
00063 class ExtensionModuleBase;
00064
00065
00066 class PYCXX_EXPORT ExtensionExceptionType : public Object
00067 {
00068 public:
00069 ExtensionExceptionType();
00070 virtual ~ExtensionExceptionType();
00071
00072
00073 void init( ExtensionModuleBase &module, const std::string &name, ExtensionExceptionType &parent );
00074 void init( ExtensionModuleBase &module, const std::string &name );
00075 };
00076
00077 class PYCXX_EXPORT MethodTable
00078 {
00079 public:
00080 MethodTable();
00081 virtual ~MethodTable();
00082
00083 void add( const char *method_name, PyCFunction f, const char *doc="", int flag=1 );
00084 PyMethodDef *table();
00085
00086 protected:
00087 std::vector<PyMethodDef> t;
00088 PyMethodDef *mt;
00089
00090 static PyMethodDef method( const char* method_name, PyCFunction f, int flags=1, const char* doc="" );
00091
00092 private:
00093
00094
00095
00096 MethodTable( const MethodTable &m );
00097 void operator=( const MethodTable &m );
00098
00099 };
00100
00101
00102 extern "C" typedef PyObject *(*method_noargs_call_handler_t)( PyObject *_self, PyObject * );
00103 extern "C" typedef PyObject *(*method_varargs_call_handler_t)( PyObject *_self, PyObject *_args );
00104 extern "C" typedef PyObject *(*method_keyword_call_handler_t)( PyObject *_self, PyObject *_args, PyObject *_dict );
00105
00106 template<class T>
00107 class MethodDefExt : public PyMethodDef
00108 {
00109 public:
00110 typedef Object (T::*method_noargs_function_t)();
00111 typedef Object (T::*method_varargs_function_t)( const Tuple &args );
00112 typedef Object (T::*method_keyword_function_t)( const Tuple &args, const Dict &kws );
00113
00114
00115 MethodDefExt
00116 (
00117 const char *_name,
00118 method_noargs_function_t _function,
00119 method_noargs_call_handler_t _handler,
00120 const char *_doc
00121 )
00122 {
00123 ext_meth_def.ml_name = const_cast<char *>( _name );
00124 ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
00125 ext_meth_def.ml_flags = METH_NOARGS;
00126 ext_meth_def.ml_doc = const_cast<char *>( _doc );
00127
00128 ext_noargs_function = _function;
00129 ext_varargs_function = NULL;
00130 ext_keyword_function = NULL;
00131 }
00132
00133
00134 MethodDefExt
00135 (
00136 const char *_name,
00137 method_varargs_function_t _function,
00138 method_varargs_call_handler_t _handler,
00139 const char *_doc
00140 )
00141 {
00142 ext_meth_def.ml_name = const_cast<char *>( _name );
00143 ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
00144 ext_meth_def.ml_flags = METH_VARARGS;
00145 ext_meth_def.ml_doc = const_cast<char *>( _doc );
00146
00147 ext_noargs_function = NULL;
00148 ext_varargs_function = _function;
00149 ext_keyword_function = NULL;
00150 }
00151
00152
00153 MethodDefExt
00154 (
00155 const char *_name,
00156 method_keyword_function_t _function,
00157 method_keyword_call_handler_t _handler,
00158 const char *_doc
00159 )
00160 {
00161 ext_meth_def.ml_name = const_cast<char *>( _name );
00162 ext_meth_def.ml_meth = reinterpret_cast<method_varargs_call_handler_t>( _handler );
00163 ext_meth_def.ml_flags = METH_VARARGS|METH_KEYWORDS;
00164 ext_meth_def.ml_doc = const_cast<char *>( _doc );
00165
00166 ext_noargs_function = NULL;
00167 ext_varargs_function = NULL;
00168 ext_keyword_function = _function;
00169 }
00170
00171 ~MethodDefExt()
00172 {}
00173
00174 PyMethodDef ext_meth_def;
00175 method_noargs_function_t ext_noargs_function;
00176 method_varargs_function_t ext_varargs_function;
00177 method_keyword_function_t ext_keyword_function;
00178 Object py_method;
00179 };
00180 }
00181
00182 #include "CXX/Python2/ExtensionModule.hxx"
00183 #include "CXX/Python2/PythonType.hxx"
00184 #include "CXX/Python2/ExtensionTypeBase.hxx"
00185 #include "CXX/Python2/ExtensionOldType.hxx"
00186 #include "CXX/Python2/ExtensionType.hxx"
00187
00188
00189 #endif