00001 /*************************************************************************** 00002 * Copyright (C) 2007 by Ilya A. Volynets-Evenbakh * 00003 * ilya@total-knowledge.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 #include <serverconfig/serverconfig.h> 00022 #include <iostream> 00023 00024 namespace container { 00025 namespace serverconfig { 00026 00034 Context* ContextRegistry::getContext(const ConfigNode& node, 00035 Context* parent) 00036 { 00037 registry_t::iterator it=m_registry.find(node.getType()); 00038 if(it==m_registry.end()) 00039 return 0; 00040 return it->second.create(node, parent); 00041 } 00042 00046 void ContextRegistry::registerContext(const std::string& type, ContextRegistry::createcontext_f creator, int flags) 00047 { 00048 ContextInfo cinfo(flags, creator); 00049 m_registry[type]=cinfo; 00050 } 00051 00052 Context* ContextRegistry::ContextInfo::create(const ConfigNode& node, 00053 Context* parent) 00054 { 00055 if(m_flags&PARAM_SINGLE_OF_TYPE && m_type_done) { 00056 std::cerr<<"Error while registering context "<<node.getType() 00057 <<" (name="<<node.getName() 00058 <<"): another one of same type already exists"<<std::endl; 00059 return 0; 00060 } 00061 if(m_flags&PARAM_SINGLE_OF_NAME && m_names.find(node.getName())!=m_names.end()) { 00062 std::cerr<<"Error while registering context "<<node.getType() 00063 <<" (name="<<node.getName() 00064 <<"): another one with same name already exists"<<std::endl; 00065 return 0; 00066 } 00067 m_type_done = true; 00068 m_names.insert(node.getName()); 00069 return m_f(node, parent); 00070 } 00071 00072 } 00073 }