PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Source/Modules/module.cxx

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