Skip to content

File evaHandler.h

File List > src > evaHandler.h

Go to the documentation of this file

#pragma once

namespace eva
{

    struct CallbackInfo
    {
        unsigned short eventType;
        signed short eventArg;
    };

    class IHandler
    {
    public:
        virtual void invoke(void *msgSender, CallbackInfo cbInfo) = 0;
    };

    template <class T>
    class Handler : public IHandler
    {
        T *msgReceiver;
        void (T::*method)(void *, CallbackInfo);
    public:
        Handler(T *msgReceiver, void (T::*method)(void *, CallbackInfo))
            : msgReceiver(msgReceiver), method(method)
        {
        }

        void invoke(void *msgSender, CallbackInfo cbInfo) override
        {
            (this->msgReceiver->*method)(msgSender, cbInfo);
        }
    };

    class HandlerF : public IHandler
    {
    public:
        HandlerF(void (*function)(void *, CallbackInfo))
            : function(function)
        {
        }

        void invoke(void *msgSender, CallbackInfo cbInfo) override
        {
            (*function)(msgSender, cbInfo);
        }

    private:
        void (*function)(void *, CallbackInfo);
    };
}