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