fbxevent.h

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