/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
****************************************************************************/

#pragma once

#include "glmICallBack.h"

namespace glm
{
    // Callback on a void class method
    template <class T>
    class MethodCallBack : public ICallBack
    {
    public:
        typedef SmartPointer<MethodCallBack> SP;

        // Type of the pointed method
        typedef void (T::*MethodType)(int64_t index);

        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        MethodCallBack(T* object, MethodType method);
        virtual ~MethodCallBack();

        // Call the pointed method on the object instance
        virtual void call(int64_t index) override;

    private:
        MethodCallBack();

        T* _object;
        void (T::*_method)(int64_t index);
    };

    //-------------------------------------------------------------------------
    template <class T>
    MethodCallBack<T>::MethodCallBack()
        : ICallBack()
        , _object(NULL)
        , _method(NULL)
    {
    }

    //-------------------------------------------------------------------------
    template <class T>
    MethodCallBack<T>::MethodCallBack(T* object, MethodType method)
        : ICallBack()
        , _object(object)
        , _method(method)
    {
    }

    //-------------------------------------------------------------------------
    template <class T>
    MethodCallBack<T>::~MethodCallBack()
    {
    }

    //-------------------------------------------------------------------------
    template <class T>
    void MethodCallBack<T>::call(int64_t index)
    {
        GLM_DEBUG_ASSERT(_object != NULL);
        (_object->*_method)(index);
    }
} // namespace glm
