// ------------------------------------------------------------------------
/*
	author: Jaap Suter
   
	Copyright (C) Electronic Arts Canada Inc. 2002.  All rights reserved.	
*/
// ------------------------------------------------------------------------

/*! \file */

#ifndef REVEAL_CALLBACK_MEM_FUN_ADAPTER_H
#define REVEAL_CALLBACK_MEM_FUN_ADAPTER_H

#include "reveal/callback/callback_0.h"
#include "reveal/callback/callback_1.h"
#include "reveal/callback/callback_3.h"

namespace Reveal {
    namespace Callback {

// ------------------------------------------------------------------------
/*!
	\function MemFunAdapter1
    \brief Constructs a functor from a pointer to a member function taking one parameter and an object

    This allows us to create a callback that calls a member function, without burdening
	the user with all sorts of template trickery;
*/
// ------------------------------------------------------------------------
template < class ClassType, class ReturnType, class ParamType >
Callback1< ReturnType, ParamType > MemFunAdapter1( ClassType& objectRef, ReturnType (ClassType::*ptrToMemFun)( ParamType ) const )
{
    return Callback1< ReturnType, ParamType >( objectRef, ptrToMemFun );
}

//! \function MemFunAdapter
//! Version for non-const member functions;
template < class ClassType, class ReturnType, class ParamType >
Callback1< ReturnType, ParamType > MemFunAdapter1( ClassType& objectRef, ReturnType (ClassType::*ptrToMemFun)( ParamType ) )
{
    return Callback1< ReturnType, ParamType >( objectRef, ptrToMemFun );
}

// ------------------------------------------------------------------------
/*!
	\function MemFunAdapter0
    \brief Constructs a functor from a pointer to a member function taking no parameters and an object

    This allows us to create a callback that calls a member function, without burdening
	the user with all sorts of template trickery;
*/
// ------------------------------------------------------------------------
template < class ClassType, class ReturnType >
Callback0< ReturnType > MemFunAdapter0( ClassType& objectRef, ReturnType (ClassType::*ptrToMemFun)() const )
{
    return Callback0< ReturnType >( objectRef, ptrToMemFun );
}

//! \function MemFunAdapter0
//! Version for non-const member functions;
template < class ClassType, class ReturnType >
Callback0< ReturnType > MemFunAdapter0( ClassType& objectRef, ReturnType (ClassType::*ptrToMemFun)() )
{
    return Callback0< ReturnType >( objectRef, ptrToMemFun );
}

// ------------------------------------------------------------------------
/*!
	\function MemFunAdapter3
    \brief Constructs a functor from a pointer to a member function taking three parameters and an object

    This allows us to create a callback that calls a member function, without burdening
	the user with all sorts of template trickery;
*/
// ------------------------------------------------------------------------
template < class ClassType, class ReturnType, class P0, class P1, class P2 >
Callback3< ReturnType, P0, P1, P2 > MemFunAdapter3( ClassType& objectRef, ReturnType (ClassType::*ptrToMemFun)( P0, P1, P2 ) const )
{
    return Callback3< ReturnType, P0, P1, P2 >( objectRef, ptrToMemFun );
}

//! \function MemFunAdapter3
//! Version for non-const member functions;
template < class ClassType, class ReturnType, class P0, class P1, class P2 >
Callback3< ReturnType, P0, P1, P2 > MemFunAdapter3( ClassType& objectRef, ReturnType (ClassType::*ptrToMemFun)( P0, P1, P2 ) )
{
    return Callback3< ReturnType, P0, P1, P2 >( objectRef, ptrToMemFun );
}


    } // Namespace Callback;
} // Namespace Reveal;

#endif
