#ifndef I2_DELEGATE_H #define I2_DELEGATE_H #include namespace icinga { using std::tr1::function; using namespace std::tr1::placeholders; template int delegate_fwd(int (TObject::*function)(TArgs), weak_ptr wref, const TArgs& args) { shared_ptr ref = wref.lock(); if (ref == NULL) return -1; return (ref.get()->*function)(args); } template function bind_weak(int (TObject::*function)(TArgs), const weak_ptr& wref) { return std::tr1::bind(delegate_fwd, function, wref, _1); } template function bind_weak(int (TObject::*function)(TArgs), shared_ptr ref) { weak_ptr wref = weak_ptr(ref); return bind_weak(function, wref); } template function bind_weak(int (TObject::*function)(TArgs), shared_ptr ref) { weak_ptr wref = weak_ptr(static_pointer_cast(ref)); return bind_weak(function, wref); } } #endif /* I2_DELEGATE_H */