00001 
00004 #ifndef FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00005 #define FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 #include <fbxfilesdk/components/kbaselib/kaydaradef_h.h>
00043 #include <fbxfilesdk/kfbxplugins/kfbxtypes.h>
00044 #include <fbxfilesdk/kfbxplugins/kfbxdatatypes.h>
00045 #include <fbxfilesdk/kfbxmp/kfbxmutex.h>
00046 
00047 
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     
00083     
00084     
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     
00092     
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     
00108     
00109     
00110 
00111     
00112     
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     
00127     
00128     #define KFBXEVENT_TEMPLATE_FOOTER_NOT_FBXTYPE()\
00129     };
00130 
00131 
00132     
00133     
00134     
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             
00145             
00146             
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                     
00165                     
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     
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 
00188 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00189 
00190 #endif // FBXFILESDK_KFBXEVENTS_KFBXEVENTS_H
00191