00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MOCKPP_TypelessStub_H
00032 #define MOCKPP_TypelessStub_H
00033
00034
00035 #include <mockpp/mockpp.h>
00036
00037 #include <mockpp/stub/Stub.h>
00038
00039 #include <mockpp/SelfDescribing.h>
00040
00041
00042 MOCKPP_NS_START
00043
00044
00049 template <typename R>
00050 class TypelessStub : public SelfDescribing
00051 {
00052 public:
00053
00054 typedef AutoPointer<TypelessStub<R> > AP;
00055
00058 virtual ~TypelessStub()
00059 {}
00060
00064 virtual R typelessInvoke() = 0;
00065
00070 virtual String describeTo( String &buffer ) const = 0;
00071 };
00072
00073
00077 template <typename R,
00078 typename I>
00079 class TypelessStubAdapterBase : public Stub<R, I>
00080 {
00081 protected:
00082
00087 TypelessStubAdapterBase(typename TypelessStub<R>::AP tm, bool in_delete)
00088 : stubber(tm.release())
00089 , do_delete(in_delete)
00090 {}
00091
00094 virtual ~TypelessStubAdapterBase()
00095 {
00096 if (do_delete)
00097 delete stubber;
00098 stubber = 0;
00099 }
00100
00101 public:
00102
00107 virtual String describeTo( String &buffer ) const
00108 {
00109 return stubber->describeTo(buffer);
00110 }
00111
00112 protected:
00113
00114 TypelessStub<R> *stubber;
00115 bool do_delete;
00116 };
00117
00118
00122 template <typename R,
00123 typename I>
00124 class TypelessStubAdapter : public TypelessStubAdapterBase<R, I>
00125 {
00126 public:
00127
00132 TypelessStubAdapter(typename TypelessStub<R>::AP tm, bool in_delete = true)
00133 : TypelessStubAdapterBase<R, I>(tm, in_delete)
00134 {}
00135
00140 virtual R invoke( const I &invocation )
00141 {
00142 MOCKPP_UNUSED(invocation);
00143 return this->stubber->typelessInvoke();
00144 }
00145 };
00146
00147
00148 #ifndef MOCKPP_PTI_WEAKNESS // Partial Template Instantiation Weakness
00149
00150
00155 template <typename I>
00156 class TypelessStubAdapter<void, I> : public TypelessStubAdapterBase<void, I>
00157 {
00158 public:
00159
00164 TypelessStubAdapter(typename TypelessStub<void>::AP tm, bool in_delete = true)
00165 : TypelessStubAdapterBase<void, I>(tm, in_delete)
00166 {}
00167
00171 virtual void invoke( const I &invocation )
00172 {
00173 MOCKPP_UNUSED(invocation);
00174 this->stubber->typelessInvoke();
00175 }
00176 };
00177
00178
00179 #define MOCKPP_TYPELESSSTUBADAPTER_PTI_IMPL(I)
00180 #define MOCKPP_TYPELESSSTUBADAPTER_PTI_DECL(I)
00181
00182
00183 #else // MOCKPP_PTI_WEAKNESS Partial Template Instantiation Weakness
00184
00185
00186 #define MOCKPP_TYPELESSSTUBADAPTER_PTI_DECL(I) \
00187 MOCKPP_NS_START \
00188 template<> \
00189 void MOCKPP_NS::TypelessStubAdapter<void, I >; \
00190 }
00191
00192
00193 #define MOCKPP_TYPELESSSTUBADAPTER_PTI_IMPL(I) \
00194 MOCKPP_NS_START \
00195 template<> \
00196 class TypelessStubAdapter<void, I > : public TypelessStubAdapterBase<void, I > \
00197 { \
00198 public: \
00199 TypelessStubAdapter<void, I >(TypelessStub<void>::AP tm, bool in_delete = true) \
00200 : TypelessStubAdapterBase<void, I >(tm, in_delete) \
00201 {} \
00202 \
00203 void invoke( const I &invocation) \
00204 { \
00205 MOCKPP_UNUSED(invocation); \
00206 this->stubber->typelessInvoke(); \
00207 } \
00208 }; \
00209 MOCKPP_NS_END
00210
00211
00212 #endif // MOCKPP_PTI_WEAKNESS
00213
00225 MOCKPP_NS_END
00226
00227
00228 #endif // MOCKPP_TypelessStub_H
00229