fbxeventhandler.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2012 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 // Local includes
00019 #include <fbxsdk/core/fbxevent.h>
00020 
00021 // FBX include
00022 #include <fbxsdk/core/base/fbxintrusivelist.h>
00023 
00024 #include <fbxsdk/fbxsdk_nsbegin.h>
00025 
00026 class FbxListener;
00027 
00028 //-----------------------------------------------------------------
00045 class FbxEventHandler
00046 {
00047 public:
00048     enum EType
00049     {
00050         eListener,
00051         eEmitter,
00052         eCount
00053     };
00054 
00057     FbxEventHandler(){}
00058 
00061     virtual ~FbxEventHandler(){}
00062 
00063     // Handler handles a certain type of event.
00067     virtual int GetHandlerEventType() = 0;
00068 
00073     virtual void FunctionCall(const FbxEventBase& pEvent) = 0;
00074 
00078     virtual FbxListener* GetListener() = 0;
00079 
00080     FBXSDK_INTRUSIVE_LIST_NODE(FbxEventHandler, eCount);
00081 };
00082 
00084 //
00085 //  WARNING!
00086 //
00087 //  Anything beyond these lines may not be documented accurately and is
00088 //  subject to change without notice.
00089 //
00091 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00092 //-----------------------------------------------------------------
00093 template <typename EventType, typename ListenerType> class FbxMemberFuncEventHandler : public FbxEventHandler
00094 {
00095 // VC6Note: There's no reason why the callback is a (const EventType*) it is obvious that it should be
00096 //           a (const EventType&) but because of a VC6 template limitation, we put  a pointer. 
00097 typedef void (ListenerType::*CBFunction)(const EventType*);
00098 
00099 public:
00100     FbxMemberFuncEventHandler(ListenerType* pListenerInstance, CBFunction pFunc) :
00101         mListener(pListenerInstance),
00102         mFunc(pFunc)
00103     {
00104     }
00105 
00106     // From FbxEventHandler
00107     virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }  
00108     virtual void FunctionCall(const FbxEventBase& pEvent){ (*mListener.*mFunc)(reinterpret_cast<const EventType*>(&pEvent)); } 
00109     virtual FbxListener* GetListener(){ return mListener;}
00110 private:
00111     ListenerType* mListener;
00112 
00113     // The callback function
00114     CBFunction mFunc;
00115 };
00116 
00117 //-----------------------------------------------------------------
00118 template <typename EventType, typename ListenerType> class FbxConstMemberFuncEventHandler : public FbxEventHandler
00119 {
00120 
00121 // VC6Note: There's no reason why the callback is a (const EventType*) it is obvious that it should be
00122 //           a (const EventType&) but because of a VC6 template limitation, we put  a pointer. 
00123 typedef void (ListenerType::*CBFunction)(const EventType*)const;
00124 
00125 public:
00126     FbxConstMemberFuncEventHandler(ListenerType* pListenerInstance, CBFunction pFunc) :
00127         mListener(pListenerInstance),
00128         mFunc(pFunc)
00129     {
00130     }
00131 
00132     // From FbxEventHandler
00133     virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }    
00134     virtual void FunctionCall(const FbxEventBase& pEvent){ (*mListener.*mFunc)(reinterpret_cast<const EventType*>(&pEvent)); }
00135     virtual FbxListener* GetListener(){ return mListener;}
00136 private:
00137     ListenerType* mListener;
00138 
00139     // The callback function
00140     CBFunction mFunc;
00141 };
00142 
00143 //-----------------------------------------------------------------
00144 template <typename EventType> class FbxFuncEventHandler : public FbxEventHandler
00145 {
00146 // VC6Note: There's no reason why the callback is a (const EventType*,FbxListener*) it is obvious that it should be
00147 //           a (const EventType&,FbxListener*) but because of a VC6 template limitation, we put  a pointer.
00148 typedef void (*CBFunction)(const EventType*,FbxListener*);
00149 
00150 public:
00151     FbxFuncEventHandler(FbxListener* pListener, CBFunction pFunc) :
00152         mListener(pListener),
00153         mFunc(pFunc)
00154     {
00155     }
00156 
00157     // From FbxEventHandler
00158     virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }   
00159     virtual void FunctionCall(const FbxEventBase& pEvent){ (*mFunc)(reinterpret_cast<const EventType*>(&pEvent),mListener); }
00160     virtual FbxListener* GetListener(){ return mListener; }
00161 private:
00162     FbxListener* mListener;
00163 
00164     // The callback function
00165     CBFunction mFunc;
00166 };
00167 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00168 
00169 #include <fbxsdk/fbxsdk_nsend.h>
00170 
00171 #endif /* _FBXSDK_CORE_EVENT_HANDLER_H_ */