Fl_Plugin.H 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_Plugin class . */
  20. #ifndef Fl_Plugin_H
  21. # define Fl_Plugin_H
  22. # include "Fl_Preferences.H"
  23. /**
  24. \brief Fl_Plugin allows link-time and run-time integration of binary modules.
  25. Fl_Plugin and Fl_Plugin_Manager provide a small and simple solution for
  26. linking C++ classes at run-time, or optionally linking modules at compile
  27. time without the need to change the main application.
  28. Fl_Plugin_Manager uses static initialisation to create the plugin interface
  29. early during startup. Plugins are stored in a temporary database, organized
  30. in classes.
  31. Plugins should derive a new class from Fl_Plugin as a base:
  32. \code
  33. class My_Plugin : public Fl_Plugin {
  34. public:
  35. My_Plugin() : Fl_Plugin("effects", "blur") { }
  36. void do_something(...);
  37. };
  38. My_Plugin blur_plugin();
  39. \endcode
  40. Plugins can be put into modules and either linked before distribution, or loaded
  41. from dynamically linkable files. An Fl_Plugin_Manager is used to list and
  42. access all currently loaded plugins.
  43. \code
  44. Fl_Plugin_Manager mgr("effects");
  45. int i, n = mgr.plugins();
  46. for (i=0; i<n; i++) {
  47. My_Plugin *pin = (My_Plugin*)mgr.plugin(i);
  48. pin->do_something();
  49. }
  50. \endcode
  51. */
  52. class FL_EXPORT Fl_Plugin {
  53. Fl_Preferences::ID id;
  54. public:
  55. Fl_Plugin(const char *klass, const char *name);
  56. virtual ~Fl_Plugin();
  57. };
  58. /**
  59. \brief Fl_Plugin_Manager manages link-time and run-time plugin binaries.
  60. \see Fl_Plugin
  61. */
  62. class FL_EXPORT Fl_Plugin_Manager : public Fl_Preferences {
  63. public:
  64. Fl_Plugin_Manager(const char *klass);
  65. ~Fl_Plugin_Manager();
  66. /** \brief Return the number of plugins in the klass.
  67. */
  68. int plugins() { return groups(); }
  69. Fl_Plugin *plugin(int index);
  70. Fl_Plugin *plugin(const char *name);
  71. Fl_Preferences::ID addPlugin(const char *name, Fl_Plugin *plugin);
  72. static void removePlugin(Fl_Preferences::ID id);
  73. static int load(const char *filename);
  74. static int loadAll(const char *filepath, const char *pattern=0);
  75. };
  76. #endif // !Fl_Preferences_H
  77. //
  78. // End of "$Id: Fl_Preferences.H 6995 2010-01-12 08:48:55Z matt $".
  79. //