SysAppFactory.h 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * SysAppFactory.h
  3. *
  4. * Created on: Oct 25, 2017
  5. * Author: guoxs
  6. */
  7. #ifndef _APP_SYSAPP_FACTORY_H_
  8. #define _APP_SYSAPP_FACTORY_H_
  9. #include <vector>
  10. #include "AppTypeDef.h"
  11. #include "BaseApp.h"
  12. class SysAppFactory {
  13. public:
  14. static SysAppFactory *getInstance();
  15. bool registerSysApp(int appType, BaseApp* (*create)());
  16. BaseApp* create(int appType);
  17. private:
  18. SysAppFactory() { }
  19. private:
  20. typedef struct {
  21. int appType;
  22. BaseApp* (*create)();
  23. } SSysAppInfo;
  24. std::vector<SSysAppInfo> mSysAppInfos;
  25. };
  26. #define SYSAPPFACTORY SysAppFactory::getInstance()
  27. #define REGISTER_SYSAPP(appType, _class) \
  28. static struct _SysAppFactory_##_class { \
  29. static BaseApp* create() { \
  30. return new _class(); \
  31. } \
  32. _SysAppFactory_##_class() { \
  33. SYSAPPFACTORY->registerSysApp(appType, create); \
  34. } \
  35. } _autoRegister_SysApp_##_class
  36. #endif /* _APP_SYSAPP_FACTORY_H_ */