tb_addon.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_ADDON_H
  6. #define TB_ADDON_H
  7. #include "tb_linklist.h"
  8. #include "tb_widgets.h"
  9. namespace tb {
  10. /** TBAddon provides a simple API with Init/Shutdown callbacks that will
  11. be called during tb_core_init and tb_core_shutdown.
  12. THIS CLASS IS DEPRECATED! */
  13. class TBAddon : public TBLinkOf<TBAddon>
  14. {
  15. public:
  16. /** Called during tb_core_init after turbo badger core has been initiated. */
  17. virtual bool Init() = 0;
  18. /** Called during tb_core_shutdown before turbo badger core has been shut down. */
  19. virtual void Shutdown() = 0;
  20. virtual ~TBAddon() {}
  21. };
  22. /** TBAddonFactory is ment to be subclassed to create a TBAddon, by
  23. being declared as a global object. It will then register itself
  24. so the addon is created, initiated during tb_core_init and
  25. destroyed during tb_core_shutdown.
  26. THIS CLASS IS DEPRECATED! */
  27. class TBAddonFactory
  28. {
  29. public:
  30. TBAddonFactory();
  31. virtual TBAddon *Create() = 0;
  32. TBAddonFactory *next; ///< Next registered addon factory.
  33. };
  34. /** Init addons. */
  35. bool TBInitAddons();
  36. /** Shutdown and delete addons. */
  37. void TBShutdownAddons();
  38. /** This macro creates a new TBAddonFactory for the given class name. */
  39. #define TB_ADDON_FACTORY(classname) \
  40. class classname##AddonFactory : public TBAddonFactory \
  41. { \
  42. public: \
  43. virtual TBAddon *Create() \
  44. { \
  45. return new classname(); \
  46. } \
  47. }; \
  48. static classname##AddonFactory classname##_af;
  49. }; // namespace tb
  50. #endif // TB_ADDON_H