FBX C++ API Reference
fbxevent.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_CORE_EVENT_H_
14 #define _FBXSDK_CORE_EVENT_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
19 
20 #include <fbxsdk/fbxsdk_nsbegin.h>
21 
41 {
42  public:
47  virtual ~FbxEventBase();
50 
54  virtual int GetTypeId() const = 0;
55 
59  virtual const char* GetEventName() const = 0;
60 
61  protected:
62  static int GetStaticTypeId(const char*);
63 };
64 
65 // Force events to declare a name by using an abstract method, and force them to use
66 // the proper name by making the call from FbxEvent<> go through the private static
67 // method.
68 #define FBXSDK_EVENT_DECLARE(Class) \
69  public: virtual const char* GetEventName() const { return FbxEventName(); } \
70  private: static const char* FbxEventName() { return #Class; } \
71  friend class FbxEvent<Class>; \
72 
73 //
74 // Similar to above, but to be used when you've got an event template, and the
75 // type is something know to FBX
76 //
77 #define FBXSDK_EVENT_TYPE_DECLARE(Class, FBXType) \
78  public: virtual const char* GetEventName() const { return FbxEventName(); } \
79  private: \
80  static const char* FbxEventName() { \
81  static FbxString lEventName = FbxString(#Class) + FbxString("<") + \
82  FbxGetDataTypeFromEnum(FbxTypeOf(*((const FBXType *)0))).GetName() + ">"; \
83  \
84  return lEventName.Buffer(); \
85  } \
86  friend class FbxEvent< Class<FBXType> >;
87 
88 
89 
90 //This is for templates classes that will uses non fbxtypes in their templates
91 //We force the the creation of an UNIQUE string for each types so that we can
92 //retrieve the event within multiple DLLs
93 
94 //to be able to use this, the char EventName[] = "uniqueEventName"; must be declared
95 //globally.
96 
97 #define FBXSDK_EVENT_TEMPLATE_HEADER(ClassName, TemplateName)\
98 template < class TemplateName, const char* T > \
99 class ClassName: public FbxEvent< ClassName <TemplateName,T> >\
100 {\
101  public: virtual const char* GetEventName() const {return FbxEventName();}\
102  private: static const char* FbxEventName() {\
103  static FbxString lEventName = (FbxString(#ClassName) +"<"+ FbxString(T) +">");\
104  return lEventName.Buffer();\
105  }\
106  friend class FbxEvent< ClassName<TemplateName, T> >;
107 
108 
109 //This is the footer macro, to put at the end to close the template class
110 //created by FBXSDK_EVENT_TEMPLATE_HEADER
111 #define FBXSDK_EVENT_TEMPLATE_FOOTER()\
112 };
113 
131 //---------------------------------------------------
132 // T : We use the curiously recurring template pattern
133 // to initialize the typeId of each event type
134 template<typename T> class FbxEvent : public FbxEventBase
135 {
136 public:
138  virtual ~FbxEvent(){}
139 
143  static void ForceTypeId(int pTypeId)
144  {
145  // This is to handle specific cases where the type ID must be hard coded
146  // It is useful for shared event across DLL. We can then guarantee that
147  // The ID of a certain type will always have the same ID
148  smTypeId = pTypeId;
149  }
150 
155  virtual int GetTypeId() const
156  {
157  return GetStaticTypeId();
158  }
159 
163  static int GetStaticTypeId()
164  {
165  if( !smTypeId )
166  {
167  if( !smTypeId )
168  {
169  // If this does not compile, you need to add
170  // FBXSDK_EVENT_DECLARE(YourEventClassName) to your class declaration
171  smTypeId = FbxEventBase::GetStaticTypeId(T::FbxEventName());
172  }
173  }
174 
175  return smTypeId;
176  }
177 
178 private:
180  static int smTypeId;
181 };
182 
183 // Static members implementation
184 template<typename T> int FbxEvent<T>::smTypeId = 0;
185 
186 #include <fbxsdk/fbxsdk_nsend.h>
187 
188 #endif /* _FBXSDK_CORE_EVENT_H_ */
FBX SDK environment definition.
static int GetStaticTypeId(const char *)
FBX SDK event base class.
Definition: fbxevent.h:40
virtual int GetTypeId() const
Retrieve the event type ID.
Definition: fbxevent.h:155
static void ForceTypeId(int pTypeId)
Update the type ID of current event with the given type ID.
Definition: fbxevent.h:143
static int GetStaticTypeId()
Retrieve the event type ID.
Definition: fbxevent.h:163
#define FBXSDK_DLL
Definition: fbxarch.h:173
virtual ~FbxEvent()
Destructor.
Definition: fbxevent.h:138
FBX event class, derived from FbxEventBase, and it contains a type ID for event.
Definition: fbxevent.h:134