1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/test/utils/callback.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,337 @@
1.4 +// (C) Copyright Gennadiy Rozental 2005.
1.5 +// Use, modification, and distribution are subject to the
1.6 +// Boost Software License, Version 1.0. (See accompanying file
1.7 +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
1.8 +
1.9 +// See http://www.boost.org/libs/test for the library home page.
1.10 +//
1.11 +// File : $RCSfile: callback.hpp,v $
1.12 +//
1.13 +// Version : $Revision: 1.7 $
1.14 +//
1.15 +// Description :
1.16 +// ***************************************************************************
1.17 +
1.18 +#ifndef BOOST_TEST_CALLBACK_020505GER
1.19 +#define BOOST_TEST_CALLBACK_020505GER
1.20 +
1.21 +// Boost
1.22 +#include <boost/config.hpp>
1.23 +#include <boost/detail/workaround.hpp>
1.24 +#include <boost/shared_ptr.hpp>
1.25 +
1.26 +#include <boost/test/detail/suppress_warnings.hpp>
1.27 +
1.28 +#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(BOOST_INTEL, <= 700)
1.29 +# define BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
1.30 +#endif
1.31 +
1.32 +//____________________________________________________________________________//
1.33 +
1.34 +namespace boost {
1.35 +
1.36 +namespace unit_test {
1.37 +
1.38 +namespace ut_detail {
1.39 +
1.40 +struct unused {};
1.41 +
1.42 +template<typename R>
1.43 +struct invoker {
1.44 + template<typename Functor>
1.45 + R invoke( Functor& f ) { return f(); }
1.46 + template<typename Functor, typename T1>
1.47 + R invoke( Functor& f, T1 t1 ) { return f( t1 ); }
1.48 + template<typename Functor, typename T1, typename T2>
1.49 + R invoke( Functor& f, T1 t1, T2 t2 ) { return f( t1, t2 ); }
1.50 + template<typename Functor, typename T1, typename T2, typename T3>
1.51 + R invoke( Functor& f, T1 t1, T2 t2, T3 t3 ) { return f( t1, t2, t3 ); }
1.52 +};
1.53 +
1.54 +//____________________________________________________________________________//
1.55 +
1.56 +template<>
1.57 +struct invoker<unused> {
1.58 + template<typename Functor>
1.59 + unused invoke( Functor& f ) { f(); return unused(); }
1.60 + template<typename Functor, typename T1>
1.61 + unused invoke( Functor& f, T1 t1 ) { f( t1 ); return unused(); }
1.62 + template<typename Functor, typename T1, typename T2>
1.63 + unused invoke( Functor& f, T1 t1, T2 t2 ) { f( t1, t2 ); return unused(); }
1.64 + template<typename Functor, typename T1, typename T2, typename T3>
1.65 + unused invoke( Functor& f, T1 t1, T2 t2, T3 t3 ) { f( t1, t2, t3 ); return unused(); }
1.66 +};
1.67 +
1.68 +//____________________________________________________________________________//
1.69 +
1.70 +} // namespace ut_detail
1.71 +
1.72 +// ************************************************************************** //
1.73 +// ************** unit_test::callback0 ************** //
1.74 +// ************************************************************************** //
1.75 +
1.76 +namespace ut_detail {
1.77 +
1.78 +template<typename R>
1.79 +struct callback0_impl {
1.80 + virtual ~callback0_impl() {}
1.81 +
1.82 + virtual R invoke() = 0;
1.83 +};
1.84 +
1.85 +//____________________________________________________________________________//
1.86 +
1.87 +template<typename R, typename Functor>
1.88 +struct callback0_impl_t : callback0_impl<R> {
1.89 + // Constructor
1.90 + explicit callback0_impl_t( Functor f ) : m_f( f ) {}
1.91 +
1.92 + virtual R invoke() { return invoker<R>().invoke( m_f ); }
1.93 +
1.94 +private:
1.95 + // Data members
1.96 + Functor m_f;
1.97 +};
1.98 +
1.99 +//____________________________________________________________________________//
1.100 +
1.101 +} // namespace ut_detail
1.102 +
1.103 +template<typename R = ut_detail::unused>
1.104 +class callback0 {
1.105 +public:
1.106 + // Constructors
1.107 + callback0() {}
1.108 +#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
1.109 + callback0( callback0 const& rhs ) : m_impl( rhs.m_impl ) {}
1.110 +#endif
1.111 +
1.112 + template<typename Functor>
1.113 + callback0( Functor f )
1.114 + : m_impl( new ut_detail::callback0_impl_t<R,Functor>( f ) ) {}
1.115 +
1.116 + void operator=( callback0 const& rhs ) { m_impl = rhs.m_impl; }
1.117 +
1.118 + template<typename Functor>
1.119 + void operator=( Functor f ) { m_impl.reset( new ut_detail::callback0_impl_t<R,Functor>( f ) ); }
1.120 +
1.121 + R operator()() const { return m_impl->invoke(); }
1.122 +
1.123 + bool operator!() const { return !m_impl; }
1.124 +
1.125 +private:
1.126 + // Data members
1.127 + boost::shared_ptr<ut_detail::callback0_impl<R> > m_impl;
1.128 +};
1.129 +
1.130 +// ************************************************************************** //
1.131 +// ************** unit_test::callback1 ************** //
1.132 +// ************************************************************************** //
1.133 +
1.134 +namespace ut_detail {
1.135 +
1.136 +template<typename R, typename T1>
1.137 +struct callback1_impl {
1.138 + virtual ~callback1_impl() {}
1.139 +
1.140 + virtual R invoke( T1 t1 ) = 0;
1.141 +};
1.142 +
1.143 +//____________________________________________________________________________//
1.144 +
1.145 +template<typename R, typename T1,typename Functor>
1.146 +struct callback1_impl_t : callback1_impl<R,T1> {
1.147 + // Constructor
1.148 + explicit callback1_impl_t( Functor f ) : m_f( f ) {}
1.149 +
1.150 + virtual R invoke( T1 t1 ) { return invoker<R>().invoke( m_f, t1 ); }
1.151 +
1.152 +private:
1.153 + // Data members
1.154 + Functor m_f;
1.155 +};
1.156 +
1.157 +//____________________________________________________________________________//
1.158 +
1.159 +} // namespace ut_detail
1.160 +
1.161 +template<typename T1,typename R = ut_detail::unused>
1.162 +class callback1 {
1.163 +public:
1.164 + // Constructors
1.165 + callback1() {}
1.166 +#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
1.167 + callback1( callback1 const& rhs ) : m_impl( rhs.m_impl ) {}
1.168 +#endif
1.169 +
1.170 + template<typename Functor>
1.171 + callback1( Functor f )
1.172 + : m_impl( new ut_detail::callback1_impl_t<R,T1,Functor>( f ) ) {}
1.173 +
1.174 + void operator=( callback1 const& rhs ) { m_impl = rhs.m_impl; }
1.175 +
1.176 + template<typename Functor>
1.177 + void operator=( Functor f ) { m_impl.reset( new ut_detail::callback1_impl_t<R,T1,Functor>( f ) ); }
1.178 +
1.179 + R operator()( T1 t1 ) const { return m_impl->invoke( t1 ); }
1.180 +
1.181 + bool operator!() const { return !m_impl; }
1.182 +
1.183 +private:
1.184 + // Data members
1.185 + boost::shared_ptr<ut_detail::callback1_impl<R,T1> > m_impl;
1.186 +};
1.187 +
1.188 +// ************************************************************************** //
1.189 +// ************** unit_test::callback2 ************** //
1.190 +// ************************************************************************** //
1.191 +
1.192 +namespace ut_detail {
1.193 +
1.194 +template<typename R, typename T1,typename T2>
1.195 +struct callback2_impl {
1.196 + virtual ~callback2_impl() {}
1.197 +
1.198 + virtual R invoke( T1 t1, T2 t2 ) = 0;
1.199 +};
1.200 +
1.201 +//____________________________________________________________________________//
1.202 +
1.203 +template<typename R, typename T1, typename T2, typename Functor>
1.204 +struct callback2_impl_t : callback2_impl<R,T1,T2> {
1.205 + // Constructor
1.206 + explicit callback2_impl_t( Functor f ) : m_f( f ) {}
1.207 +
1.208 + virtual R invoke( T1 t1, T2 t2 ) { return invoker<R>().template invoke<Functor,T1,T2>( m_f, t1, t2 ); }
1.209 +
1.210 +private:
1.211 + // Data members
1.212 + Functor m_f;
1.213 +};
1.214 +
1.215 +//____________________________________________________________________________//
1.216 +
1.217 +} // namespace ut_detail
1.218 +
1.219 +template<typename T1,typename T2, typename R = ut_detail::unused>
1.220 +class callback2 {
1.221 +public:
1.222 + // Constructors
1.223 + callback2() {}
1.224 +#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
1.225 + callback2( callback2 const& rhs ) : m_impl( rhs.m_impl ) {}
1.226 +#endif
1.227 +
1.228 + template<typename Functor>
1.229 + callback2( Functor f ) : m_impl( new ut_detail::callback2_impl_t<R,T1,T2,Functor>( f ) ) {}
1.230 +
1.231 + void operator=( callback2 const& rhs ) { m_impl = rhs.m_impl; }
1.232 +
1.233 + template<typename Functor>
1.234 + void operator=( Functor f ) { m_impl.reset( new ut_detail::callback2_impl_t<R,T1,T2,Functor>( f ) ); }
1.235 +
1.236 + R operator()( T1 t1, T2 t2 ) const { return m_impl->invoke( t1, t2 ); }
1.237 +
1.238 + bool operator!() const { return !m_impl; }
1.239 +
1.240 +private:
1.241 + // Data members
1.242 + boost::shared_ptr<ut_detail::callback2_impl<R,T1,T2> > m_impl;
1.243 +};
1.244 +
1.245 +// ************************************************************************** //
1.246 +// ************** unit_test::callback3 ************** //
1.247 +// ************************************************************************** //
1.248 +
1.249 +namespace ut_detail {
1.250 +
1.251 +template<typename R, typename T1, typename T2, typename T3>
1.252 +struct callback3_impl {
1.253 + virtual ~callback3_impl() {}
1.254 +
1.255 + virtual R invoke( T1 t1, T2 t2, T3 t3 ) = 0;
1.256 +};
1.257 +
1.258 +//____________________________________________________________________________//
1.259 +
1.260 +template<typename R, typename T1, typename T2, typename T3, typename Functor>
1.261 +struct callback3_impl_t : callback3_impl<R,T1,T2,T3> {
1.262 + // Constructor
1.263 + explicit callback3_impl_t( Functor f ) : m_f( f ) {}
1.264 +
1.265 + virtual R invoke( T1 t1, T2 t2, T3 t3 ) { return invoker<R>().invoke( m_f, t1, t2, t3 ); }
1.266 +
1.267 +private:
1.268 + // Data members
1.269 + Functor m_f;
1.270 +};
1.271 +
1.272 +//____________________________________________________________________________//
1.273 +
1.274 +} // namespace ut_detail
1.275 +
1.276 +template<typename T1,typename T2, typename T3, typename R = ut_detail::unused>
1.277 +class callback3 {
1.278 +public:
1.279 + // Constructors
1.280 + callback3() {}
1.281 +#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
1.282 + callback3( callback3 const& rhs ) : m_impl( rhs.m_impl ) {}
1.283 +#endif
1.284 +
1.285 + template<typename Functor>
1.286 + callback3( Functor f )
1.287 + : m_impl( new ut_detail::callback3_impl_t<R,T1,T2,T3,Functor>( f ) ) {}
1.288 +
1.289 + void operator=( callback3 const& rhs ) { m_impl = rhs.m_impl; }
1.290 +
1.291 + template<typename Functor>
1.292 + void operator=( Functor f ) { m_impl.reset( new ut_detail::callback3_impl_t<R,T1,T2,T3,Functor>( f ) ); }
1.293 +
1.294 + R operator()( T1 t1, T2 t2, T3 t3 ) const { return m_impl->invoke( t1, t2, t3 ); }
1.295 +
1.296 + bool operator!() const { return !m_impl; }
1.297 +
1.298 +private:
1.299 + // Data members
1.300 + boost::shared_ptr<ut_detail::callback3_impl<R,T1,T2,T3> > m_impl;
1.301 +};
1.302 +
1.303 +} // namespace unit_test
1.304 +
1.305 +} // namespace boost
1.306 +
1.307 +#undef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
1.308 +
1.309 +//____________________________________________________________________________//
1.310 +
1.311 +#include <boost/test/detail/enable_warnings.hpp>
1.312 +
1.313 +// ************************************************************************** //
1.314 +// Revision History:
1.315 +//
1.316 +// $Log: callback.hpp,v $
1.317 +// Revision 1.7 2006/02/21 04:27:16 rogeeff
1.318 +// rev back
1.319 +//
1.320 +// Revision 1.6 2006/01/28 08:57:03 rogeeff
1.321 +// VC6.0 workaround removed
1.322 +//
1.323 +// Revision 1.5 2005/04/13 05:09:00 rogeeff
1.324 +// Intel 7.1 bug fix
1.325 +//
1.326 +// Revision 1.4 2005/04/12 06:50:06 rogeeff
1.327 +// suppress warnings
1.328 +//
1.329 +// Revision 1.3 2005/03/22 07:05:18 rogeeff
1.330 +// minor vc7.1 workaround
1.331 +//
1.332 +// Revision 1.2 2005/02/24 19:28:17 turkanis
1.333 +// removed redundant copy ctors, except for VC6
1.334 +//
1.335 +// Revision 1.1 2005/02/20 08:27:08 rogeeff
1.336 +// This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
1.337 +//
1.338 +// ************************************************************************** //
1.339 +
1.340 +#endif // BOOST_TEST_CALLBACK_020505GER