kfbxeventhandler.h

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