source: src/base/factory.cpp@ 759a6a

Last change on this file since 759a6a was ac6d04, checked in by Julian Iseringhausen <isering@…>, 14 years ago

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 1.7 KB
Line 
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
27using namespace VMG;
28
29Factory::Factory()
30{
31}
32
33Factory::~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
39void Factory::Register(Object* object)
40{
41 Delete(object->Name());
42 object_map.insert(std::make_pair(object->Name(), object));
43}
44
45Object* 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
58void 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
68void Factory::PrintAvailableObjects()
69{
70 MG::GetComm()->PrintString("Registered objects:");
71 for (std::map<std::string, Object*>::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
72 MG::GetComm()->PrintString("%s", iter->second->Name().c_str());
73}
74
75bool Factory::TestObject(std::string id) const
76{
77 return object_map.find(id) != object_map.end();
78}
Note: See TracBrowser for help on using the repository browser.