HyperspaceExplorer 0.7.1
ParameterMap.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 PARAMETERMAP_H
00022 #define PARAMETERMAP_H
00023 
00024 #include <iostream>
00025 #include <map>
00026 #include <sstream>
00027 
00028 #include "FunctionParameterFactory.h"
00029 #include "Log.h"
00030 
00032 
00036 class ParameterMap : public std::map< std::string, FunctionParameter::parameter_ptr_type > {
00037 
00039   typedef std::map< std::string, FunctionParameter::parameter_ptr_type > map_type;
00040 
00041 public:
00042 
00044     class NonexistentParameterAccessed: public std::invalid_argument {
00045     public:
00047 
00050       NonexistentParameterAccessed(const std::string &which, const ParameterMap &map):
00051         std::invalid_argument("Tried to access parameter \""+which+"\" in ParameterMap "+map.toString()) { }
00052     };
00053 
00054     ParameterMap(): ParameterMap::map_type() { }
00055 
00057 
00059     template<typename T> ParameterMap(const std::string &name, const T &value):
00060             ParameterMap::map_type() {
00061         insertByValue(name, value);
00062     }
00063 
00064     ~ParameterMap() { }
00065 
00067 
00069     template <typename T> void insertByValue(const std::string name, const T &value) {
00070       insert(
00071         std::make_pair(
00072           name,
00073           TheFunctionParameterFactory::Instance().createParameterWithValue(name, value)));
00074         }
00075 
00077 
00079     template <typename T> void insertByDefault(const std::string name, const T &defaultValue) {
00080       insert(
00081         std::make_pair(
00082           name,
00083           TheFunctionParameterFactory::Instance().createParameterWithDefault(name, defaultValue)));
00084         }
00085 
00087     FunctionParameter::parameter_ptr_type getParameter(const std::string &name);
00088 
00090     FunctionParameter::value_ptr_type getValue(const std::string &name);
00091 
00093 
00100     template <typename T> void set(const std::string &name, const T &value) {
00101       getParameter(name)->setValue(value.toString());
00102     }
00103 
00105     std::string toString() const;
00106 
00107   private:
00108 
00110     ParameterMap::iterator findOrThrow(const std::string &name);
00111 
00112 };
00113 
00115 template <> void ParameterMap::set(const std::string &name, const double &value);
00117 template <> void ParameterMap::set(const std::string &name, const unsigned &value);
00119 template <> void ParameterMap::set(const std::string &name, const int &value);
00121 template <> void ParameterMap::set(const std::string &name, const std::string &value);
00122 
00123 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

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