CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

paramregistry.h

Go to the documentation of this file.
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 #ifndef _SERVERCONFIG_PARAMREGISTRY_H_
00022 #define _SERVERCONFIG_PARAMREGISTRY_H_
00023 
00024 #include "context.h"
00025 
00026 namespace container {
00027 namespace serverconfig {
00028 
00035 template <class T>
00036     class ParamRegistry
00037 {
00038 public:
00039     typedef bool (T::*setter_f)(const ConfigNode& val);
00040     typedef std::map<std::string, setter_f> settermap_t;
00041     typedef std::map<std::string, Context::UnsetParam> flagmap_t;
00042 public:
00043     void registerParam(const std::string& type, setter_f setter, int flags)
00044     {
00045         m_sregistry[type]=setter;
00046         m_fregistry[type]=Context::UnsetParam(flags);
00047     }
00048     bool setParam(const ConfigNode& val, T* context)
00049     {
00050         if(m_sregistry.find(val.getType())==m_sregistry.end())
00051             return false;
00052         setter_f set=m_sregistry[val.getType()];
00053         return (context->*set)(val);
00054     }
00055     
00056     ParamRegistry(void(*registerParams)(ParamRegistry<T>&))
00057     {
00058         registerParams(*this);
00059     }
00060     void getParamList(Context::unsetparams_t& ret)
00061     {
00065         ret.clear();
00066         ret.insert(m_fregistry.begin(),m_fregistry.end());
00067     }
00068 private:
00069     settermap_t m_sregistry;
00070     flagmap_t m_fregistry;
00071 };
00072 
00073 }
00074 }
00075 #endif //_SERVERCONFIG_PARAMREGISTRY_H_

SourceForge.net Logo