The Gaudi Framework  v29r0 (ff2e7097)
CallbackStreamBuf.cpp
Go to the documentation of this file.
1 // ============================================================================
2 #include "GaudiPython/CallbackStreamBuf.h" // this one first, so Python.h is first
3 // ============================================================================
5 // ============================================================================
6 #include <algorithm>
7 // ============================================================================
8 
9 // ============================================================================
11 // ============================================================================
12 int GaudiPython::call_python_method( PyObject* self, const char* method, char* buf )
13 {
14  if ( !self || !method ) {
15  return 1;
16  }
17  PyObject* r = PyObject_CallMethod( self, const_cast<char*>( method ), const_cast<char*>( "s" ), buf );
18  if ( !r ) {
19  std::string err( "Unsuccessful call to bound Python method" );
20  err += method;
21  PyErr_SetString( PyExc_TypeError, err.c_str() );
22  PyErr_Print();
23  return 1;
24  }
25  Py_DECREF( r );
26  return 0;
27 }
28 
29 // ============================================================================
31 // ============================================================================
32 GaudiPython::CallbackStreamBuf::CallbackStreamBuf( PyObject* self ) : m_self( self ) {}
33 
34 // ============================================================================
36 // ============================================================================
38 {
39  size_t length;
40  char* x;
41  for ( length = 0, x = pbase(); x < epptr(); ++x, ++length )
42  ;
43  // getting in a null terminated buffer the characters
44  memcpy( m_callbackBuff.data(), pbase(), std::min( length, m_callbackBuff.size() ) );
45  m_callbackBuff[std::min( length, m_callbackBuff.size() )] = '\0';
46  // calling the python method
48  // reseting in/out buffer pointers
49  setp( pbase(), pbase() );
50  setg( eback(), eback(), eback() );
51  return 0;
52 }
int sync() override
reimplementation of stringbuf::sync()
std::array< char, 512 > m_callbackBuff
STL class.
T min(T...args)
T data(T...args)
T size(T...args)
T pbase(T...args)
T c_str(T...args)
CallbackStreamBuf(PyObject *self)
CallbackStreamBuf constructor.
T setg(T...args)
T eback(T...args)
T setp(T...args)
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:29