callback_r_0.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_0_H
00060 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_0_H
00061
00062
00063
00064
00065
00066 #include "util_common.h"
00067 #include "shared_ptr.h"
00068 #include "callback_common.h"
00069 #include "impl/dispatcher_r_0.h"
00070
00071
00072
00073
00074
00075
00076 namespace lass
00077 {
00078 namespace util
00079 {
00080
00081
00082
00083
00084
00085 template
00086 <
00087 typename R
00088 >
00089 class CallbackR0
00090 {
00091 public:
00092
00093 typedef CallbackR0<R> TSelf;
00094 typedef SharedPtr< impl::DispatcherR0<R> > TDispatcherPtr;
00095
00096
00097
00098
00099
00100 CallbackR0()
00101 {
00102 }
00103
00104
00105
00106 template <typename Function>
00107 CallbackR0(Function iFunction):
00108 dispatcher_(make(iFunction, meta::Wrap<typename meta::IsDerived<Function, impl::DispatcherR0<R> >::Type>()))
00109 {
00110 }
00111
00112
00113
00114 template <typename ObjectPtr, typename Method>
00115 CallbackR0(ObjectPtr iObject, Method iMethod):
00116 dispatcher_(new impl::DispatcherR0Method<R, ObjectPtr, Method>(iObject, iMethod))
00117 {
00118 }
00119
00120
00121
00122 CallbackR0(const TSelf& iOther):
00123 dispatcher_(iOther.dispatcher_)
00124 {
00125 }
00126
00127
00128
00129
00130
00131
00132
00133 template <typename Other>
00134 TSelf& operator=(const Other& iOther)
00135 {
00136 TSelf temp(iOther);
00137 swap(temp);
00138 return *this;
00139 }
00140
00141
00142
00143 R operator()() const
00144 {
00145 if (isEmpty())
00146 {
00147 LASS_THROW_EX(EmptyCallback, "You've tried to call an empty CallbackR0. Can't return a value.");
00148 }
00149 return dispatcher_->call();
00150 }
00151
00152
00153
00154
00155
00156
00157 void reset()
00158 {
00159 dispatcher_.reset();
00160 }
00161
00162
00163
00164 bool isEmpty() const
00165 {
00166 return dispatcher_.isEmpty();
00167 }
00168
00169
00170
00171 bool operator!() const
00172 {
00173 return dispatcher_.isEmpty();
00174 }
00175
00176
00177
00178 operator num::SafeBool() const
00179 {
00180 return dispatcher_.isEmpty() ? num::safeFalse : num::safeTrue;
00181 }
00182
00183
00184
00185 void swap(TSelf& iOther)
00186 {
00187 dispatcher_.swap(iOther.dispatcher_);
00188 }
00189
00190 private:
00191
00192 template <typename Function>
00193 static TDispatcherPtr make(Function iFunction, meta::Wrap<meta::False>)
00194 {
00195 return TDispatcherPtr(new impl::DispatcherR0Function<R, Function>(iFunction));
00196 }
00197
00198 template <typename Dispatcher>
00199 static TDispatcherPtr make(Dispatcher iDispatcher, meta::Wrap<meta::True>)
00200 {
00201 return TDispatcherPtr(new Dispatcher(iDispatcher));
00202 }
00203
00204 TDispatcherPtr dispatcher_;
00205 };
00206
00207
00208
00209
00210
00211
00212 template <typename R>
00213 bool operator!=(const CallbackR0<R>& iA, const CallbackR0<R>& iB)
00214 {
00215 return !(iA == iB);
00216 }
00217
00218
00219
00220
00221
00222
00223 template <typename R> inline
00224 CallbackR0<R> makeCallback(R (*iFunction)())
00225 {
00226 return Callback0(iFunction);
00227 }
00228
00229
00230
00231
00232
00233
00234 template <typename R> inline
00235 const CallbackR0<R>& makeCallback(const CallbackR0<R>& iCallback)
00236 {
00237 return iCallback;
00238 }
00239
00240
00241
00242
00243
00244
00245 template <typename ObjectPtr, typename Object, typename R> inline
00246 CallbackR0<R> makeCallback(ObjectPtr iObject, R (Object::*iMethod)())
00247 {
00248 return Callback0(iObject, iMethod);
00249 }
00250
00251
00252
00253
00254
00255
00256 template <typename ObjectPtr, typename Object, typename R> inline
00257 CallbackR0<R> makeCallback(ObjectPtr iObject, R (Object::*iMethod)() const)
00258 {
00259 return Callback0(iObject, iMethod);
00260 }
00261
00262
00263
00264 }
00265
00266 }
00267
00268 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_CALLBACK_R0
00269 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_PYTHON_H
00270 # include "callback_python.h"
00271 #endif
00272
00273 #endif // Guardian of Inclusion
00274
00275