#ifndef DELEGATE_H #define DELEGATE_H #include namespace icinga { template int delegate_fwd(int (TObject::*function)(TArgs), weak_ptr wref, const TArgs& args) { shared_ptr ref = wref.lock(); if (ref.get() == 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 /* DELEGATE_H */