/** * @file factory.cpp * @author Julian Iseringhausen * @date Tue Apr 5 20:40:05 2011 */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "base/command.hpp" #include "base/discretization.hpp" #include "base/factory.hpp" #include "base/object.hpp" #include "comm/comm.hpp" #include "grid/multigrid.hpp" #include "grid/tempgrid.hpp" #include "level/level_operator.hpp" #include "smoother/smoother.hpp" #include "solver/solver.hpp" #include "mg.hpp" using namespace VMG; Factory::Factory() { } Factory::~Factory() { for (std::map::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter) delete iter->second; } void Factory::Register(Object* object) { Delete(object->Name()); object_map.insert(std::make_pair(object->Name(), object)); } Object* Factory::Get(std::string id) { std::map::iterator iter = object_map.find(id); if (iter != object_map.end()) return iter->second; MG::GetComm()->PrintStringOnce("Error: Object %s is not registered", id.c_str()); assert(0); return NULL; } void Factory::Delete(std::string id) { std::map::iterator iter = object_map.find(id); if (iter != object_map.end()) { delete iter->second; object_map.erase(iter); } } void Factory::PrintAvailableObjects() { MG::GetComm()->PrintString("Registered objects:"); for (std::map::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter) MG::GetComm()->PrintString("%s", iter->second->Name().c_str()); } bool Factory::TestObject(std::string id) const { return object_map.find(id) != object_map.end(); }