PageRenderTime 32ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/rel-1.3.35/Source/Modules/module.cxx

#
C++ | 57 lines | 31 code | 8 blank | 18 comment | 3 complexity | cb11aa71293213d8e4470a43639670af MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * See the LICENSE file for information on copyright, usage and redistribution
  3. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
  4. *
  5. * module.cxx
  6. *
  7. * This file is responsible for the module system.
  8. * ----------------------------------------------------------------------------- */
  9. char cvsroot_module_cxx[] = "$Id: module.cxx 10003 2007-10-17 21:42:11Z wsfulton $";
  10. #include "swigmod.h"
  11. struct Module {
  12. ModuleFactory fac;
  13. char *name;
  14. Module *next;
  15. Module(const char *n, ModuleFactory f) {
  16. fac = f;
  17. name = new char[strlen(n) + 1];
  18. strcpy(name, n);
  19. next = 0;
  20. } ~Module() {
  21. delete[]name;
  22. }
  23. };
  24. static Module *modules = 0;
  25. /* -----------------------------------------------------------------------------
  26. * void Swig_register_module()
  27. *
  28. * Register a module.
  29. * ----------------------------------------------------------------------------- */
  30. void Swig_register_module(const char *n, ModuleFactory f) {
  31. Module *m = new Module(n, f);
  32. m->next = modules;
  33. modules = m;
  34. }
  35. /* -----------------------------------------------------------------------------
  36. * Language *Swig_find_module()
  37. *
  38. * Given a command line option, locates the factory function.
  39. * ----------------------------------------------------------------------------- */
  40. ModuleFactory Swig_find_module(const char *name) {
  41. Module *m = modules;
  42. while (m) {
  43. if (strcmp(m->name, name) == 0) {
  44. return m->fac;
  45. }
  46. m = m->next;
  47. }
  48. return 0;
  49. }