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 10char cvsroot_module_cxx[] = "$Id: module.cxx 10003 2007-10-17 21:42:11Z wsfulton $"; 11 12#include "swigmod.h" 13 14struct Module { 15 ModuleFactory fac; 16 char *name; 17 Module *next; 18 Module(const char *n, ModuleFactory f) { 19 fac = f; 20 name = new char[strlen(n) + 1]; 21 strcpy(name, n); 22 next = 0; 23 } ~Module() { 24 delete[]name; 25 } 26}; 27 28static Module *modules = 0; 29 30/* ----------------------------------------------------------------------------- 31 * void Swig_register_module() 32 * 33 * Register a module. 34 * ----------------------------------------------------------------------------- */ 35 36void Swig_register_module(const char *n, ModuleFactory f) { 37 Module *m = new Module(n, f); 38 m->next = modules; 39 modules = m; 40} 41 42/* ----------------------------------------------------------------------------- 43 * Language *Swig_find_module() 44 * 45 * Given a command line option, locates the factory function. 46 * ----------------------------------------------------------------------------- */ 47 48ModuleFactory Swig_find_module(const char *name) { 49 Module *m = modules; 50 while (m) { 51 if (strcmp(m->name, name) == 0) { 52 return m->fac; 53 } 54 m = m->next; 55 } 56 return 0; 57} 58