kfbxevents.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00005 #define FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2010 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 #include <fbxfilesdk/kfbxplugins/kfbxtypes.h>
00044 #include <fbxfilesdk/kfbxplugins/kfbxdatatypes.h>
00045 #include <fbxfilesdk/kfbxmp/kfbxmutex.h>
00046 
00047 // FBX namespace begin
00048 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00049 namespace kfbxevents
00050 {
00069     class KFBX_DLL KFbxEventBase
00070     {
00071       public:
00076 
00077          virtual ~KFbxEventBase();
00079 
00083          virtual int GetTypeId() const = 0;
00084 
00088          virtual const char* GetEventName() const = 0;   
00089 
00090         protected:
00091          static int GetStaticTypeId(char const*);
00092 
00093         private:
00094          static kfbxmp::KFbxMutex smMutex;
00095     };
00096 
00097     // Force events to declare a name by using an abstract method, and force them to use 
00098     // the proper name by making the call from KFbxEvent<> go through the private static
00099     // method.
00100     #define KFBXEVENT_DECLARE(Class)                                                    \
00101       public: virtual const char* GetEventName() const { return FbxEventName(); }       \
00102       private: static const char* FbxEventName() { return #Class; }                     \
00103       friend class KFbxEvent<Class>;
00104 
00105     //
00106     // Similar to above, but to be used when you've got an event template, and the
00107     // type is something know to FBX
00108     //
00109     #define KFBXEVENT_DECLARE_FBXTYPE(Class, FBXType)                                  \
00110       public: virtual const char* GetEventName() const { return FbxEventName(); }      \
00111       private:                                                                         \
00112          static const char* FbxEventName() {                                           \
00113          static KString lEventName = KString(#Class) + KString("<") +                  \
00114          GetFbxDataType(FbxTypeOf(*((FBXType const*)0))).GetName() + ">";               \
00115                                                                                        \
00116          return lEventName.Buffer();                                                   \
00117       }                                                                                \
00118       friend class KFbxEvent< Class<FBXType> >;
00119 
00120 
00121 
00122     //This is for templates classes that will uses non fbxtypes in their templates
00123     //We force the the creation of an UNIQUE string for each types so that we can
00124     //retrieve the event within multiple DLLs
00125 
00126     //to be able to use this, the char EventName[] = "uniqueEventName"; must be declared
00127     //globally.
00128 
00129     #define KFBXEVENT_TEMPLATE_HEADER_NOT_FBXTYPE(ClassName, TemplateName)\
00130     template < class TemplateName, const char* T > \
00131     class ClassName: public kfbxevents:: KFbxEvent< ClassName <TemplateName,T> >\
00132     {\
00133         public: virtual const char* GetEventName() const {return FbxEventName();}\
00134         private: static const char* FbxEventName() {\
00135         static KString lEventName = (KString(#ClassName) +"<"+ KString(T) +">");\
00136         return lEventName.Buffer();\
00137         }\
00138         friend class KFbxEvent< ClassName<TemplateName, T> >;
00139 
00140 
00141     //This is the footer macro, to put at the end to close the template class
00142     //created by KFBXEVENT_TEMPLATE_HEADER_NOT_FBXTYPE
00143     #define KFBXEVENT_TEMPLATE_FOOTER_NOT_FBXTYPE()\
00144     };
00145 
00163     //---------------------------------------------------
00164     // EventT : We use the curiously recurring template pattern
00165     //          to initialize the typeId of each event type
00166     template<typename EventT>
00167     class KFbxEvent : public KFbxEventBase
00168     {
00169     public:
00171         virtual ~KFbxEvent(){}
00172 
00176         static void ForceTypeId(int pTypeId)
00177         {
00178             kfbxmp::KFbxMutexHelper lLock( smMutex );
00179 
00180             // This is to handle specific cases where the type ID must be hard coded
00181             // It is useful for shared event across DLL. We can then guarantee that
00182             // The ID of a certain type will always have the same ID
00183             smTypeId = pTypeId;
00184         }
00185 
00190         virtual int GetTypeId() const 
00191         {
00192             return GetStaticTypeId();
00193         }
00194 
00198         static int GetStaticTypeId() 
00199         {
00200             if( !smTypeId )
00201             {
00202                 kfbxmp::KFbxMutexHelper lLock( smMutex );
00203 
00204                 if( !smTypeId )
00205                 {
00206                     // If this does not compile, you need to add 
00207                     // KFBXEVENT_DECLARE(YourEventClassName) to your class declaration
00208                     smTypeId  = KFbxEventBase::GetStaticTypeId(EventT::FbxEventName());
00209                 }
00210             }
00211 
00212            return smTypeId;
00213         }
00214 
00215     private:
00217         static int smTypeId;
00218         static kfbxmp::KFbxMutex smMutex;
00219     };
00220 
00221     // Static members implementation
00222     template<typename EventT>
00223     int KFbxEvent<EventT>::smTypeId = 0;
00224     template<typename EventT>
00225     kfbxmp::KFbxMutex KFbxEvent<EventT>::smMutex;
00226 }
00227 using namespace kfbxevents;
00228 
00229 
00230 // FBX namespace end
00231 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00232 
00233 #endif // FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00234