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 {
00054     class KFBX_DLL KFbxEventBase
00055     {
00056       public:
00061 
00062          virtual ~KFbxEventBase();
00064 
00068          virtual int GetTypeId() const = 0;
00069 
00073          virtual const char* GetEventName() const = 0;   
00074 
00075         protected:
00076          static int GetStaticTypeId(char const*);
00077 
00078         private:
00079          /*static kfbxmp::KFbxMutex smMutex;*/
00080     };
00081 
00082     // Force events to declare a name by using an abstract method, and force them to use 
00083     // the proper name by making tne call from KFbxEvent<> go through the private static
00084     // method.
00085     #define KFBXEVENT_DECLARE(Class)                                                    \
00086       public: virtual const char* GetEventName() const { return FbxEventName(); }       \
00087       private: static const char* FbxEventName() { return #Class; }                     \
00088       friend class KFbxEvent<Class>;
00089 
00090     //
00091     // Similar to above, but to be used when you've got an event template, and the
00092     // type is something know to FBX
00093     //
00094     #define KFBXEVENT_DECLARE_FBXTYPE(Class, FBXType)                                  \
00095       public: virtual const char* GetEventName() const { return FbxEventName(); }      \
00096       private:                                                                         \
00097          static const char* FbxEventName() {                                           \
00098          static KString lEventName = KString(#Class) + KString("<") +                  \
00099          GetFbxDataType(FbxTypeOf(*((FBXType const*)0))).GetName() + ">";               \
00100                                                                                        \
00101          return lEventName.Buffer();                                                   \
00102       }                                                                                \
00103       friend class KFbxEvent< Class<FBXType> >;
00104 
00105 
00106 
00107     //This is for templates classes that will uses non fbxtypes in their templates
00108     //We force the the creation of an UNIQUE string for each types so that we can
00109     //retrieve the event within multiple DLLs
00110 
00111     //to be able to use this, the char EventName[] = "uniqueEventName"; must be declared
00112     //globally.
00113 
00114     #define KFBXEVENT_TEMPLATE_HEADER_NOT_FBXTYPE(ClassName, TemplateName)\
00115     template < class TemplateName, const char* T > \
00116     class ClassName: public kfbxevents:: KFbxEvent< ClassName <TemplateName,T> >\
00117     {\
00118         public: virtual const char* GetEventName() const {return FbxEventName();}\
00119         private: static const char* FbxEventName() {\
00120         static KString lEventName = (KString(#ClassName) +"<"+ KString(T) +">");\
00121         return lEventName.Buffer();\
00122         }\
00123         friend class KFbxEvent< ClassName<TemplateName, T> >;
00124 
00125 
00126     //This is the footer macro, to put at the end to close the template class
00127     //created by KFBXEVENT_TEMPLATE_HEADER_NOT_FBXTYPE
00128     #define KFBXEVENT_TEMPLATE_FOOTER_NOT_FBXTYPE()\
00129     };
00130 
00131 
00132     //---------------------------------------------------
00133     // EventT : We use the curiously recurring template pattern
00134     //          to initialize the typeId of each event type
00135     template<typename EventT>
00136     class KFbxEvent : public KFbxEventBase
00137     {
00138     public:
00139         virtual ~KFbxEvent(){}
00140         static void ForceTypeId(int pTypeId)
00141         {
00142             //kfbxmp::KFbxMutexHelper lLock( smMutex );
00143 
00144             // This is to handle specific cases where the type ID must be hard coded
00145             // It is useful for shared event across DLL. We can then guarantee that
00146             // The ID of a certain type will always have the same ID
00147             smTypeId = pTypeId;
00148         }
00149 
00151         virtual int GetTypeId() const 
00152         {
00153             return GetStaticTypeId();
00154         }
00155 
00156         static int GetStaticTypeId() 
00157         {
00158             if( !smTypeId )
00159             {
00160                 //kfbxmp::KFbxMutexHelper lLock( smMutex );
00161 
00162                 if( !smTypeId )
00163                 {
00164                     // If this does not compile, you need to add 
00165                     // KFBXEVENT_DECLARE(YourEventClassName) to your class declaration
00166                     smTypeId  = KFbxEventBase::GetStaticTypeId(EventT::FbxEventName());
00167                 }
00168             }
00169 
00170            return smTypeId;
00171         }
00172 
00173     private:
00174         static int smTypeId;
00175         /*static kfbxmp::KFbxMutex smMutex;*/
00176     };
00177 
00178     // Static members implementation
00179     template<typename EventT>
00180     int KFbxEvent<EventT>::smTypeId = 0;
00181     /*template<typename EventT>
00182     kfbxmp::KFbxMutex KFbxEvent<EventT>::smMutex;*/
00183 }
00184 using namespace kfbxevents;
00185 
00186 
00187 // FBX namespace end
00188 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00189 
00190 #endif // FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00191