fbxemitter.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxemitter.h
  9. #ifndef _FBXSDK_CORE_EMITTER_H_
  10. #define _FBXSDK_CORE_EMITTER_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/base/fbxintrusivelist.h>
  13. #include <fbxsdk/core/fbxeventhandler.h>
  14. #include <fbxsdk/fbxsdk_nsbegin.h>
  15. class FbxListener;
  16. /** Base class to emit event with the specified event type.
  17. * The event type could be a specific class which derived from FbxEvent. Please read FbxEmitter::Emit() for more details.
  18. * Event emitter contains a list of event handlers.
  19. * FBX object could be used as emitter, since FbxObject is derived from FbxEmitter.
  20. * Before using emitter to emit an event, one or more event handlers must be added to the handlers list of current emitter.
  21. * In other words, it's "bind event handlers to emitter".
  22. * There are two ways to bind event handlers to emitter.
  23. * \li 1. If you already got an event handler and would like to bind it to current emitter, please call FbxEmitter::AddListener().
  24. * \li 2. Or you can create an event listener first and then call FbxListener::Bind().
  25. * It will create an event handler automatically and bind the handler to the specified emitter.
  26. * It's similar to unbind or remove an even handler. For more details,
  27. * \see FbxEmitter::RemoveListener()
  28. * \see FbxListener::Unbind()
  29. * \remarks An object(emitter) can emit a certain type of event, the plug-in(listener) who are listening to that type of event,
  30. * will receive a signal and take action to process the event data.
  31. * \par The whole process of event is:
  32. * \li 1. Create an emitter and a listener, then bind them together via the same event handler.
  33. * \li 2. Emitter can emit an event at certain conditions. The event could be handled by event handler.
  34. * \li 3. Once an event is emitted, the listener to this event will receive a signal.
  35. * \li 4. And then the listener could process the event data according to the types of event, by calling event handler.
  36. * \note The event data is process by the callback function of event handler.
  37. * \nosubgrouping
  38. * \see FbxListener FbxEventHandler FbxEvent FbxEventBase
  39. */
  40. class FBXSDK_DLL FbxEmitter
  41. {
  42. public:
  43. /** Add the specified event handler to current emitter list.
  44. * \param pHandler The event handler will be added to the handlers list of current emitter. */
  45. void AddListener(FbxEventHandler& pHandler);
  46. /** Remove the specified event handler from current emitter list.
  47. * \param pHandler The event handler will be removed from the handlers list of current emitter. */
  48. void RemoveListener(FbxEventHandler& pHandler);
  49. /** Emit an event with the specified the event type. One the event is emitted, the listener to this event will receive a signal.
  50. * \param pEvent Specify the event type to emit. Could be a specific class which derived from FbxEvent, such as FbxObjectPropertyChanged.
  51. * \see FbxEventBase FbxObjectPropertyChanged FbxEventReferencedDocument FbxEventPostExport
  52. * \see FbxEventPostImport FbxEventPreExport FbxEventPreImport FbxEventPopulateSystemLibrary */
  53. template <typename EventType> void Emit(const EventType& pEvent) const
  54. {
  55. if( !mData ) return;
  56. EventHandlerList::iterator itBegin = mData->mEventHandlerList.Begin();
  57. EventHandlerList::iterator itEnd = mData->mEventHandlerList.End();
  58. for( EventHandlerList::iterator it = itBegin; it != itEnd; ++it )
  59. {
  60. if ((*it).GetHandlerEventType() == pEvent.GetTypeId())
  61. {
  62. (*it).FunctionCall(pEvent);
  63. }
  64. }
  65. }
  66. /*****************************************************************************************************************************
  67. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  68. *****************************************************************************************************************************/
  69. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  70. FbxEmitter();
  71. ~FbxEmitter();
  72. protected:
  73. typedef FbxIntrusiveList<FbxEventHandler, FbxEventHandler::eEmitter> EventHandlerList;
  74. struct EventData { EventHandlerList mEventHandlerList; };
  75. EventData* mData;
  76. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  77. };
  78. #include <fbxsdk/fbxsdk_nsend.h>
  79. #endif /* _FBXSDK_CORE_EMITTER_H_ */