CPPSERV


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

contextregistry.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_CONTEXTREGISTRY_H_
00022 #define _SERVERCONFIG_CONTEXTREGISTRY_H_
00023 
00024 #include "context.h"
00025 #include <set>
00026 
00027 namespace container {
00028 namespace serverconfig {
00029 
00030 class ContextRegistry
00031 {
00032 public:
00033     typedef Context* (* createcontext_f)(const ConfigNode& n, Context* parent);
00034     struct ContextInfo
00035     {
00036     private:
00037         int m_flags;
00038         createcontext_f m_f;
00039         bool m_type_done;
00040         std::set<std::string> m_names;
00041     public:
00042         ContextInfo(int flags, createcontext_f f)
00043             : m_flags(flags)
00044             , m_f(f)
00045             , m_type_done(false)
00046         {}
00047         ContextInfo()
00048             : m_flags(0)
00049             , m_f(0)
00050             , m_type_done(false)
00051         {}
00052         Context* create(const ConfigNode&, Context*);
00053     };
00054 private:
00055     typedef std::map<std::string, ContextInfo> registry_t;
00056     registry_t m_registry;
00057 public:
00058     void registerContext(const std::string& type, createcontext_f creator, int flags);
00059     ContextRegistry(void(*registerContexts)(ContextRegistry&))
00060     {
00061         registerContexts(*this);
00062     }
00063     Context* getContext(const ConfigNode&, Context*);
00064 };
00065 
00066 }
00067 }
00068 #endif //_SERVERCONFIG_CONTEXTREGISTRY_H_

SourceForge.net Logo