os/ossrv/ossrv_pub/boost_apis/boost/test/utils/callback.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
//  (C) Copyright Gennadiy Rozental 2005.
sl@0
     2
//  Use, modification, and distribution are subject to the 
sl@0
     3
//  Boost Software License, Version 1.0. (See accompanying file 
sl@0
     4
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     5
sl@0
     6
//  See http://www.boost.org/libs/test for the library home page.
sl@0
     7
//
sl@0
     8
//  File        : $RCSfile: callback.hpp,v $
sl@0
     9
//
sl@0
    10
//  Version     : $Revision: 1.7 $
sl@0
    11
//
sl@0
    12
//  Description : 
sl@0
    13
// ***************************************************************************
sl@0
    14
sl@0
    15
#ifndef BOOST_TEST_CALLBACK_020505GER
sl@0
    16
#define BOOST_TEST_CALLBACK_020505GER
sl@0
    17
sl@0
    18
// Boost
sl@0
    19
#include <boost/config.hpp>
sl@0
    20
#include <boost/detail/workaround.hpp>
sl@0
    21
#include <boost/shared_ptr.hpp>
sl@0
    22
sl@0
    23
#include <boost/test/detail/suppress_warnings.hpp>
sl@0
    24
sl@0
    25
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(BOOST_INTEL, <= 700)
sl@0
    26
#  define BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
sl@0
    27
#endif
sl@0
    28
sl@0
    29
//____________________________________________________________________________//
sl@0
    30
sl@0
    31
