| The Gaudi Framework v28r2-patches (bc4ad17a)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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