PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: EventHandler.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_EVENTHANDLER_H__ 00024 #define __PLCORE_EVENTHANDLER_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Base/Func/Functor.h" 00032 #include "PLCore/Base/Event/DynEventHandler.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14, typename T15> 00045 class Event; 00046 00047 00048 //[-------------------------------------------------------] 00049 //[ Classes ] 00050 //[-------------------------------------------------------] 00051 /** 00052 * @brief 00053 * Generic event handler class 00054 */ 00055 template <typename T0 = NullType, typename T1 = NullType, typename T2 = NullType, typename T3 = NullType, typename T4 = NullType, typename T5 = NullType, typename T6 = NullType, typename T7 = NullType, typename T8 = NullType, typename T9 = NullType, typename T10 = NullType, typename T11 = NullType, typename T12 = NullType, typename T13 = NullType, typename T14 = NullType, typename T15 = NullType> 00056 class EventHandler : public DynEventHandler { 00057 00058 00059 //[-------------------------------------------------------] 00060 //[ Friends ] 00061 //[-------------------------------------------------------] 00062 friend class Event<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>; 00063 00064 00065 //[-------------------------------------------------------] 00066 //[ Public data types ] 00067 //[-------------------------------------------------------] 00068 public: 00069 typedef Functor<void, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> TypeFunctor; 00070 typedef Signature<void, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> TypeSignature; 00071 00072 00073 //[-------------------------------------------------------] 00074 //[ Public functions ] 00075 //[-------------------------------------------------------] 00076 public: 00077 /** 00078 * @brief 00079 * Constructor 00080 */ 00081 EventHandler() : 00082 m_cFunctor() 00083 { 00084 } 00085 00086 /** 00087 * @brief 00088 * Constructor 00089 * 00090 * @param[in] cFunctor 00091 * Functor containing an event handler function 00092 */ 00093 EventHandler(const TypeFunctor &cFunctor) : 00094 m_cFunctor(cFunctor) 00095 { 00096 } 00097 00098 /** 00099 * @brief 00100 * Constructor 00101 * 00102 * @param[in] pFunc 00103 * Pointer to a static function 00104 */ 00105 EventHandler(const typename Signature<void, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::FuncType &pFunc) : 00106 m_cFunctor(pFunc) 00107 { 00108 } 00109 00110 /** 00111 * @brief 00112 * Constructor 00113 * 00114 * @param[in] pMemFunc 00115 * Pointer to a member function of a class 00116 * @param[in] pObject 00117 * Pointer to an instance of that class 00118 */ 00119 template <class CLASS> 00120 EventHandler(const typename MethodSignature<CLASS, void, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>::MemFuncType &pMemFunc, CLASS *pObject) : 00121 m_cFunctor(pMemFunc, pObject) 00122 { 00123 } 00124 00125 /** 00126 * @brief 00127 * Destructor 00128 */ 00129 ~EventHandler() 00130 { 00131 } 00132 00133 00134 //[-------------------------------------------------------] 00135 //[ Public virtual DynEventHandler functions ] 00136 //[-------------------------------------------------------] 00137 public: 00138 virtual String GetSignature() const override 00139 { 00140 return TypeSignature::GetSignatureID(); 00141 } 00142 00143 00144 //[-------------------------------------------------------] 00145 //[ Protected data ] 00146 //[-------------------------------------------------------] 00147 protected: 00148 TypeFunctor m_cFunctor; /**< Functor containing the event handler */ 00149 00150 00151 }; 00152 00153 00154 //[-------------------------------------------------------] 00155 //[ Namespace ] 00156 //[-------------------------------------------------------] 00157 } // PLCore 00158 00159 00160 #endif // __PLCORE_EVENTHANDLER_H__
|