namespace boost {
sl@0
    32
sl@0
    33
namespace unit_test {
sl@0
    34
sl@0
    35
namespace ut_detail {
sl@0
    36
sl@0
    37
struct unused {};
sl@0
    38
sl@0
    39
template<typename R>
sl@0
    40
struct invoker {
sl@0
    41
    template<typename Functor>
sl@0
    42
    R       invoke( Functor& f )                        { return f(); }
sl@0
    43
    template<typename Functor, typename T1>
sl@0
    44
    R       invoke( Functor& f, T1 t1 )                 { return f( t1 ); }
sl@0
    45
    template<typename Functor, typename T1, typename T2>
sl@0
    46
    R       invoke( Functor& f, T1 t1, T2 t2 )          { return f( t1, t2 ); }
sl@0
    47
    template<typename Functor, typename T1, typename T2, typename T3>
sl@0
    48
    R       invoke( Functor& f, T1 t1, T2 t2, T3 t3 )   { return f( t1, t2, t3 ); }
sl@0
    49
};
sl@0
    50
sl@0
    51
//____________________________________________________________________________//
sl@0
    52
sl@0
    53
template<>
sl@0
    54
struct invoker<unused> {
sl@0
    55
    template<typename Functor>
sl@0
    56
    unused  invoke( Functor& f )                        { f(); return unused(); }
sl@0
    57
    template<typename Functor, typename T1>
sl@0
    58
    unused  invoke( Functor& f, T1 t1 )                 { f( t1 ); return unused(); }
sl@0
    59
    template<typename Functor, typename T1, typename T2>
sl@0
    60
    unused  invoke( Functor& f, T1 t1, T2 t2 )          { f( t1, t2 ); return unused(); }
sl@0
    61
    template<typename Functor, typename T1, typename T2, typename T3>
sl@0
    62
    unused  invoke( Functor& f, T1 t1, T2 t2, T3 t3 )   { f( t1, t2, t3 ); return unused(); }
sl@0
    63
};
sl@0
    64
sl@0
    65
//____________________________________________________________________________//
sl@0
    66
sl@0
    67
} // namespace ut_detail
sl@0
    68
sl@0
    69
// ************************************************************************** //
sl@0
    70
// **************             unit_test::callback0             ************** //
sl@0
    71
// ************************************************************************** //
sl@0
    72
sl@0
    73
namespace ut_detail {
sl@0
    74
sl@0
    75
template<typename R>
sl@0
    76
struct callback0_impl {
sl@0
    77
    virtual ~callback0_impl() {}
sl@0
    78
sl@0
    79
    virtual R invoke() = 0;
sl@0
    80
};
sl@0
    81
sl@0
    82
//____________________________________________________________________________//
sl@0
    83
sl@0
    84
template<typename R, typename Functor>
sl@0
    85
struct callback0_impl_t : callback0_impl<R> {
sl@0
    86
    // Constructor
sl@0
    87
    explicit callback0_impl_t( Functor f ) : m_f( f ) {}
sl@0
    88
sl@0
    89
    virtual R invoke() { return invoker<R>().invoke( m_f ); }
sl@0
    90
sl@0
    91
private:
sl@0
    92
    // Data members
sl@0
    93
    Functor m_f;
sl@0
    94
};
sl@0
    95
sl@0
    96
//____________________________________________________________________________//
sl@0
    97
sl@0
    98
} // namespace ut_detail
sl@0
    99
sl@0
   100
template<typename R = ut_detail::unused>
sl@0
   101
class callback0 {
sl@0
   102
public:
sl@0
   103
    // Constructors
sl@0
   104
    callback0() {}
sl@0
   105
#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
sl@0
   106
    callback0( callback0 const& rhs ) : m_impl( rhs.m_impl ) {}
sl@0
   107
#endif
sl@0
   108
sl@0
   109
    template<typename Functor>
sl@0
   110
    callback0( Functor f )
sl@0
   111
    : m_impl( new ut_detail::callback0_impl_t<R,Functor>( f ) ) {}
sl@0
   112
    
sl@0
   113
    void        operator=( callback0 const& rhs ) { m_impl = rhs.m_impl; }
sl@0
   114
sl@0
   115
    template<typename Functor>
sl@0
   116
    void        operator=( Functor f ) { m_impl.reset( new ut_detail::callback0_impl_t<R,Functor>( f ) );  }
sl@0
   117
sl@0
   118
    R           operator()() const { return m_impl->invoke(); }
sl@0
   119
sl@0
   120
    bool        operator!() const { return !m_impl; }
sl@0
   121
sl@0
   122
private:
sl@0
   123
    // Data members
sl@0
   124
    boost::shared_ptr<ut_detail::callback0_impl<R> > m_impl;
sl@0
   125
};
sl@0
   126
sl@0
   127
// ************************************************************************** //
sl@0
   128
// **************             unit_test::callback1             ************** //
sl@0
   129
// ************************************************************************** //
sl@0
   130
sl@0
   131
namespace ut_detail {
sl@0
   132
sl@0
   133
template<typename R, typename T1>
sl@0
   134
struct callback1_impl {
sl@0
   135
    virtual ~callback1_impl() {}
sl@0
   136
sl@0
   137
    virtual R invoke( T1 t1 ) = 0;
sl@0
   138
};
sl@0
   139
sl@0
   140
//____________________________________________________________________________//
sl@0
   141
sl@0
   142
template<typename R, typename T1,typename Functor>
sl@0
   143
struct callback1_impl_t : callback1_impl<R,T1> {
sl@0
   144
    // Constructor
sl@0
   145
    explicit callback1_impl_t( Functor f ) : m_f( f ) {}
sl@0
   146
sl@0
   147
    virtual R invoke( T1 t1 ) { return invoker<R>().invoke( m_f, t1 ); }
sl@0
   148
sl@0
   149
private:
sl@0
   150
    // Data members
sl@0
   151
    Functor m_f;
sl@0
   152
};
sl@0
   153
sl@0
   154
//____________________________________________________________________________//
sl@0
   155
sl@0
   156
} // namespace ut_detail
sl@0
   157
sl@0
   158
template<typename T1,typename R = ut_detail::unused>
sl@0
   159
class callback1 {
sl@0
   160
public:
sl@0
   161
    // Constructors
sl@0
   162
    callback1() {}
sl@0
   163
#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
sl@0
   164
    callback1( callback1 const& rhs ) : m_impl( rhs.m_impl ) {}
sl@0
   165
#endif
sl@0
   166
sl@0
   167
    template<typename Functor>
sl@0
   168
    callback1( Functor f )
sl@0
   169
    : m_impl( new ut_detail::callback1_impl_t<R,T1,Functor>( f ) ) {}
sl@0
   170
sl@0
   171
    void        operator=( callback1 const& rhs ) { m_impl = rhs.m_impl; }
sl@0
   172
sl@0
   173
    template<typename Functor>
sl@0
   174
    void        operator=( Functor f ) { m_impl.reset( new ut_detail::callback1_impl_t<R,T1,Functor>( f ) );  }
sl@0
   175
sl@0
   176
    R           operator()( T1 t1 ) const { return m_impl->invoke( t1 ); }
sl@0
   177
sl@0
   178
    bool        operator!() const { return !m_impl; }
sl@0
   179
sl@0
   180
private:
sl@0
   181
    // Data members
sl@0
   182
    boost::shared_ptr<ut_detail::callback1_impl<R,T1> > m_impl;
sl@0
   183
};
sl@0
   184
sl@0
   185
// ************************************************************************** //
sl@0
   186
// **************             unit_test::callback2             ************** //
sl@0
   187
// ************************************************************************** //
sl@0
   188
sl@0
   189
namespace ut_detail {
sl@0
   190
sl@0
   191
template<typename R, typename T1,typename T2>
sl@0
   192
struct callback2_impl {
sl@0
   193
    virtual ~callback2_impl() {}
sl@0
   194
sl@0
   195
    virtual R invoke( T1 t1, T2 t2 ) = 0;
sl@0
   196
};
sl@0
   197
sl@0
   198
//____________________________________________________________________________//
sl@0
   199
sl@0
   200
template<typename R, typename T1, typename T2, typename Functor>
sl@0
   201
struct callback2_impl_t : callback2_impl<R,T1,T2> {
sl@0
   202
    // Constructor
sl@0
   203
    explicit callback2_impl_t( Functor f ) : m_f( f ) {}
sl@0
   204
sl@0
   205
    virtual R invoke( T1 t1, T2 t2 ) { return invoker<R>().template invoke<Functor,T1,T2>( m_f, t1, t2 ); }
sl@0
   206
sl@0
   207
private:
sl@0
   208
    // Data members
sl@0
   209
    Functor m_f;
sl@0
   210
};
sl@0
   211
sl@0
   212
//____________________________________________________________________________//
sl@0
   213
sl@0
   214
} // namespace ut_detail
sl@0
   215
sl@0
   216
template<typename T1,typename T2, typename R = ut_detail::unused>
sl@0
   217
class callback2 {
sl@0
   218
public:
sl@0
   219
    // Constructors
sl@0
   220
    callback2() {}
sl@0
   221
#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
sl@0
   222
    callback2( callback2 const& rhs ) : m_impl( rhs.m_impl ) {}
sl@0
   223
#endif
sl@0
   224
sl@0
   225
    template<typename Functor>
sl@0
   226
                callback2( Functor f ) : m_impl( new ut_detail::callback2_impl_t<R,T1,T2,Functor>( f ) ) {}
sl@0
   227
sl@0
   228
    void        operator=( callback2 const& rhs ) { m_impl = rhs.m_impl; }
sl@0
   229
sl@0
   230
    template<typename Functor>
sl@0
   231
    void        operator=( Functor f ) { m_impl.reset( new ut_detail::callback2_impl_t<R,T1,T2,Functor>( f ) );  }
sl@0
   232
sl@0
   233
    R           operator()( T1 t1, T2 t2 ) const { return m_impl->invoke( t1, t2 ); }
sl@0
   234
sl@0
   235
    bool        operator!() const { return !m_impl; }
sl@0
   236
sl@0
   237
private:
sl@0
   238
    // Data members
sl@0
   239
    boost::shared_ptr<ut_detail::callback2_impl<R,T1,T2> > m_impl;
sl@0
   240
};
sl@0
   241
sl@0
   242
// ************************************************************************** //
sl@0
   243
// **************             unit_test::callback3             ************** //
sl@0
   244
// ************************************************************************** //
sl@0
   245
sl@0
   246
namespace ut_detail {
sl@0
   247
sl@0
   248
template<typename R, typename T1, typename T2, typename T3>
sl@0
   249
struct callback3_impl {
sl@0
   250
    virtual ~callback3_impl() {}
sl@0
   251
sl@0
   252
    virtual R invoke( T1 t1, T2 t2, T3 t3 ) = 0;
sl@0
   253
};
sl@0
   254
sl@0
   255
//____________________________________________________________________________//
sl@0
   256
sl@0
   257
template<typename R, typename T1, typename T2, typename T3, typename Functor>
sl@0
   258
struct callback3_impl_t : callback3_impl<R,T1,T2,T3> {
sl@0
   259
    // Constructor
sl@0
   260
    explicit callback3_impl_t( Functor f ) : m_f( f ) {}
sl@0
   261
sl@0
   262
    virtual R invoke( T1 t1, T2 t2, T3 t3 ) { return invoker<R>().invoke( m_f, t1, t2, t3 ); }
sl@0
   263
sl@0
   264
private:
sl@0
   265
    // Data members
sl@0
   266
    Functor m_f;
sl@0
   267
};
sl@0
   268
sl@0
   269
//____________________________________________________________________________//
sl@0
   270
sl@0
   271
} // namespace ut_detail
sl@0
   272
sl@0
   273
template<typename T1,typename T2, typename T3, typename R = ut_detail::unused>
sl@0
   274
class callback3 {
sl@0
   275
public:
sl@0
   276
    // Constructors
sl@0
   277
    callback3() {}
sl@0
   278
#ifdef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
sl@0
   279
    callback3( callback3 const& rhs ) : m_impl( rhs.m_impl ) {}
sl@0
   280
#endif
sl@0
   281
sl@0
   282
    template<typename Functor>
sl@0
   283
    callback3( Functor f )
sl@0
   284
    : m_impl( new ut_detail::callback3_impl_t<R,T1,T2,T3,Functor>( f ) ) {}
sl@0
   285
sl@0
   286
    void        operator=( callback3 const& rhs ) { m_impl = rhs.m_impl; }
sl@0
   287
sl@0
   288
    template<typename Functor>
sl@0
   289
    void        operator=( Functor f ) { m_impl.reset( new ut_detail::callback3_impl_t<R,T1,T2,T3,Functor>( f ) );  }
sl@0
   290
sl@0
   291
    R           operator()( T1 t1, T2 t2, T3 t3 ) const { return m_impl->invoke( t1, t2, t3 ); }
sl@0
   292
sl@0
   293
    bool        operator!() const { return !m_impl; }
sl@0
   294
sl@0
   295
private:
sl@0
   296
    // Data members
sl@0
   297
    boost::shared_ptr<ut_detail::callback3_impl<R,T1,T2,T3> > m_impl;
sl@0
   298
};
sl@0
   299
sl@0
   300
} // namespace unit_test
sl@0
   301
sl@0
   302
} // namespace boost
sl@0
   303
