fbxsdk/core/fbxevent.h Source File
 
 
 
fbxsdk/core/fbxevent.h
Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2013 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_H_
00014 #define _FBXSDK_CORE_EVENT_H_
00015 
00016 #include <fbxsdk/fbxsdk_def.h>
00017 
00018 #include <fbxsdk/core/fbxpropertytypes.h>
00019 
00020 #include <fbxsdk/fbxsdk_nsbegin.h>
00021 
00040 class FBXSDK_DLL FbxEventBase
00041 {
00042   public:
00047 
00048      virtual ~FbxEventBase();
00050 
00054      virtual int GetTypeId() const = 0;
00055 
00059      virtual const char* GetEventName() const = 0;   
00060 
00061         protected:
00062      static int GetStaticTypeId(const char*);
00063 };
00064 
00065 // Force events to declare a name by using an abstract method, and force them to use 
00066 // the proper name by making the call from FbxEvent<> go through the private static
00067 // method.
00068 #define FBXSDK_EVENT_DECLARE(Class)                                                                                             \
00069         public: virtual const char* GetEventName() const { return FbxEventName(); }     \
00070         private: static const char* FbxEventName() { return #Class; }                           \
00071         friend class FbxEvent<Class>;                                                                                           \
00072 
00073 //
00074 // Similar to above, but to be used when you've got an event template, and the
00075 // type is something know to FBX
00076 //
00077 #define FBXSDK_EVENT_TYPE_DECLARE(Class, FBXType)                                  \
00078   public: virtual const char* GetEventName() const { return FbxEventName(); }      \
00079   private:                                                                         \
00080      static const char* FbxEventName() {                                           \
00081      static FbxString lEventName = FbxString(#Class) + FbxString("<") +                  \
00082      FbxGetDataTypeFromEnum(FbxTypeOf(*((const FBXType *)0))).GetName() + ">";               \
00083                                                                                    \
00084      return lEventName.Buffer();                                                   \
00085   }                                                                                \
00086   friend class FbxEvent< Class<FBXType> >;
00087 
00088 
00089 
00090 //This is for templates classes that will uses non fbxtypes in their templates
00091 //We force the the creation of an UNIQUE string for each types so that we can
00092 //retrieve the event within multiple DLLs
00093 
00094 //to be able to use this, the char EventName[] = "uniqueEventName"; must be declared
00095 //globally.
00096 
00097 #define FBXSDK_EVENT_TEMPLATE_HEADER(ClassName, TemplateName)\
00098 template < class TemplateName, const char* T > \
00099 class ClassName: public  FbxEvent< ClassName <TemplateName,T> >\
00100 {\
00101     public: virtual const char* GetEventName() const {return FbxEventName();}\
00102     private: static const char* FbxEventName() {\
00103     static FbxString lEventName = (FbxString(#ClassName) +"<"+ FbxString(T) +">");\
00104     return lEventName.Buffer();\
00105     }\
00106     friend class FbxEvent< ClassName<TemplateName, T> >;
00107 
00108 
00109 //This is the footer macro, to put at the end to close the template class
00110 //created by FBXSDK_EVENT_TEMPLATE_HEADER
00111 #define FBXSDK_EVENT_TEMPLATE_FOOTER()\
00112 };
00113 
00131 //---------------------------------------------------
00132 // T : We use the curiously recurring template pattern
00133 //          to initialize the typeId of each event type
00134 template<typename T> class FbxEvent : public FbxEventBase
00135 {
00136 public:
00138     virtual ~FbxEvent(){}
00139 
00143     static void ForceTypeId(int pTypeId)
00144     {
00145         // This is to handle specific cases where the type ID must be hard coded
00146         // It is useful for shared event across DLL. We can then guarantee that
00147         // The ID of a certain type will always have the same ID
00148         smTypeId = pTypeId;
00149     }
00150 
00155     virtual int GetTypeId() const 
00156     {
00157                 return GetStaticTypeId();
00158     }
00159 
00163     static int GetStaticTypeId() 
00164     {
00165         if( !smTypeId )
00166         {
00167             if( !smTypeId )
00168             {
00169                 // If this does not compile, you need to add 
00170                 // FBXSDK_EVENT_DECLARE(YourEventClassName) to your class declaration
00171                 smTypeId  = FbxEventBase::GetStaticTypeId(T::FbxEventName());
00172             }
00173         }
00174 
00175        return smTypeId;
00176     }
00177 
00178 private:
00180     static int smTypeId;
00181 };
00182 
00183 // Static members implementation
00184 template<typename T> int FbxEvent<T>::smTypeId = 0;
00185 
00186 #include <fbxsdk/fbxsdk_nsend.h>
00187 
00188 #endif /* _FBXSDK_CORE_EVENT_H_ */