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
00060
00061
00062
00063
00064
00065
00066 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_2_H
00067 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_R_2_H
00068
00069
00070
00071
00072
00073 #include "util_common.h"
00074 #include "shared_ptr.h"
00075 #include "callback_common.h"
00076 #include "impl/dispatcher_r_2.h"
00077
00078
00079
00080
00081
00082
00083 namespace lass
00084 {
00085 namespace util
00086 {
00087
00088
00089
00090
00091
00092 template
00093 <
00094 typename R,
00095 typename P1, typename P2
00096 >
00097 class CallbackR2
00098 {
00099 public:
00100
00101 typedef CallbackR2<R, P1, P2> TSelf;
00102 typedef SharedPtr< impl::DispatcherR2<R, P1, P2> > TDispatcherPtr;
00103
00104
00105
00106
00107
00108 CallbackR2()
00109 {
00110 }
00111
00112
00113
00114 template <typename FunctionType>
00115 CallbackR2(FunctionType iFunction):
00116 dispatcher_(new impl::DispatcherR2Function<R, P1, P2, FunctionType>(iFunction))
00117 {
00118 }
00119
00120
00121
00122 template <typename ObjectPtr, typename Method>
00123 CallbackR2(ObjectPtr iObject, Method iMethod):
00124 dispatcher_(new impl::DispatcherR2Method<R, P1, P2, ObjectPtr, Method>(iObject, iMethod))
00125 {
00126 }
00127
00128
00129
00130 CallbackR2(const TSelf& iOther):
00131 dispatcher_(iOther.dispatcher_)
00132 {
00133 }
00134
00135
00136
00137
00138
00139
00140
00141 template <typename Other>
00142 TSelf& operator=(const Other& iOther)
00143 {
00144 TSelf temp(iOther);
00145 swap(temp);
00146 return *this;
00147 }
00148
00149
00150
00151 R operator()(typename util::CallTraits<P1>::TParam iP1, typename util::CallTraits<P2>::TParam iP2) const
00152 {
00153 if (isEmpty())
00154 {
00155 LASS_THROW_EX(EmptyCallback, "You've tried to call an empty CallbackR2. Can't return a value.");
00156 }
00157 return dispatcher_->call(iP1, iP2);
00158 }
00159
00160
00161
00162
00163
00164
00165 void reset()
00166 {
00167 dispatcher_.reset();
00168 }
00169
00170
00171
00172 bool isEmpty() const
00173 {
00174 return dispatcher_.isEmpty();
00175 }
00176
00177
00178
00179 bool operator!() const
00180 {
00181 return dispatcher_.isEmpty();
00182 }
00183
00184
00185
00186 operator num::SafeBool() const
00187 {
00188 return dispatcher_.isEmpty() ? num::safeFalse : num::safeTrue;
00189 }
00190
00191
00192
00193 void swap(TSelf& iOther)
00194 {
00195 dispatcher_.swap(iOther.dispatcher_);
00196 }
00197
00198 private:
00199
00200 TDispatcherPtr dispatcher_;
00201 };
00202
00203
00204
00205
00206
00207
00208 template <typename R, typename P1, typename P2> inline
00209 CallbackR2<R, P1, P2> makeCallback(R (*iFunction)(P1, P2))
00210 {
00211 return CallbackR2<R, P1, P2>(iFunction);
00212 }
00213
00214
00215
00216
00217
00218
00219 template <typename R, typename P1, typename P2> inline
00220 const CallbackR2<R, P1, P2>& makeCallback(const CallbackR2<R, P1, P2>& iCallback)
00221 {
00222 return iCallback;
00223 }
00224
00225
00226
00227
00228
00229
00230 template <typename ObjectPtr, typename Object, typename R, typename P1, typename P2> inline
00231 CallbackR2<R, P1, P2> makeCallback(ObjectPtr iObject, R (Object::*iMethod)(P1, P2))
00232 {
00233 return CallbackR2<R, P1, P2>(iObject, iMethod);
00234 }
00235
00236
00237
00238
00239
00240
00241 template <typename ObjectPtr, typename Object, typename R, typename P1, typename P2> inline
00242 CallbackR2<R, P1, P2> makeCallback(ObjectPtr iObject, R (Object::*iMethod)(P1, P2) const)
00243 {
00244 return CallbackR2<R, P1, P2>(iObject, iMethod);
00245 }
00246
00247
00248
00249 }
00250
00251 }
00252
00253 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_CALLBACK_R2
00254 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_CALLBACK_PYTHON_H
00255 # include "callback_python.h"
00256 #endif
00257
00258 #endif // Guardian of Inclusion
00259
00260