1 #ifndef GAUDIPYTHON_HELPERS_H
2 #define GAUDIPYTHON_HELPERS_H
11 #if PY_VERSION_HEX < 0x02050000
34 namespace GaudiPython {
43 return svcloc->
service(name, createif).get();
49 const bool createIf =
false )
90 const bool retrieve =
true ,
91 const bool disableDoD =
false ) ;
139 #if PY_VERSION_HEX < 0x02050000
143 Py_ssize_t size = (*(
self->ob_type->tp_as_buffer->bf_getcharbuffer))(
self, 0, &buf );
144 return size/
sizeof(T);
147 template <
class T>
static PyObject*
toPython(T* o) {
return 0; }
148 static PyObject*
toPython(
int* o) {
return PyInt_FromLong((
long)*o); }
149 static PyObject*
toPython(
short* o) {
return PyInt_FromLong((
long)*o); }
150 static PyObject*
toPython(
char* o) {
return PyInt_FromLong((
long)*o); }
151 static PyObject*
toPython(
long* o) {
return PyInt_FromLong(*o); }
152 static PyObject*
toPython(
float* o) {
return PyFloat_FromDouble((
double)*o); }
153 static PyObject*
toPython(
double* o) {
return PyFloat_FromDouble(*o); }
157 #if PY_VERSION_HEX < 0x02050000
161 Py_ssize_t size = (*(
self->ob_type->tp_as_buffer->bf_getcharbuffer))(
self, 0, &buf );
162 if ( idx < 0 || idx >= size/
int(
sizeof(T)) ) {
163 PyErr_SetString( PyExc_IndexError,
"buffer index out of range" );
172 static PyTypeObject
type = PyBuffer_Type;
173 static PySequenceMethods meth = *(PyBuffer_Type.tp_as_sequence);
174 #if PY_VERSION_HEX < 0x02050000
175 meth.sq_item = (intargfunc) &Array_item<T>;
176 meth.sq_length = (inquiry) &Array_length<T>;
178 meth.sq_item = (ssizeargfunc) &Array_item<T>;
179 meth.sq_length = (lenfunc) &Array_length<T>;
181 type.tp_as_sequence = &meth;
182 PyObject* buf = PyBuffer_FromReadWriteMemory( ptr, size*
sizeof(T) );
183 buf->ob_type = &
type;
184 Py_INCREF( buf->ob_type );
194 return &(*v.
begin());
211 template int* Helper::toAddress<int>(
void*);
212 template float* Helper::toAddress<float>(
void*);
213 template double* Helper::toAddress<double>(
void*);
217 #endif // !GAUDIPYTHON_HELPERS_H