PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: Slot.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_SLOT_H__ 00024 #define __PLCORE_SLOT_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/Base/Event/EventHandler.h" 00032 #include "PLCore/Base/Event/EventHandlerDesc.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLCore { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Classes ] 00043 //[-------------------------------------------------------] 00044 /** 00045 * @brief 00046 * Event handler of a class 00047 * 00048 * @remarks 00049 * This class template represents slots (event handlers that belong to objects). 00050 * 00051 * @note 00052 * - Implementation of the observer design pattern (this class is the observer, the destination) 00053 */ 00054 template <typename DESC> 00055 class Slot : public DESC::EventHandlerType { 00056 00057 00058 //[-------------------------------------------------------] 00059 //[ Public static data ] 00060 //[-------------------------------------------------------] 00061 public: 00062 static DESC Desc; /**< Event handler descriptor */ 00063 00064 00065 //[-------------------------------------------------------] 00066 //[ Public functions ] 00067 //[-------------------------------------------------------] 00068 public: 00069 /** 00070 * @brief 00071 * Constructor 00072 * 00073 * @param[in] pMemFunc 00074 * Pointer to member function of a class 00075 * @param[in] pObject 00076 * Pointer to object to which the method belongs 00077 */ 00078 Slot(const typename DESC::MethType::MemFuncType &pMemFunc, typename DESC::ClassType *pObject) : 00079 DESC::EventHandlerType(pMemFunc, pObject) 00080 { 00081 // Ensure that the compiler will actually create static instances 00082 Desc.Dummy(); 00083 } 00084 00085 /** 00086 * @brief 00087 * Destructor 00088 */ 00089 virtual ~Slot() 00090 { 00091 } 00092 00093 00094 //[-------------------------------------------------------] 00095 //[ Public virtual DynFunc functions ] 00096 //[-------------------------------------------------------] 00097 public: 00098 /** 00099 * @brief 00100 * Get event handler descriptor 00101 * 00102 * @return 00103 * Event handler descriptor 00104 */ 00105 virtual const EventHandlerDesc *GetDesc() const override 00106 { 00107 // Return descriptor 00108 return &Desc; 00109 } 00110 00111 00112 }; 00113 00114 00115 // Static data instances 00116 template<typename DESC> 00117 DESC Slot<DESC>::Desc; 00118 00119 00120 //[-------------------------------------------------------] 00121 //[ Namespace ] 00122 //[-------------------------------------------------------] 00123 } // PLCore 00124 00125 00126 #endif // __PLCORE_SLOT_H__
|