1 #ifndef GAUDIPYTHON_HELPERS_H
2 #define GAUDIPYTHON_HELPERS_H
22 #if PY_VERSION_HEX < 0x02050000
45 namespace GaudiPython {
54 return svcloc->
service(name, createif).get();
59 const std::string& name ,
60 const bool createIf =
false )
66 const std::string&
path )
85 const std::string&
path ) ;
100 const std::string&
path ,
101 const bool retrieve =
true ,
102 const bool disableDoD =
false ) ;
131 const std::string&
path )
140 const std::string& path )
151 #if PY_VERSION_HEX < 0x02050000
155 Py_ssize_t size = (*(
self->ob_type->tp_as_buffer->bf_getcharbuffer))(
self, 0, &buf );
156 return size/
sizeof(T);
159 template <
class T>
static PyObject*
toPython(T* ) {
return 0; }
160 static PyObject*
toPython(
int* o) {
return PyInt_FromLong((
long)*o); }
161 static PyObject*
toPython(
short* o) {
return PyInt_FromLong((
long)*o); }
162 static PyObject*
toPython(
char* o) {
return PyInt_FromLong((
long)*o); }
163 static PyObject*
toPython(
long* o) {
return PyInt_FromLong(*o); }
164 static PyObject*
toPython(
float* o) {
return PyFloat_FromDouble((
double)*o); }
165 static PyObject*
toPython(
double* o) {
return PyFloat_FromDouble(*o); }
169 #if PY_VERSION_HEX < 0x02050000
173 Py_ssize_t size = (*(
self->ob_type->tp_as_buffer->bf_getcharbuffer))(
self, 0, &buf );
174 if ( idx < 0 || idx >= size/
int(
sizeof(T)) ) {
175 PyErr_SetString( PyExc_IndexError,
"buffer index out of range" );
184 static PyTypeObject
type = PyBuffer_Type;
185 static PySequenceMethods meth = *(PyBuffer_Type.tp_as_sequence);
186 #if PY_VERSION_HEX < 0x02050000
187 meth.sq_item = (intargfunc) &Array_item<T>;
188 meth.sq_length = (inquiry) &Array_length<T>;
190 meth.sq_item = (ssizeargfunc) &Array_item<T>;
191 meth.sq_length = (lenfunc) &Array_length<T>;
193 type.tp_as_sequence = &meth;
194 PyObject* buf = PyBuffer_FromReadWriteMemory( ptr, size*
sizeof(T) );
195 buf->ob_type = &
type;
196 Py_INCREF( buf->ob_type );
206 return &(*v.begin());
227 template int* Helper::toAddress<int>(
void*);
228 template float* Helper::toAddress<float>(
void*);
229 template double* Helper::toAddress<double>(
void*);
233 #endif // !GAUDIPYTHON_HELPERS_H