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

/*! \file */

#ifndef REVEAL_CALLBACK_RETURN_REF_ADAPTER_H
#define REVEAL_CALLBACK_RETURN_REF_ADAPTER_H

#include "reveal/callback/callback_0.h"

namespace Reveal {
    namespace Callback {

// Forward;
template < class T > class ReturnRefAdapterFunctor;

// ------------------------------------------------------------------------
/*!
	\briefs Creates a callback that takes no parameters, and always returns the current value
			that the given reference has;
*/
// ------------------------------------------------------------------------
template < class T >
Callback0< T > ReturnRefAdapter( T& param )
{
	return Callback0< T >( ReturnRefAdapterFunctor< T >( param ) );
}

// ------------------------------------------------------------------------
/*!
    \brief Actual implementation of the ReturnRefAdapter;

	\internal
*/
// ------------------------------------------------------------------------
template < class T >
class ReturnRefAdapterFunctor
{
    // Default copy ctor is ok, assigment operator is disabled (references can't be reseated);
	ReturnRefAdapterFunctor& operator = ( const ReturnRefAdapterFunctor& );

private:
    friend Callback0< T > ReturnRefAdapter< T >( T& param );
    
    // Private because only the friend can construct this;
    explicit ReturnRefAdapterFunctor( T& variable ) : mVariable( variable ) {}
    
public:
       
	T& operator () () { return mVariable; }

private:

	T& mVariable;
};


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

#endif