sl@0
   304
#undef BOOST_CALLBACK_EXPLICIT_COPY_CONSTRUCTOR
sl@0
   305
sl@0
   306
//____________________________________________________________________________//
sl@0
   307
sl@0
   308
#include <boost/test/detail/enable_warnings.hpp>
sl@0
   309
sl@0
   310
// ************************************************************************** //
sl@0
   311
//   Revision History:
sl@0
   312
//
sl@0
   313
//   $Log: callback.hpp,v $
sl@0
   314
//   Revision 1.7  2006/02/21 04:27:16  rogeeff
sl@0
   315
//   rev back
sl@0
   316
//
sl@0
   317
//   Revision 1.6  2006/01/28 08:57:03  rogeeff
sl@0
   318
//   VC6.0 workaround removed
sl@0
   319
//
sl@0
   320
//   Revision 1.5  2005/04/13 05:09:00  rogeeff
sl@0
   321
//   Intel 7.1 bug fix
sl@0
   322
//
sl@0
   323
//   Revision 1.4  2005/04/12 06:50:06  rogeeff
sl@0
   324
//   suppress warnings
sl@0
   325
//
sl@0
   326
//   Revision 1.3  2005/03/22 07:05:18  rogeeff
sl@0
   327
//   minor vc7.1 workaround
sl@0
   328
//
sl@0
   329
//   Revision 1.2  2005/02/24 19:28:17  turkanis
sl@0
   330
//   removed redundant copy ctors, except for VC6
sl@0
   331
//
sl@0
   332
//   Revision 1.1  2005/02/20 08:27:08  rogeeff
sl@0
   333
//   This a major update for Boost.Test framework. See release docs for complete list of fixes/updates
sl@0
   334
//
sl@0
   335
// ************************************************************************** //
sl@0
   336
sl@0
   337
#endif // BOOST_TEST_CALLBACK_020505GER