Page MenuHomeHEPForge

pyWrapUtils.hh
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

pyWrapUtils.hh

#ifndef NPSTAT_PYWRAPUTILS_HH_
#define NPSTAT_PYWRAPUTILS_HH_
#include <stdexcept>
#include "Python.h"
namespace npstat {
inline double getDoubleFromPyObj(PyObject* d)
{
if (PyErr_Occurred()) throw std::runtime_error(
"In npstat::getDoubleFromPyObj: unhandled error at the time of call");
const double tmp = PyFloat_AsDouble(d);
if (PyErr_Occurred()) throw std::runtime_error(
"In npstat::getDoubleFromPyObj: argument can not be converted to a double");
return tmp;
}
class DecrefHandle
{
public:
inline explicit DecrefHandle(PyObject* ptr) : ptr_(ptr) {}
inline ~DecrefHandle() {Py_XDECREF(ptr_);}
inline PyObject* release() {PyObject* p = ptr_; ptr_=0; return p;}
private:
PyObject* ptr_;
};
inline void validatePyCallable(PyObject* pFunc)
{
if (!pFunc) throw std::invalid_argument(
"In npstat::validatePyCallable: null object encountered");
if (!PyCallable_Check(pFunc)) throw std::invalid_argument(
"In npstat::validatePyCallable: argument is not callable");
}
}
#endif // NPSTAT_PYWRAPUTILS_HH_

File Metadata

Mime Type
text/x-c
Expires
Tue, Sep 30, 5:49 AM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6560499
Default Alt Text
pyWrapUtils.hh (1 KB)

Event Timeline