8 #ifndef BOOSTER_CALLBACK_H 9 #define BOOSTER_CALLBACK_H 11 #include <booster/backtrace.h> 13 #include <booster/intrusive_ptr.h> 14 #include <booster/refcounted.h> 17 template<
typename Type>
20 template<
typename Type>
36 template<
typename Result,
typename ...Params>
39 virtual Result operator()(Params...) = 0;
61 template<
typename Result,
typename ...Params >
65 typedef Result result_type;
73 template<
typename R,
typename F>
74 struct callable_impl :
public callable_type {
76 callable_impl(F f) : func(f){}
77 virtual R operator()(Params... args)
78 {
return func(args...); }
82 struct callable_impl<void,F> :
public callable_type {
84 callable_impl(F f) : func(f){}
85 virtual void operator()(Params... args)
94 template<
typename Call>
98 template<
typename Call>
99 callback(std::unique_ptr<Call> ptr) : call_ptr(ptr.release())
102 template<
typename Call>
104 { call_ptr = c;
return *
this; }
106 template<
typename Call>
107 callback const &operator=(std::unique_ptr<Call> c)
108 { call_ptr = 0; call_ptr = c.release();
return *
this; }
111 callback(F func) : call_ptr(
new callable_impl<Result,F>(func))
123 call_ptr =
new callable_impl<Result,F>(func);
129 call_ptr = std::move(other.call_ptr);
134 if(
this != &other) { call_ptr=other.call_ptr; }
138 Result operator()(Params ...args)
const 141 return (*call_ptr)(args...);
147 bool empty()
const {
return call_ptr.get()==0; }
152 operator bool()
const {
return !empty(); }
155 void swap(
callback &other) { call_ptr.swap(other.call_ptr); }
157 pointer_type
const &get_pointer()
const {
return call_ptr; }
158 pointer_type &get_pointer() {
return call_ptr; }
161 pointer_type call_ptr;
this exception is thrown in case of calling unassigned/empty function
Definition: callback.h:27
intrusive_ptr< callable_type > pointer_type
Definition: callback.h:71
Same as std::runtime_error but records stack trace.
Definition: backtrace.h:158
callback()
Definition: callback.h:92
Definition: callback.h:21
Definition: callback.h:18
This class is used as base class for reference counted objects that use intrusive_ptr. Deriving from this class allows simple way to manage reference counting for single object.
Definition: refcounted.h:25
bool empty() const
Definition: callback.h:147
Definition: callback.h:37
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23