Update contrib.
1 // (C) Copyright Gennadiy Rozental 2005.
2 // Use, modification, and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
8 // File : $RCSfile: callback.hpp,v $
10 // Version : $Revision: 1.7 $
13 // ***************************************************************************
15 #ifndef BOOST_TEST_CALLBACK_020505GER
16 #define BOOST_TEST_CALLBACK_020505GER
19 #include <boost/config.hpp>
20 #include <boost/detail/workaround.hpp>
21 #include <boost/shared_ptr.hpp>
23 #include <boost/test/detail/suppress_warnings.hpp>
25 #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(BOOST_INTEL, <= 700)
26 # define BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
29 //____________________________________________________________________________//
41 template<typename Functor>
42 R invoke( Functor& f ) { return f(); }
43 template<typename Functor, typename T1>
44 R invoke( Functor& f, T1 t1 ) { return f( t1 ); }
45 template<typename Functor, typename T1, typename T2>
46 R invoke( Functor& f, T1 t1, T2 t2 ) { return f( t1, t2 ); }
47 template<typename Functor, typename T1, typename T2, typename T3>
48 R invoke( Functor& f, T1 t1, T2 t2, T3 t3 ) { return f( t1, t2, t3 ); }
51 //____________________________________________________________________________//
54 struct invoker<unused> {
55 template<typename Functor>
56 unused invoke( Functor& f ) { f(); return unused(); }
57 template<typename Functor, typename T1>
58 unused invoke( Functor& f, T1 t1 ) { f( t1 ); return unused(); }
59 template<typename Functor, typename T1, typename T2>
60 unused invoke( Functor& f, T1 t1, T2 t2 ) { f( t1, t2 ); return unused(); }
61 template<typename Functor, typename T1, typename T2, typename T3>
62 unused invoke( Functor& f, T1 t1, T2 t2, T3 t3 ) { f( t1, t2, t3 ); return unused(); }
65 //____________________________________________________________________________//
67 } // namespace ut_detail
69 // ************************************************************************** //
70 // ************** unit_test::callback0 ************** //
71 // ************************************************************************** //
76 struct callback0_impl {
77 virtual ~callback0_impl() {}
79 virtual R invoke() = 0;
82 //____________________________________________________________________________//
84 template<typename R, typename Functor>
85 struct callback0_impl_t : callback0_impl<R> {
87 explicit callback0_impl_t( Functor f ) : m_f( f ) {}
89 virtual R invoke() { return invoker<R>().invoke( m_f ); }
96 //____________________________________________________________________________//
98 } // namespace ut_detail
100 template<typename R = ut_detail::unused>
105 #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
106 callback0( callback0 const& rhs ) : m_impl( rhs.m_impl ) {}
109 template<typename Functor>
110 callback0( Functor f )
111 : m_impl( new ut_detail::callback0_impl_t<R,Functor>( f ) ) {}
113 void operator=( callback0 const& rhs ) { m_impl = rhs.m_impl; }
115 template<typename Functor>
116 void operator=( Functor f ) { m_impl.reset( new ut_detail::callback0_impl_t<R,Functor>( f ) ); }
118 R operator()() const { return m_impl->invoke(); }
120 bool operator!() const { return !m_impl; }
124 boost::shared_ptr<ut_detail::callback0_impl<R> > m_impl;
127 // ************************************************************************** //
128 // ************** unit_test::callback1 ************** //
129 // ************************************************************************** //
131 namespace ut_detail {
133 template<typename R, typename T1>
134 struct callback1_impl {
135 virtual ~callback1_impl() {}
137 virtual R invoke( T1 t1 ) = 0;
140 //____________________________________________________________________________//
142 template<typename R, typename T1,typename Functor>
143 struct callback1_impl_t : callback1_impl<R,T1> {
145 explicit callback1_impl_t( Functor f ) : m_f( f ) {}
147 virtual R invoke( T1 t1 ) { return invoker<R>().invoke( m_f, t1 ); }
154 //____________________________________________________________________________//
156 } // namespace ut_detail
158 template<typename T1,typename R = ut_detail::unused>
163 #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
164 callback1( callback1 const& rhs ) : m_impl( rhs.m_impl ) {}
167 template<typename Functor>
168 callback1( Functor f )
169 : m_impl( new ut_detail::callback1_impl_t<R,T1,Functor>( f ) ) {}
171 void operator=( callback1 const& rhs ) { m_impl = rhs.m_impl; }
173 template<typename Functor>
174 void operator=( Functor f ) { m_impl.reset( new ut_detail::callback1_impl_t<R,T1,Functor>( f ) ); }
176 R operator()( T1 t1 ) const { return m_impl->invoke( t1 ); }
178 bool operator!() const { return !m_impl; }
182 boost::shared_ptr<ut_detail::callback1_impl<R,T1> > m_impl;
185 // ************************************************************************** //
186 // ************** unit_test::callback2 ************** //
187 // ************************************************************************** //
189 namespace ut_detail {
191 template<typename R, typename T1,typename T2>
192 struct callback2_impl {
193 virtual ~callback2_impl() {}
195 virtual R invoke( T1 t1, T2 t2 ) = 0;
198 //____________________________________________________________________________//
200 template<typename R, typename T1, typename T2, typename Functor>
201 struct callback2_impl_t : callback2_impl<R,T1,T2> {
203 explicit callback2_impl_t( Functor f ) : m_f( f ) {}
205 virtual R invoke( T1 t1, T2 t2 ) { return invoker<R>().template invoke<Functor,T1,T2>( m_f, t1, t2 ); }
212 //____________________________________________________________________________//
214 } // namespace ut_detail
216 template<typename T1,typename T2, typename R = ut_detail::unused>
221 #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
222 callback2( callback2 const& rhs ) : m_impl( rhs.m_impl ) {}
225 template<typename Functor>
226 callback2( Functor f ) : m_impl( new ut_detail::callback2_impl_t<R,T1,T2,Functor>( f ) ) {}
228 void operator=( callback2 const& rhs ) { m_impl = rhs.m_impl; }
230 template<typename Functor>
231 void operator=( Functor f ) { m_impl.reset( new ut_detail::callback2_impl_t<R,T1,T2,Functor>( f ) ); }
233 R operator()( T1 t1, T2 t2 ) const { return m_impl->invoke( t1, t2 ); }
235 bool operator!() const { return !m_impl; }
239 boost::shared_ptr<ut_detail::callback2_impl<R,T1,T2> > m_impl;
242 // ************************************************************************** //
243 // ************** unit_test::callback3 ************** //
244 // ************************************************************************** //
246 namespace ut_detail {
248 template<typename R, typename T1, typename T2, typename T3>
249 struct callback3_impl {
250 virtual ~callback3_impl() {}
252 virtual R invoke( T1 t1, T2 t2, T3 t3 ) = 0;
255 //____________________________________________________________________________//
257 template<typename R, typename T1, typename T2, typename T3, typename Functor>
258 struct callback3_impl_t : callback3_impl<R,T1,T2,T3> {
260 explicit callback3_impl_t( Functor f ) : m_f( f ) {}
262 virtual R invoke( T1 t1, T2 t2, T3 t3 ) { return invoker<R>().invoke( m_f, t1, t2, t3 ); }
269 //____________________________________________________________________________//
271 } // namespace ut_detail
273 template<typename T1,typename T2, typename T3, typename R = ut_detail::unused>
278 #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
279 callback3( callback3 const& rhs ) : m_impl( rhs.m_impl ) {}
282 template<typename Functor>
283 callback3( Functor f )
284 : m_impl( new ut_detail::callback3_impl_t<R,T1,T2,T3,Functor>( f ) ) {}
286 void operator=( callback3 const& rhs ) { m_impl = rhs.m_impl; }
288 template<typename Functor>
289 void operator=( Functor f ) { m_impl.reset( new ut_detail::callback3_impl_t<R,T1,T2,T3,Functor>( f ) ); }
291 R operator()( T1 t1, T2 t2, T3 t3 ) const { return m_impl->invoke( t1, t2, t3 ); }
293 bool operator!() const { return !m_impl; }
297 boost::shared_ptr<ut_detail::callback3_impl<R,T1,T2,T3> > m_impl;
300 } // namespace unit_test
304 #undef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
306 //____________________________________________________________________________//
308 #include <boost/test/detail/enable_warnings.hpp>
310 // ************************************************************************** //
313 // $Log: callback.hpp,v $
314 // Revision 1.7 2006/02/21 04:27:16 rogeeff
317 // Revision 1.6 2006/01/28 08:57:03 rogeeff
318 // VC6.0 workaround removed
320 // Revision 1.5 2005/04/13 05:09:00 rogeeff
323 // Revision 1.4 2005/04/12 06:50:06 rogeeff
326 // Revision 1.3 2005/03/22 07:05:18 rogeeff
327 // minor vc7.1 workaround
329 // Revision 1.2 2005/02/24 19:28:17 turkanis
330 // removed redundant copy ctors, except for VC6
332 // Revision 1.1 2005/02/20 08:27:08 rogeeff
333 // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
335 // ************************************************************************** //
337 #endif // BOOST_TEST_CALLBACK_020505GER