SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
ModuleRegistry.cc
Go to the documentation of this file.
1 #include "ModuleRegistry.hh"
2 
3 // slic
4 #include "Module.hh"
5 
6 // geant4
7 #include "globals.hh"
8 
9 namespace slic {
11  Module("ModuleRegistry", false, false) {
12 }
13 
15 }
16 
17 Module* ModuleRegistry::findModule(const std::string& name) {
18  return m_modules[name];
19 }
20 
22  if (module == 0) {
23  log().warning("ModuleRegistry::registerModule - module points to null!");
24  return;
25  }
26 
27  if (m_modules[module->getName()] == 0) {
28  m_modules[module->getName()] = module;
29  } else {
30  log().warning(module->getName() + " is already registered!");
31  }
32 }
33 
35  deregisterModule(module->getName());
36 }
37 
38 void ModuleRegistry::deregisterModule(const std::string& name) {
39  ModuleMap::iterator it = m_modules.find(name);
40 
41  if (it != m_modules.end()) {
42  m_modules.erase(it);
43  }
44 }
45 
47  log() << LOG::always << LOG::endl;
48  log() << LOG::always << "********************" << LOG::endl;
49  log() << LOG::always << "* Module Registry *" << LOG::endl;
50  log() << LOG::always << "********************" << LOG::endl;
51  for (ModuleMap::const_iterator it = m_modules.begin(); it != m_modules.end(); it++) {
52  log() << LOG::always << it->first << LOG::endl;
53  }
54 }
55 
57  for (ModuleMap::iterator it = m_modules.begin(); it != m_modules.end(); it++) {
58  // Delete it as long as Module has not
59  // been flagged to not delete on exit.
60  if (it->second->deleteOnExit()) {
61  delete it->second;
62  }
63  }
64 }
65 }
LogStream & warning()
Definition: LogStream.hh:254
Module * findModule(const std::string &name)
void registerModule(Module *module)
void deregisterModule(Module *module)
Base class for slic code modules that provides common functionality, such as logging to an output str...
Definition: Module.hh:25
const std::string & getName() const
Definition: Module.hh:54
LogStream & log()
Definition: Module.hh:99
@ always
Definition: LogStream.hh:33
@ name
Definition: LogStream.hh:26
@ endl
Definition: LogStream.hh:26