/* Copyright (C) 2014 * swift project community / contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ #ifndef BLACKSIMPLUGIN_FS9_CALLBACK_WRAPPER_H #define BLACKSIMPLUGIN_FS9_CALLBACK_WRAPPER_H #include #include #include #include namespace BlackSimPlugin { namespace Fs9 { //! Template, wrapping the C-style DirectPlay handler callback to a class member template struct CallbackWrapper { //! Typedef to a MemberFunction typedef ReturnType (Object::*MemberFunction)(Argument1, Argument2); //! Constructor CallbackWrapper(Object *obj, MemberFunction memberFunction) : m_object(obj), m_memberFunction(memberFunction) {} //! FS9 message handler callback static ReturnType WINAPI messageHandler(void *userContext, Argument1 arg1, Argument2 arg2) { CallbackWrapper *_this = static_cast(userContext); Object *obj = _this->m_object; MemberFunction func = _this->m_memberFunction; ReturnType result = (obj->*func)(arg1, arg2); return result; } private: QPointer m_object; MemberFunction m_memberFunction; }; } } #endif // guard