| 1 | /**
|
|---|
| 2 | * @file factory.cpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Tue Apr 5 20:40:05 2011
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #ifdef HAVE_CONFIG_H
|
|---|
| 8 | #include <config.h>
|
|---|
| 9 | #endif
|
|---|
| 10 |
|
|---|
| 11 | #include <cassert>
|
|---|
| 12 | #include <cstdio>
|
|---|
| 13 | #include <iostream>
|
|---|
| 14 |
|
|---|
| 15 | #include "base/command.hpp"
|
|---|
| 16 | #include "base/discretization.hpp"
|
|---|
| 17 | #include "base/factory.hpp"
|
|---|
| 18 | #include "base/object.hpp"
|
|---|
| 19 | #include "comm/comm.hpp"
|
|---|
| 20 | #include "grid/multigrid.hpp"
|
|---|
| 21 | #include "grid/tempgrid.hpp"
|
|---|
| 22 | #include "level/level_operator.hpp"
|
|---|
| 23 | #include "smoother/smoother.hpp"
|
|---|
| 24 | #include "solver/solver.hpp"
|
|---|
| 25 | #include "mg.hpp"
|
|---|
| 26 |
|
|---|
| 27 | using namespace VMG;
|
|---|
| 28 |
|
|---|
| 29 | Factory::Factory()
|
|---|
| 30 | {
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | Factory::~Factory()
|
|---|
| 34 | {
|
|---|
| 35 | for (std::map<std::string, Object*>::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
|
|---|
| 36 | delete iter->second;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | void Factory::Register(Object* object)
|
|---|
| 40 | {
|
|---|
| 41 | Delete(object->Name());
|
|---|
| 42 | object_map.insert(std::make_pair(object->Name(), object));
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | Object* Factory::Get(std::string id)
|
|---|
| 46 | {
|
|---|
| 47 | std::map<std::string, Object*>::iterator iter = object_map.find(id);
|
|---|
| 48 |
|
|---|
| 49 | if (iter != object_map.end())
|
|---|
| 50 | return iter->second;
|
|---|
| 51 |
|
|---|
| 52 | MG::GetComm()->PrintStringOnce("Error: Object %s is not registered", id.c_str());
|
|---|
| 53 | assert(0);
|
|---|
| 54 |
|
|---|
| 55 | return NULL;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | void Factory::Delete(std::string id)
|
|---|
| 59 | {
|
|---|
| 60 | std::map<std::string, Object*>::iterator iter = object_map.find(id);
|
|---|
| 61 |
|
|---|
| 62 | if (iter != object_map.end()) {
|
|---|
| 63 | delete iter->second;
|
|---|
| 64 | object_map.erase(iter);
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void Factory::PrintAvailableObjects()
|
|---|
| 69 | {
|
|---|
| 70 | MG::GetComm()->PrintStringOnce("Registered objects:");
|
|---|
| 71 | for (std::map<std::string, Object*>::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
|
|---|
| 72 | MG::GetComm()->PrintStringOnce("%s", iter->second->Name().c_str());
|
|---|
| 73 | }
|
|---|