Module.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Copyright (c) 2006-2018 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #ifndef LOVE_MODULE_H
  21. #define LOVE_MODULE_H
  22. // LOVE
  23. #include "Exception.h"
  24. #include "Object.h"
  25. namespace love
  26. {
  27. /**
  28. * Abstract superclass for all modules.
  29. **/
  30. class Module : public Object
  31. {
  32. public:
  33. static love::Type type;
  34. enum ModuleType
  35. {
  36. M_AUDIO,
  37. M_DATA,
  38. M_EVENT,
  39. M_FILESYSTEM,
  40. M_FONT,
  41. M_GRAPHICS,
  42. M_IMAGE,
  43. M_JOYSTICK,
  44. M_KEYBOARD,
  45. M_MATH,
  46. M_MOUSE,
  47. M_PHYSICS,
  48. M_SOUND,
  49. M_SYSTEM,
  50. M_THREAD,
  51. M_TIMER,
  52. M_TOUCH,
  53. M_VIDEO,
  54. M_WINDOW,
  55. M_MAX_ENUM
  56. };
  57. Module();
  58. virtual ~Module();
  59. /**
  60. * Gets the base type of the module.
  61. **/
  62. virtual ModuleType getModuleType() const = 0;
  63. /**
  64. * Gets the name of the module. This is used in case of errors
  65. * and other messages.
  66. *
  67. * @return The full name of the module, eg. love.graphics.opengl.
  68. **/
  69. virtual const char *getName() const = 0;
  70. /**
  71. * Add module to internal registry. To be used /only/ in
  72. * runtime.cpp:luax_register_module()
  73. * @param instance The module instance.
  74. */
  75. static void registerInstance(Module *instance);
  76. /**
  77. * Retrieve module instance from internal registry. May return NULL
  78. * if module not registered.
  79. * @param name The full name of the module.
  80. * @return Module instance or NULL if the module is not registered.
  81. */
  82. static Module *getInstance(const std::string &name);
  83. /**
  84. * Retrieve module instance from the internal registry using the base
  85. * module type. May return null if the module is not registered.
  86. * @param type The base type of the module.
  87. **/
  88. template <typename T>
  89. static T *getInstance(ModuleType type)
  90. {
  91. return (T *) instances[type];
  92. }
  93. private:
  94. static Module *instances[M_MAX_ENUM];
  95. }; // Module
  96. } // love
  97. #endif // LOVE_MODULE_H