FBX SDK Reference Guide: kfbxeventhandler.h Source File
00001 #ifndef FBXFILESDK_KFBXEVENTS_KFBXEVENTHANDLER_H
00002 #define FBXFILESDK_KFBXEVENTS_KFBXEVENTHANDLER_H
00003 
00004 /**************************************************************************************
00005 
00006  Copyright © 2001 - 2008 Autodesk, Inc. and/or its licensors.
00007  All Rights Reserved.
00008 
00009  The coded instructions, statements, computer programs, and/or related material 
00010  (collectively the "Data") in these files contain unpublished information 
00011  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00012  Canada and United States of America federal copyright law and by international 
00013  treaties. 
00014  
00015  The Data may not be disclosed or distributed to third parties, in whole or in
00016  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00017 
00018  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00019  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00020  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00021  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00022  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00023  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00024  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00025  
00026  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00027  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00028  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00029  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00030  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00031  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00032  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00033  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00034  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00035  OR DAMAGE. 
00036 
00037 **************************************************************************************/
00038 #include <fbxfilesdk/components/kbaselib/kaydaradef_h.h>
00039 // Local includes
00040 #include <fbxfilesdk/kfbxevents/kfbxevents.h>
00041 
00042 // FBX include
00043 #include <fbxfilesdk/components/kbaselib/klib/kintrusivelist.h>
00044 
00045 // FBX namespace begin
00046 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00047 namespace kfbxevents
00048 {
00049     class KFbxListener;
00050 
00051     //-----------------------------------------------------------------
00052     class KFbxEventHandler
00053     {
00054     public:
00055         enum
00056         {
00057             eNODE_LISTENER = 0,
00058             eNODE_EMITTER,
00059             eNODE_COUNT
00060         };
00061 
00062         KFbxEventHandler(){}
00063         virtual ~KFbxEventHandler(){}
00064 
00065         // Handler handles a certain type of event
00066         virtual int GetHandlerEventType() = 0;
00067         virtual void FunctionCall(const KFbxEventBase& pEvent) = 0;
00068         virtual KFbxListener* GetListener() = 0;
00069 
00070         KFBX_LISTNODE(KFbxEventHandler, eNODE_COUNT);
00071     };
00072 
00073     //-----------------------------------------------------------------
00074     template <typename EventType, typename ListenerType>
00075     class KFbxMemberFuncEventHandler : public KFbxEventHandler
00076     {
00077     // VC6Note: There's no reason why the callback is a (const EventType*) it is obvious that it should be
00078     //           a (const EventType&) but because of a VC6 template limitation, we put  a pointer. 
00079     typedef void (ListenerType::*CBFunction)(const EventType*);
00080 
00081     public:
00082         KFbxMemberFuncEventHandler(ListenerType* pListenerInstance, CBFunction pFunc) :
00083             mFunc(pFunc),
00084             mListener(pListenerInstance){}
00085 
00086         // From KFbxEventHandler
00087         virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }  
00088         virtual void FunctionCall(const KFbxEventBase& pEvent){ (*mListener.*mFunc)(reinterpret_cast<const EventType*>(&pEvent)); } 
00089         virtual KFbxListener* GetListener(){ return mListener;}
00090     
00091     private:
00092         ListenerType* mListener;
00093 
00094         // The callback function
00095         CBFunction mFunc;
00096     };
00097 
00098     //-----------------------------------------------------------------
00099     template <typename EventType, typename ListenerType>
00100     class KFbxConstMemberFuncEventHandler : public KFbxEventHandler
00101     {
00102     // VC6Note: There's no reason why the callback is a (const EventType*) it is obvious that it should be
00103     //           a (const EventType&) but because of a VC6 template limitation, we put  a pointer. 
00104     typedef void (ListenerType::*CBFunction)(const EventType*)const;
00105 
00106     public:
00107         KFbxConstMemberFuncEventHandler(ListenerType* pListenerInstance, CBFunction pFunc) :
00108             mFunc(pFunc),
00109             mListener(pListenerInstance){}
00110 
00111         // From KFbxEventHandler
00112         virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }    
00113         virtual void FunctionCall(const KFbxEventBase& pEvent){ (*mListener.*mFunc)(reinterpret_cast<const EventType*>(&pEvent)); }
00114         virtual KFbxListener* GetListener(){ return mListener;}
00115 
00116     private:
00117         ListenerType* mListener;
00118 
00119         // The callback function
00120         CBFunction mFunc;
00121     };
00122 
00123     //-----------------------------------------------------------------
00124     template <typename EventType>
00125     class KFbxFuncEventHandler : public KFbxEventHandler
00126     {
00127     // VC6Note: There's no reason why the callback is a (const EventType*,KFbxListener*) it is obvious that it should be
00128     //           a (const EventType&,KFbxListener*) but because of a VC6 template limitation, we put  a pointer.
00129     typedef void (*CBFunction)(const EventType*,KFbxListener*);
00130 
00131     public:
00132         KFbxFuncEventHandler(KFbxListener* pListener, CBFunction pFunc) :
00133             mFunc(pFunc),
00134             mListener(pListener){}
00135 
00136         // From KFbxEventHandler
00137         virtual int GetHandlerEventType(){ return EventType::GetStaticTypeId(); }   
00138         virtual void FunctionCall(const KFbxEventBase& pEvent){ (*mFunc)(reinterpret_cast<const EventType*>(&pEvent),mListener); }
00139         virtual KFbxListener* GetListener(){ return mListener; }
00140 
00141     private:
00142         KFbxListener* mListener;
00143 
00144         // The callback function
00145         CBFunction mFunc;
00146     };
00147 }
00148 // FBX namespace end
00149 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00150 
00151 #endif // FBXFILESDK_KFBXEVENTS_KFBXEVENTHANDLER_H
00152