HyperspaceExplorer 0.7.1
FunctionFactory.h
00001 /*
00002 Hyperspace Explorer - visualizing higher-dimensional geometry
00003 Copyright (C) 2010  Lene Preuss <lene.preuss@gmail.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 along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 */
00020 
00021 #ifndef FUNCTIONFACTORY_H
00022 #define FUNCTIONFACTORY_H
00023 
00024 #include "SingletonHolder.h"
00025 #include "Displayable.h"
00026 
00027 #include <map>
00028 
00029 class Displayable;
00030 
00032 
00059 class FunctionFactory {
00060 
00061   public:
00062 
00064     typedef Displayable *(*CreateFunctionCallback)();
00065 
00067     struct BadFunctionException: public std::runtime_error {
00069       BadFunctionException(const std::string &what):
00070         std::runtime_error("\""+what+"\" is not the name of a registered Function") { }
00071     };
00072 
00073   private:
00074 
00076     typedef std::map<std::string, CreateFunctionCallback> CallbackMap;
00077 
00078   public:
00079 
00081     bool registerFunction(CreateFunctionCallback creator,
00082                           const std::string &parent_category);
00083 
00085     bool unregisterFunction(const std::string &name);
00086 
00088     Displayable *createFunction(const std::string &name);
00089 
00091     std::vector<std::string> listFunctions();
00092 
00093   private:
00094 
00096     FunctionFactory(): callbacks() { }
00098     FunctionFactory(const FunctionFactory &);
00100     FunctionFactory &operator=(const FunctionFactory &);
00102     ~FunctionFactory();
00103 
00104     CallbackMap callbacks;  
00105 
00106   friend class Loki::CreateUsingNew<FunctionFactory>;
00107 
00108 };
00109 
00110 typedef Loki::SingletonHolder<FunctionFactory> TheFunctionFactory;
00111 
00112 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:14 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo