PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Source/Modules/module.cxx

#
C++ | 61 lines | 31 code | 8 blank | 22 comment | 3 complexity | 28420f8a92eebcce5c7e4a9367679e95 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. /* -----------------------------------------------------------------------------
  2. * This file is part of SWIG, which is licensed as a whole under version 3
  3. * (or any later version) of the GNU General Public License. Some additional
  4. * terms also apply to certain portions of SWIG. The full details of the SWIG
  5. * license and copyrights can be found in the LICENSE and COPYRIGHT files
  6. * included with the SWIG source code as distributed by the SWIG developers
  7. * and at http://www.swig.org/legal.html.
  8. *
  9. * module.cxx
  10. *
  11. * This file is responsible for the module system.
  12. * ----------------------------------------------------------------------------- */
  13. char cvsroot_module_cxx[] = "$Id: module.cxx 11876 2010-02-27 23:53:33Z wsfulton $";
  14. #include "swigmod.h"
  15. struct Module {
  16. ModuleFactory fac;
  17. char *name;
  18. Module *next;
  19. Module(const char *n, ModuleFactory f) {
  20. fac = f;
  21. name = new char[strlen(n) + 1];
  22. strcpy(name, n);
  23. next = 0;
  24. } ~Module() {
  25. delete[]name;
  26. }
  27. };
  28. static Module *modules = 0;
  29. /* -----------------------------------------------------------------------------
  30. * void Swig_register_module()
  31. *
  32. * Register a module.
  33. * ----------------------------------------------------------------------------- */
  34. void Swig_register_module(const char *n, ModuleFactory f) {
  35. Module *m = new Module(n, f);
  36. m->next = modules;
  37. modules = m;
  38. }
  39. /* -----------------------------------------------------------------------------
  40. * Language *Swig_find_module()
  41. *
  42. * Given a command line option, locates the factory function.
  43. * ----------------------------------------------------------------------------- */
  44. ModuleFactory Swig_find_module(const char *name) {
  45. Module *m = modules;
  46. while (m) {
  47. if (strcmp(m->name, name) == 0) {
  48. return m->fac;
  49. }
  50. m = m->next;
  51. }
  52. return 0;
  53. }