sl@0: // (C) Copyright Gennadiy Rozental 2005. sl@0: // Use, modification, and distribution are subject to the sl@0: // Boost Software License, Version 1.0. (See accompanying file sl@0: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org/libs/test for the library home page. sl@0: // sl@0: // File : $RCSfile: callback.hpp,v $ sl@0: // sl@0: // Version : $Revision: 1.7 $ sl@0: // sl@0: // Description : sl@0: // *************************************************************************** sl@0: sl@0: #ifndef BOOST_TEST_CALLBACK_020505GER sl@0: #define BOOST_TEST_CALLBACK_020505GER sl@0: sl@0: // Boost sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: sl@0: #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(BOOST_INTEL, <= 700) sl@0: # define BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR sl@0: #endif sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: namespace boost { sl@0: sl@0: namespace unit_test { sl@0: sl@0: namespace ut_detail { sl@0: sl@0: struct unused {}; sl@0: sl@0: template sl@0: struct invoker { sl@0: template sl@0: R invoke( Functor& f ) { return f(); } sl@0: template sl@0: R invoke( Functor& f, T1 t1 ) { return f( t1 ); } sl@0: template sl@0: R invoke( Functor& f, T1 t1, T2 t2 ) { return f( t1, t2 ); } sl@0: template sl@0: R invoke( Functor& f, T1 t1, T2 t2, T3 t3 ) { return f( t1, t2, t3 ); } sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template<> sl@0: struct invoker { sl@0: template sl@0: unused invoke( Functor& f ) { f(); return unused(); } sl@0: template sl@0: unused invoke( Functor& f, T1 t1 ) { f( t1 ); return unused(); } sl@0: template sl@0: unused invoke( Functor& f, T1 t1, T2 t2 ) { f( t1, t2 ); return unused(); } sl@0: template sl@0: unused invoke( Functor& f, T1 t1, T2 t2, T3 t3 ) { f( t1, t2, t3 ); return unused(); } sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace ut_detail sl@0: sl@0: // ************************************************************************** // sl@0: // ************** unit_test::callback0 ************** // sl@0: // ************************************************************************** // sl@0: sl@0: namespace ut_detail { sl@0: sl@0: template sl@0: struct callback0_impl { sl@0: virtual ~callback0_impl() {} sl@0: sl@0: virtual R invoke() = 0; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: struct callback0_impl_t : callback0_impl { sl@0: // Constructor sl@0: explicit callback0_impl_t( Functor f ) : m_f( f ) {} sl@0: sl@0: virtual R invoke() { return invoker().invoke( m_f ); } sl@0: sl@0: private: sl@0: // Data members sl@0: Functor m_f; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace ut_detail sl@0: sl@0: template sl@0: class callback0 { sl@0: public: sl@0: // Constructors sl@0: callback0() {} sl@0: #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR sl@0: callback0( callback0 const& rhs ) : m_impl( rhs.m_impl ) {} sl@0: #endif sl@0: sl@0: template sl@0: callback0( Functor f ) sl@0: : m_impl( new ut_detail::callback0_impl_t( f ) ) {} sl@0: sl@0: void operator=( callback0 const& rhs ) { m_impl = rhs.m_impl; } sl@0: sl@0: template sl@0: void operator=( Functor f ) { m_impl.reset( new ut_detail::callback0_impl_t( f ) ); } sl@0: sl@0: R operator()() const { return m_impl->invoke(); } sl@0: sl@0: bool operator!() const { return !m_impl; } sl@0: sl@0: private: sl@0: // Data members sl@0: boost::shared_ptr > m_impl; sl@0: }; sl@0: sl@0: // ************************************************************************** // sl@0: // ************** unit_test::callback1 ************** // sl@0: // ************************************************************************** // sl@0: sl@0: namespace ut_detail { sl@0: sl@0: template sl@0: struct callback1_impl { sl@0: virtual ~callback1_impl() {} sl@0: sl@0: virtual R invoke( T1 t1 ) = 0; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: struct callback1_impl_t : callback1_impl { sl@0: // Constructor sl@0: explicit callback1_impl_t( Functor f ) : m_f( f ) {} sl@0: sl@0: virtual R invoke( T1 t1 ) { return invoker().invoke( m_f, t1 ); } sl@0: sl@0: private: sl@0: // Data members sl@0: Functor m_f; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace ut_detail sl@0: sl@0: template sl@0: class callback1 { sl@0: public: sl@0: // Constructors sl@0: callback1() {} sl@0: #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR sl@0: callback1( callback1 const& rhs ) : m_impl( rhs.m_impl ) {} sl@0: #endif sl@0: sl@0: template sl@0: callback1( Functor f ) sl@0: : m_impl( new ut_detail::callback1_impl_t( f ) ) {} sl@0: sl@0: void operator=( callback1 const& rhs ) { m_impl = rhs.m_impl; } sl@0: sl@0: template sl@0: void operator=( Functor f ) { m_impl.reset( new ut_detail::callback1_impl_t( f ) ); } sl@0: sl@0: R operator()( T1 t1 ) const { return m_impl->invoke( t1 ); } sl@0: sl@0: bool operator!() const { return !m_impl; } sl@0: sl@0: private: sl@0: // Data members sl@0: boost::shared_ptr > m_impl; sl@0: }; sl@0: sl@0: // ************************************************************************** // sl@0: // ************** unit_test::callback2 ************** // sl@0: // ************************************************************************** // sl@0: sl@0: namespace ut_detail { sl@0: sl@0: template sl@0: struct callback2_impl { sl@0: virtual ~callback2_impl() {} sl@0: sl@0: virtual R invoke( T1 t1, T2 t2 ) = 0; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: struct callback2_impl_t : callback2_impl { sl@0: // Constructor sl@0: explicit callback2_impl_t( Functor f ) : m_f( f ) {} sl@0: sl@0: virtual R invoke( T1 t1, T2 t2 ) { return invoker().template invoke( m_f, t1, t2 ); } sl@0: sl@0: private: sl@0: // Data members sl@0: Functor m_f; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace ut_detail sl@0: sl@0: template sl@0: class callback2 { sl@0: public: sl@0: // Constructors sl@0: callback2() {} sl@0: #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR sl@0: callback2( callback2 const& rhs ) : m_impl( rhs.m_impl ) {} sl@0: #endif sl@0: sl@0: template sl@0: callback2( Functor f ) : m_impl( new ut_detail::callback2_impl_t( f ) ) {} sl@0: sl@0: void operator=( callback2 const& rhs ) { m_impl = rhs.m_impl; } sl@0: sl@0: template sl@0: void operator=( Functor f ) { m_impl.reset( new ut_detail::callback2_impl_t( f ) ); } sl@0: sl@0: R operator()( T1 t1, T2 t2 ) const { return m_impl->invoke( t1, t2 ); } sl@0: sl@0: bool operator!() const { return !m_impl; } sl@0: sl@0: private: sl@0: // Data members sl@0: boost::shared_ptr > m_impl; sl@0: }; sl@0: sl@0: // ************************************************************************** // sl@0: // ************** unit_test::callback3 ************** // sl@0: // ************************************************************************** // sl@0: sl@0: namespace ut_detail { sl@0: sl@0: template sl@0: struct callback3_impl { sl@0: virtual ~callback3_impl() {} sl@0: sl@0: virtual R invoke( T1 t1, T2 t2, T3 t3 ) = 0; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: struct callback3_impl_t : callback3_impl { sl@0: // Constructor sl@0: explicit callback3_impl_t( Functor f ) : m_f( f ) {} sl@0: sl@0: virtual R invoke( T1 t1, T2 t2, T3 t3 ) { return invoker().invoke( m_f, t1, t2, t3 ); } sl@0: sl@0: private: sl@0: // Data members sl@0: Functor m_f; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace ut_detail sl@0: sl@0: template sl@0: class callback3 { sl@0: public: sl@0: // Constructors sl@0: callback3() {} sl@0: #ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR sl@0: callback3( callback3 const& rhs ) : m_impl( rhs.m_impl ) {} sl@0: #endif sl@0: sl@0: template sl@0: callback3( Functor f ) sl@0: : m_impl( new ut_detail::callback3_impl_t( f ) ) {} sl@0: sl@0: void operator=( callback3 const& rhs ) { m_impl = rhs.m_impl; } sl@0: sl@0: template sl@0: void operator=( Functor f ) { m_impl.reset( new ut_detail::callback3_impl_t( f ) ); } sl@0: sl@0: R operator()( T1 t1, T2 t2, T3 t3 ) const { return m_impl->invoke( t1, t2, t3 ); } sl@0: sl@0: bool operator!() const { return !m_impl; } sl@0: sl@0: private: sl@0: // Data members sl@0: boost::shared_ptr > m_impl; sl@0: }; sl@0: sl@0: } // namespace unit_test sl@0: sl@0: } // namespace boost sl@0: sl@0: #undef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #include sl@0: sl@0: // ************************************************************************** // sl@0: // Revision History: sl@0: // sl@0: // $Log: callback.hpp,v $ sl@0: // Revision 1.7 2006/02/21 04:27:16 rogeeff sl@0: // rev back sl@0: // sl@0: // Revision 1.6 2006/01/28 08:57:03 rogeeff sl@0: // VC6.0 workaround removed sl@0: // sl@0: // Revision 1.5 2005/04/13 05:09:00 rogeeff sl@0: // Intel 7.1 bug fix sl@0: // sl@0: // Revision 1.4 2005/04/12 06:50:06 rogeeff sl@0: // suppress warnings sl@0: // sl@0: // Revision 1.3 2005/03/22 07:05:18 rogeeff sl@0: // minor vc7.1 workaround sl@0: // sl@0: // Revision 1.2 2005/02/24 19:28:17 turkanis sl@0: // removed redundant copy ctors, except for VC6 sl@0: // sl@0: // Revision 1.1 2005/02/20 08:27:08 rogeeff sl@0: // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates sl@0: // sl@0: // ************************************************************************** // sl@0: sl@0: #endif // BOOST_TEST_CALLBACK_020505GER