fbxsdk/core/fbxeventhandler.h Source File
 
 
 
fbxsdk/core/fbxeventhandler.h
Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2013 Autodesk, Inc.
00004    All rights reserved.
00005  
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009  
00010 ****************************************************************************************/
00011 
00013 #ifndef _FBXSDK_CORE_EVENT_HANDLER_H_
00014 #define _FBXSDK_CORE_EVENT_HANDLER_H_
00015 
00016 #include <fbxsdk/fbxsdk_def.h>
00017 
00018 #include <fbxsdk/core/fbxevent.h>
00019 #include <fbxsdk/core/base/fbxintrusivelist.h>
00020 
00021 #include <fbxsdk/fbxsdk_nsbegin.h>
00022 
00023 class FbxListener;
00024 
00041 class FbxEventHandler
00042 {
00043 public:
00045         enum EType
00046         {
00047                 eListener,      
00048                 eEmitter,       
00049                 eCount          
00050         };
00051 
00054         virtual int GetHandlerEventType()=0;
00055 
00059         virtual void FunctionCall(const FbxEventBase& pEvent)=0;
00060 
00063         virtual FbxListener* GetListener()=0;
00064 
00065 /*****************************************************************************************************************************
00066 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
00067 *****************************************************************************************************************************/
00068 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00069     FbxEventHandler(){}
00070     virtual ~FbxEventHandler(){}
00071 
00072         FBXSDK_INTRUSIVE_LIST_NODE(FbxEventHandler, eCount);
00073 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
00074 };
00075 
00076 /*****************************************************************************************************************************
00077 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
00078 *****************************************************************************************************************************/
00079 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00080 
00081 template <typename EventType, typename ListenerType> class FbxMemberFuncEventHandler : public FbxEventHandler
00082 {
00083         typedef void (ListenerType::*CallbackFnc)(const EventType*);
00084 
00085 public:
00086     FbxMemberFuncEventHandler(ListenerType* pListenerInstance, CallbackFnc pFunction) : mListener(pListenerInstance), mFunction(pFunction){}
00087         virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }  
00088         virtual void FunctionCall(const FbxEventBase& pEvent){ (*mListener.*mFunction)(reinterpret_cast<const EventType*>(&pEvent)); } 
00089         virtual FbxListener* GetListener(){ return mListener; }
00090 
00091 private:
00092         ListenerType*   mListener;
00093         CallbackFnc             mFunction;
00094 };
00095 
00096 template <typename EventType, typename ListenerType> class FbxConstMemberFuncEventHandler : public FbxEventHandler
00097 {
00098         typedef void (ListenerType::*CallbackFnc)(const EventType*) const;
00099 
00100 public:
00101         FbxConstMemberFuncEventHandler(ListenerType* pListenerInstance, CallbackFnc pFunction) : mListener(pListenerInstance), mFunction(pFunction){}
00102         virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }    
00103         virtual void FunctionCall(const FbxEventBase& pEvent){ (*mListener.*mFunction)(reinterpret_cast<const EventType*>(&pEvent)); }
00104         virtual FbxListener* GetListener(){ return mListener; }
00105 
00106 private:
00107         ListenerType*   mListener;
00108         CallbackFnc             mFunction;
00109 };
00110 
00111 template <typename EventType> class FbxFuncEventHandler : public FbxEventHandler
00112 {
00113         typedef void (*CallbackFnc)(const EventType*, FbxListener*);
00114 
00115 public:
00116         FbxFuncEventHandler(FbxListener* pListener, CallbackFnc pFunction) : mListener(pListener), mFunction(pFunction){}
00117         virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }   
00118         virtual void FunctionCall(const FbxEventBase& pEvent){ (*mFunction)(reinterpret_cast<const EventType*>(&pEvent), mListener); }
00119         virtual FbxListener* GetListener(){ return mListener; }
00120 
00121 private:
00122         FbxListener*    mListener;
00123         CallbackFnc             mFunction;
00124 };
00125 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
00126 
00127 #include <fbxsdk/fbxsdk_nsend.h>
00128 
00129 #endif /* _FBXSDK_CORE_EVENT_HANDLER_H_ */