2006-02-10 22:01:20 +00:00
/*
Copyright ( C ) 2001 - 2006 , William Joseph .
All Rights Reserved .
This file is part of GtkRadiant .
GtkRadiant is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 2 of the License , or
( at your option ) any later version .
GtkRadiant is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with GtkRadiant ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
*/
# if !defined(INCLUDED_GENERIC_CLOSURE_H)
# define INCLUDED_GENERIC_CLOSURE_H
/// \file
2006-04-09 17:15:13 +00:00
/// \brief Type-safe techniques for binding the first argument of an opaque callback.
2006-02-10 22:01:20 +00:00
# include <cstddef>
2006-04-09 17:15:13 +00:00
# include "functional.h"
# include "callbackfwd.h"
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
template < typename Type >
inline void * convertToOpaque ( Type * t )
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
return t ;
}
template < typename Type >
inline void * convertToOpaque ( const Type * t )
{
return const_cast < Type * > ( t ) ;
}
template < typename Type >
inline void * convertToOpaque ( Type & t )
{
return & t ;
}
template < typename Type >
inline void * convertToOpaque ( const Type & t )
{
return const_cast < Type * > ( & t ) ;
}
template < typename Type >
class ConvertFromOpaque
{
} ;
template < typename Type >
class ConvertFromOpaque < Type & >
{
public :
static Type & apply ( void * p )
{
return * static_cast < Type * > ( p ) ;
}
} ;
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
template < typename Type >
class ConvertFromOpaque < const Type & >
{
public :
static const Type & apply ( void * p )
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
return * static_cast < Type * > ( p ) ;
2006-02-10 22:01:20 +00:00
}
2006-04-09 17:15:13 +00:00
} ;
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
template < typename Type >
class ConvertFromOpaque < Type * >
{
public :
static Type * apply ( void * p )
{
return static_cast < Type * > ( p ) ;
}
} ;
template < typename Type >
class ConvertFromOpaque < const Type * >
{
public :
static const Type * apply ( void * p )
{
return static_cast < Type * > ( p ) ;
}
} ;
template < typename Caller >
class BindFirstOpaque
{
typedef typename Caller : : first_argument_type FirstBound ;
FirstBound firstBound ;
2006-02-10 22:01:20 +00:00
public :
2006-04-09 17:15:13 +00:00
typedef typename Caller : : result_type result_type ;
explicit BindFirstOpaque ( FirstBound firstBound ) : firstBound ( firstBound )
2006-02-10 22:01:20 +00:00
{
}
2006-04-09 17:15:13 +00:00
result_type operator ( ) ( ) const
{
return Caller : : call ( firstBound ) ;
}
FirstBound getBound ( ) const
{
return firstBound ;
}
static result_type thunk ( void * environment )
{
return Caller : : call ( ConvertFromOpaque < FirstBound > : : apply ( environment ) ) ;
}
void * getEnvironment ( ) const
{
return convertToOpaque ( firstBound ) ;
}
} ;
template < typename Caller >
class BindFirstOpaque1
{
typedef typename Caller : : first_argument_type FirstBound ;
FirstBound firstBound ;
public :
typedef typename Caller : : second_argument_type first_argument_type ;
typedef typename Caller : : result_type result_type ;
explicit BindFirstOpaque1 ( FirstBound firstBound ) : firstBound ( firstBound )
{
}
result_type operator ( ) ( first_argument_type a1 ) const
{
return Caller : : call ( firstBound , a1 ) ;
}
FirstBound getBound ( ) const
{
return firstBound ;
}
static result_type thunk ( void * environment , first_argument_type a1 )
{
return Caller : : call ( ConvertFromOpaque < FirstBound > : : apply ( environment ) , a1 ) ;
}
void * getEnvironment ( ) const
{
return convertToOpaque ( firstBound ) ;
}
} ;
template < typename Caller >
class BindFirstOpaque2
{
typedef typename Caller : : first_argument_type FirstBound ;
FirstBound firstBound ;
public :
typedef typename Caller : : second_argument_type first_argument_type ;
typedef typename Caller : : third_argument_type second_argument_type ;
typedef typename Caller : : result_type result_type ;
explicit BindFirstOpaque2 ( FirstBound firstBound ) : firstBound ( firstBound )
{
}
result_type operator ( ) ( first_argument_type a1 , second_argument_type a2 ) const
{
return Caller : : call ( firstBound , a1 , a2 ) ;
}
FirstBound getBound ( ) const
{
return firstBound ;
}
static result_type thunk ( void * environment , first_argument_type a1 , second_argument_type a2 )
{
return Caller : : call ( ConvertFromOpaque < FirstBound > : : apply ( environment ) , a1 , a2 ) ;
}
void * getEnvironment ( ) const
{
return convertToOpaque ( firstBound ) ;
}
} ;
template < typename Caller >
class BindFirstOpaque3
{
typedef typename Caller : : first_argument_type FirstBound ;
FirstBound firstBound ;
public :
typedef typename Caller : : second_argument_type first_argument_type ;
typedef typename Caller : : third_argument_type second_argument_type ;
typedef typename Caller : : fourth_argument_type third_argument_type ;
typedef typename Caller : : result_type result_type ;
explicit BindFirstOpaque3 ( FirstBound firstBound ) : firstBound ( firstBound )
{
}
result_type operator ( ) ( first_argument_type a1 , second_argument_type a2 , third_argument_type a3 ) const
{
return Caller : : call ( firstBound , a1 , a2 , a3 ) ;
}
FirstBound getBound ( ) const
{
return firstBound ;
}
static result_type thunk ( void * environment , first_argument_type a1 , second_argument_type a2 , third_argument_type a3 )
{
return Caller : : call ( ConvertFromOpaque < FirstBound > : : apply ( environment ) , a1 , a2 , a3 ) ;
}
void * getEnvironment ( ) const
{
return convertToOpaque ( firstBound ) ;
}
} ;
2006-04-10 18:10:29 +00:00
template < typename Thunk_ >
2006-04-09 17:15:13 +00:00
class CallbackBase
{
void * m_environment ;
Thunk_ m_thunk ;
public :
typedef Thunk_ Thunk ;
CallbackBase ( void * environment , Thunk function ) : m_environment ( environment ) , m_thunk ( function )
2006-02-10 22:01:20 +00:00
{
}
void * getEnvironment ( ) const
{
return m_environment ;
}
Thunk getThunk ( ) const
{
return m_thunk ;
}
} ;
2006-04-10 18:10:29 +00:00
template < typename Thunk >
2006-04-09 17:15:13 +00:00
inline bool operator = = ( const CallbackBase < Thunk > & self , const CallbackBase < Thunk > & other )
2006-02-10 22:01:20 +00:00
{
return self . getEnvironment ( ) = = other . getEnvironment ( ) & & self . getThunk ( ) = = other . getThunk ( ) ;
}
2006-04-10 18:10:29 +00:00
template < typename Thunk >
2006-04-09 17:15:13 +00:00
inline bool operator ! = ( const CallbackBase < Thunk > & self , const CallbackBase < Thunk > & other )
{
return ! ( self = = other ) ;
}
2006-04-10 18:10:29 +00:00
template < typename Thunk >
2006-04-09 17:15:13 +00:00
inline bool operator < ( const CallbackBase < Thunk > & self , const CallbackBase < Thunk > & other )
2006-02-10 22:01:20 +00:00
{
return self . getEnvironment ( ) < other . getEnvironment ( ) | |
( ! ( other . getEnvironment ( ) < self . getEnvironment ( ) ) & & self . getThunk ( ) < other . getThunk ( ) ) ;
}
2006-04-09 17:15:13 +00:00
/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer.
2006-02-10 22:01:20 +00:00
///
2006-04-09 17:15:13 +00:00
/// Use with the callback constructors MemberCaller, ConstMemberCaller, ReferenceCaller, ConstReferenceCaller, PointerCaller, ConstPointerCaller and FreeCaller.
template < typename Result >
class Callback0 : public CallbackBase < Result ( * ) ( void * ) >
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
typedef CallbackBase < Result ( * ) ( void * ) > Base ;
static Result nullThunk ( void * )
2006-02-10 22:01:20 +00:00
{
}
public :
2006-04-09 17:15:13 +00:00
typedef Result result_type ;
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
Callback0 ( ) : Base ( 0 , nullThunk )
2006-02-10 22:01:20 +00:00
{
}
2006-04-09 17:15:13 +00:00
template < typename Caller >
Callback0 ( const BindFirstOpaque < Caller > & caller ) : Base ( caller . getEnvironment ( ) , BindFirstOpaque < Caller > : : thunk )
2006-02-10 22:01:20 +00:00
{
}
2006-04-10 18:16:18 +00:00
Callback0 ( void * environment , typename Base : : Thunk function ) : Base ( environment , function )
2006-02-10 22:01:20 +00:00
{
}
2006-04-09 17:15:13 +00:00
result_type operator ( ) ( ) const
2006-02-10 22:01:20 +00:00
{
2006-04-10 18:19:55 +00:00
return Base : : getThunk ( ) ( Base : : getEnvironment ( ) ) ;
2006-02-10 22:01:20 +00:00
}
} ;
2006-04-09 17:15:13 +00:00
template < typename Caller >
inline Callback0 < typename Caller : : result_type > makeCallback0 ( const Caller & caller , typename Caller : : first_argument_type callee )
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
return Callback0 < typename Caller : : result_type > ( BindFirstOpaque < Caller > ( callee ) ) ;
2006-02-10 22:01:20 +00:00
}
2006-04-09 17:15:13 +00:00
template < typename Caller >
inline Callback0 < typename Caller : : result_type > makeStatelessCallback0 ( const Caller & caller )
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
return makeCallback0 ( Caller0To1 < Caller > ( ) , 0 ) ;
2006-02-10 22:01:20 +00:00
}
2006-04-09 17:15:13 +00:00
typedef Callback0 < void > Callback ;
/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and one other argument.
///
/// Use with the callback constructors MemberCaller1, ConstMemberCaller1, ReferenceCaller1, ConstReferenceCaller1, PointerCaller1, ConstPointerCaller1 and FreeCaller1.
template < typename FirstArgument , typename Result >
class Callback1 : public CallbackBase < Result ( * ) ( void * , FirstArgument ) >
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
typedef CallbackBase < Result ( * ) ( void * , FirstArgument ) > Base ;
static Result nullThunk ( void * , FirstArgument )
{
}
2006-02-10 22:01:20 +00:00
public :
2006-04-09 17:15:13 +00:00
typedef FirstArgument first_argument_type ;
typedef Result result_type ;
Callback1 ( ) : Base ( 0 , nullThunk )
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
}
template < typename Caller >
Callback1 ( const BindFirstOpaque1 < Caller > & caller ) : Base ( caller . getEnvironment ( ) , BindFirstOpaque1 < Caller > : : thunk )
{
}
2006-04-10 18:16:18 +00:00
Callback1 ( void * environment , typename Base : : Thunk function ) : Base ( environment , function )
2006-04-09 17:15:13 +00:00
{
}
result_type operator ( ) ( FirstArgument firstArgument ) const
{
2006-04-10 18:19:55 +00:00
return Base : : getThunk ( ) ( Base : : getEnvironment ( ) , firstArgument ) ;
2006-02-10 22:01:20 +00:00
}
} ;
2006-04-09 17:15:13 +00:00
template < typename Caller >
inline Callback1 < typename Caller : : second_argument_type , typename Caller : : result_type > makeCallback1 ( const Caller & caller , typename Caller : : first_argument_type callee )
{
return Callback1 < typename Caller : : second_argument_type , typename Caller : : result_type > ( BindFirstOpaque1 < Caller > ( callee ) ) ;
}
template < typename Caller >
inline Callback1 < typename Caller : : second_argument_type , typename Caller : : result_type > makeStatelessCallback1 ( const Caller & caller )
{
return makeCallback1 ( Caller1To2 < Caller > ( ) , 0 ) ;
}
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and two other arguments.
///
template < typename FirstArgument , typename SecondArgument , typename Result >
class Callback2 : public CallbackBase < Result ( * ) ( void * , FirstArgument , SecondArgument ) >
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
typedef CallbackBase < Result ( * ) ( void * , FirstArgument , SecondArgument ) > Base ;
static Result nullThunk ( void * , FirstArgument , SecondArgument )
{
}
2006-02-10 22:01:20 +00:00
public :
2006-04-09 17:15:13 +00:00
typedef FirstArgument first_argument_type ;
typedef SecondArgument second_argument_type ;
typedef Result result_type ;
Callback2 ( ) : Base ( 0 , nullThunk )
{
}
template < typename Caller >
Callback2 ( const BindFirstOpaque2 < Caller > & caller ) : Base ( caller . getEnvironment ( ) , BindFirstOpaque2 < Caller > : : thunk )
2006-02-10 22:01:20 +00:00
{
}
2006-04-10 18:16:18 +00:00
Callback2 ( void * environment , typename Base : : Thunk function ) : Base ( environment , function )
2006-02-10 22:01:20 +00:00
{
2006-04-09 17:15:13 +00:00
}
result_type operator ( ) ( FirstArgument firstArgument , SecondArgument secondArgument ) const
{
2006-04-10 18:19:55 +00:00
return Base : : getThunk ( ) ( Base : : getEnvironment ( ) , firstArgument , secondArgument ) ;
2006-02-10 22:01:20 +00:00
}
} ;
2006-04-09 17:15:13 +00:00
template < typename Caller >
inline Callback2 <
typename Caller : : second_argument_type ,
typename Caller : : third_argument_type ,
typename Caller : : result_type
> makeCallback2 ( const Caller & caller , typename Caller : : first_argument_type callee )
{
return Callback2 <
typename Caller : : second_argument_type ,
typename Caller : : third_argument_type ,
typename Caller : : result_type
> ( BindFirstOpaque2 < Caller > ( callee ) ) ;
}
template < typename Caller >
inline Callback2 <
typename Caller : : first_argument_type ,
typename Caller : : second_argument_type ,
typename Caller : : result_type
> makeStatelessCallback2 ( const Caller & caller )
{
return makeCallback2 ( Caller2To3 < Caller > ( ) , 0 ) ;
}
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
/// \brief Combines a void pointer with a pointer to a function which operates on a void pointer and three other arguments.
///
template < typename FirstArgument , typename SecondArgument , typename ThirdArgument , typename Result >
class Callback3 : public CallbackBase < Result ( * ) ( void * , FirstArgument , SecondArgument , ThirdArgument ) >
{
typedef CallbackBase < Result ( * ) ( void * , FirstArgument , SecondArgument , ThirdArgument ) > Base ;
static Result nullThunk ( void * , FirstArgument , SecondArgument , ThirdArgument )
{
}
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
public :
typedef FirstArgument first_argument_type ;
typedef SecondArgument second_argument_type ;
typedef ThirdArgument third_argument_type ;
typedef Result result_type ;
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
Callback3 ( ) : Base ( 0 , nullThunk )
{
}
template < typename Caller >
Callback3 ( const BindFirstOpaque3 < Caller > & caller ) : Base ( caller . getEnvironment ( ) , BindFirstOpaque3 < Caller > : : thunk )
{
}
2006-04-10 18:16:18 +00:00
Callback3 ( void * environment , typename Base : : Thunk function ) : Base ( environment , function )
2006-04-09 17:15:13 +00:00
{
}
result_type operator ( ) ( FirstArgument firstArgument , SecondArgument secondArgument , ThirdArgument thirdArgument ) const
{
2006-04-10 18:19:55 +00:00
return Base : : getThunk ( ) ( Base : : getEnvironment ( ) , firstArgument , secondArgument , thirdArgument ) ;
2006-04-09 17:15:13 +00:00
}
} ;
2006-02-10 22:01:20 +00:00
2006-04-09 17:15:13 +00:00
template < typename Caller >
inline Callback3 <
typename Caller : : second_argument_type ,
typename Caller : : third_argument_type ,
typename Caller : : fourth_argument_type ,
typename Caller : : result_type
> makeCallback3 ( const Caller & caller , typename Caller : : first_argument_type callee )
{
return Callback3 <
typename Caller : : second_argument_type ,
typename Caller : : third_argument_type ,
typename Caller : : fourth_argument_type ,
typename Caller : : result_type
> ( BindFirstOpaque3 < Caller > ( callee ) ) ;
}
template < typename Caller >
inline Callback3 <
typename Caller : : first_argument_type ,
typename Caller : : second_argument_type ,
typename Caller : : third_argument_type ,
typename Caller : : result_type
> makeStatelessCallback3 ( const Caller & caller )
{
return makeCallback3 ( Caller3To4 < Caller > ( ) , 0 ) ;
}
2006-02-10 22:01:20 +00:00
/// \brief Forms a Callback from a non-const Environment reference and a non-const Environment member-function.
///
/// \dontinclude generic/callback.cpp
/// \skipline MemberCaller example
/// \until end example
template < typename Environment , void ( Environment : : * member ) ( ) >
2006-04-09 17:15:13 +00:00
class MemberCaller : public BindFirstOpaque < Member < Environment , void , member > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
MemberCaller ( Environment & environment ) : BindFirstOpaque < Member < Environment , void , member > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a const Environment reference and a const Environment member-function.
///
/// \dontinclude generic/callback.cpp
/// \skipline MemberCaller example
/// \until end example
template < typename Environment , void ( Environment : : * member ) ( ) const >
2006-04-09 17:15:13 +00:00
class ConstMemberCaller : public BindFirstOpaque < ConstMember < Environment , void , member > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ConstMemberCaller ( const Environment & environment ) : BindFirstOpaque < ConstMember < Environment , void , member > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a non-const Environment reference and a const Environment member-function which takes one argument.
template < typename Environment , typename FirstArgument , void ( Environment : : * member ) ( FirstArgument ) >
2006-04-09 17:15:13 +00:00
class MemberCaller1 : public BindFirstOpaque1 < Member1 < Environment , FirstArgument , void , member > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
MemberCaller1 ( Environment & environment ) : BindFirstOpaque1 < Member1 < Environment , FirstArgument , void , member > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a const Environment reference and a const Environment member-function which takes one argument.
template < typename Environment , typename FirstArgument , void ( Environment : : * member ) ( FirstArgument ) const >
2006-04-09 17:15:13 +00:00
class ConstMemberCaller1 : public BindFirstOpaque1 < ConstMember1 < Environment , FirstArgument , void , member > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ConstMemberCaller1 ( const Environment & environment ) : BindFirstOpaque1 < ConstMember1 < Environment , FirstArgument , void , member > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference.
///
/// \dontinclude generic/callback.cpp
/// \skipline ReferenceCaller example
/// \until end example
template < typename Environment , void ( * func ) ( Environment & ) >
2006-04-09 17:15:13 +00:00
class ReferenceCaller : public BindFirstOpaque < Function1 < Environment & , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ReferenceCaller ( Environment & environment ) : BindFirstOpaque < Function1 < Environment & , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference.
///
/// \dontinclude generic/callback.cpp
/// \skipline ReferenceCaller example
/// \until end example
template < typename Environment , void ( * func ) ( const Environment & ) >
2006-04-09 17:15:13 +00:00
class ConstReferenceCaller : public BindFirstOpaque < Function1 < const Environment & , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ConstReferenceCaller ( const Environment & environment ) : BindFirstOpaque < Function1 < const Environment & , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a non-const Environment reference and a free function which operates on a non-const Environment reference and one other argument.
template < typename Environment , typename FirstArgument , void ( * func ) ( Environment & , FirstArgument ) >
2006-04-09 17:15:13 +00:00
class ReferenceCaller1 : public BindFirstOpaque1 < Function2 < Environment & , FirstArgument , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ReferenceCaller1 ( Environment & environment ) : BindFirstOpaque1 < Function2 < Environment & , FirstArgument , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a const Environment reference and a free function which operates on a const Environment reference and one other argument.
template < typename Environment , typename FirstArgument , void ( * func ) ( const Environment & , FirstArgument ) >
2006-04-09 17:15:13 +00:00
class ConstReferenceCaller1 : public BindFirstOpaque1 < Function2 < const Environment & , FirstArgument , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ConstReferenceCaller1 ( const Environment & environment ) : BindFirstOpaque1 < Function2 < const Environment & , FirstArgument , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer.
template < typename Environment , void ( * func ) ( Environment * ) >
2006-04-09 17:15:13 +00:00
class PointerCaller : public BindFirstOpaque < Function1 < Environment * , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
PointerCaller ( Environment * environment ) : BindFirstOpaque < Function1 < Environment * , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer.
template < typename Environment , void ( * func ) ( const Environment * ) >
2006-04-09 17:15:13 +00:00
class ConstPointerCaller : public BindFirstOpaque < Function1 < const Environment * , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ConstPointerCaller ( const Environment * environment ) : BindFirstOpaque < Function1 < const Environment * , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a non-const Environment pointer and a free function which operates on a non-const Environment pointer and one other argument.
template < typename Environment , typename FirstArgument , void ( * func ) ( Environment * , FirstArgument ) >
2006-04-09 17:15:13 +00:00
class PointerCaller1 : public BindFirstOpaque1 < Function2 < Environment * , FirstArgument , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
PointerCaller1 ( Environment * environment ) : BindFirstOpaque1 < Function2 < Environment * , FirstArgument , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a const Environment pointer and a free function which operates on a const Environment pointer and one other argument.
template < typename Environment , typename FirstArgument , void ( * func ) ( const Environment * , FirstArgument ) >
2006-04-09 17:15:13 +00:00
class ConstPointerCaller1 : public BindFirstOpaque1 < Function2 < const Environment * , FirstArgument , void , func > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
ConstPointerCaller1 ( const Environment * environment ) : BindFirstOpaque1 < Function2 < const Environment * , FirstArgument , void , func > > ( environment )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a free function which takes no arguments.
template < void ( * func ) ( ) >
2006-04-09 17:15:13 +00:00
class FreeCaller : public BindFirstOpaque < Caller0To1 < Function0 < void , func > > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
FreeCaller ( ) : BindFirstOpaque < Caller0To1 < Function0 < void , func > > > ( 0 )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Forms a Callback from a free function which takes a single argument.
template < typename FirstArgument , void ( * func ) ( FirstArgument ) >
2006-04-09 17:15:13 +00:00
class FreeCaller1 : public BindFirstOpaque1 < Caller1To2 < Function1 < FirstArgument , void , func > > >
2006-02-10 22:01:20 +00:00
{
public :
2006-04-09 17:15:13 +00:00
FreeCaller1 ( ) : BindFirstOpaque1 < Caller1To2 < Function1 < FirstArgument , void , func > > > ( 0 )
2006-02-10 22:01:20 +00:00
{
}
} ;
/// \brief Constructs a Callback from a non-const \p functor with zero arguments.
///
/// \param Functor Must define \c operator()().
template < typename Functor >
inline Callback makeCallback ( Functor & functor )
{
return Callback ( MemberCaller < Functor , & Functor : : operator ( ) > ( functor ) ) ;
}
/// \brief Constructs a Callback from a const \p functor with zero arguments.
///
/// \param Functor Must define const \c operator()().
template < typename Functor >
inline Callback makeCallback ( const Functor & functor )
{
return Callback ( ConstMemberCaller < Functor , & Functor : : operator ( ) > ( functor ) ) ;
}
/// \brief Constructs a Callback1 from a non-const \p functor with one argument.
///
/// \param Functor Must define \c first_argument_type and \c operator()(first_argument_type).
template < typename Functor >
inline Callback1 < typename Functor : : first_argument_type > makeCallback1 ( Functor & functor )
{
typedef typename Functor : : first_argument_type FirstArgument ;
return Callback1 < FirstArgument > ( MemberCaller1 < Functor , FirstArgument , & Functor : : operator ( ) > ( functor ) ) ;
}
/// \brief Constructs a Callback1 from a const \p functor with one argument.
///
/// \param Functor Must define \c first_argument_type and const \c operator()(first_argument_type).
template < typename Functor >
inline Callback1 < typename Functor : : first_argument_type > makeCallback1 ( const Functor & functor )
{
typedef typename Functor : : first_argument_type FirstArgument ;
return Callback1 < FirstArgument > ( ConstMemberCaller1 < Functor , FirstArgument , & Functor : : operator ( ) > ( functor ) ) ;
}
2006-04-09 17:15:13 +00:00
typedef Callback1 < bool > BoolImportCallback ;
typedef Callback1 < const BoolImportCallback & > BoolExportCallback ;
typedef Callback1 < int > IntImportCallback ;
typedef Callback1 < const IntImportCallback & > IntExportCallback ;
typedef Callback1 < float > FloatImportCallback ;
typedef Callback1 < const FloatImportCallback & > FloatExportCallback ;
typedef Callback1 < const char * > StringImportCallback ;
typedef Callback1 < const StringImportCallback & > StringExportCallback ;
typedef Callback1 < std : : size_t > SizeImportCallback ;
typedef Callback1 < const SizeImportCallback & > SizeExportCallback ;
2006-02-10 22:01:20 +00:00
# endif