You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.0KB

  1. //
  2. // "$Id: Fl_Plugin.H 6995 2010-01-12 08:48:55Z matt $"
  3. //
  4. // A Plugin system for FLTK, implemented in Fl_Preferences.cxx.
  5. //
  6. // Copyright 2002-2010 by Matthias Melcher.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /* \file
  28. Fl_Plugin class . */
  29. #ifndef Fl_Plugin_H
  30. # define Fl_Plugin_H
  31. # include "Fl_Preferences.H"
  32. /**
  33. \brief Fl_Plugin allows link-time and run-time integration of binary modules.
  34. Fl_Plugin and Fl_Plugin_Manager provide a small and simple solution for
  35. linking C++ classes at run-time, or optionally linking modules at compile
  36. time without the need to change the main application.
  37. Fl_Plugin_Manager uses static initialisation to create the plugin interface
  38. early during startup. Plugins are stored in a temporary database, organized
  39. in classes.
  40. Plugins should derive a new class from Fl_Plugin as a base:
  41. \code
  42. class My_Plugin : public Fl_Plugin {
  43. public:
  44. My_Plugin() : Fl_Plugin("effects", "blur") { }
  45. void do_something(...);
  46. };
  47. My_Plugin blur_plugin();
  48. \endcode
  49. Plugins can be put into modules and either linked before distribution, or loaded
  50. from dynamically linkable files. An Fl_Plugin_Manager is used to list and
  51. access all currently loaded plugins.
  52. \code
  53. Fl_Plugin_Manager mgr("effects");
  54. int i, n = mgr.plugins();
  55. for (i=0; i<n; i++) {
  56. My_Plugin *pin = (My_Plugin*)mgr.plugin(i);
  57. pin->do_something();
  58. }
  59. \endcode
  60. */
  61. class FL_EXPORT Fl_Plugin {
  62. Fl_Preferences::ID id;
  63. public:
  64. Fl_Plugin(const char *klass, const char *name);
  65. virtual ~Fl_Plugin();
  66. };
  67. /**
  68. \brief Fl_Plugin_Manager manages link-time and run-time plugin binaries.
  69. \see Fl_Plugin
  70. */
  71. class FL_EXPORT Fl_Plugin_Manager : public Fl_Preferences {
  72. public:
  73. Fl_Plugin_Manager(const char *klass);
  74. ~Fl_Plugin_Manager();
  75. /** \brief Return the number of plugins in the klass.
  76. */
  77. int plugins() { return groups(); }
  78. Fl_Plugin *plugin(int index);
  79. Fl_Plugin *plugin(const char *name);
  80. Fl_Preferences::ID addPlugin(const char *name, Fl_Plugin *plugin);
  81. static void removePlugin(Fl_Preferences::ID id);
  82. static int load(const char *filename);
  83. static int loadAll(const char *filepath, const char *pattern=0);
  84. };
  85. #endif // !Fl_Preferences_H
  86. //
  87. // End of "$Id: Fl_Preferences.H 6995 2010-01-12 08:48:55Z matt $".
  88. //