00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2001, 2002, 2003 Stéphane Del Pino 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: ParameterCenter.hpp,v 1.3 2004/12/31 14:00:47 delpinux Exp $ 00019 00020 #ifndef PARAMETER_CENTER_HPP 00021 #define PARAMETER_CENTER_HPP 00022 00023 #include <StringParameter.hpp> 00024 #include <IntegerParameter.hpp> 00025 #include <DoubleParameter.hpp> 00026 #include <EnumParameter.hpp> 00027 00028 #include <IdentifierSet.hpp> 00029 00030 #include <ParametrizableObject.hpp> 00031 #include <ReferenceCounting.hpp> 00032 00033 #include <ErrorHandler.hpp> 00034 00035 #include <ParameterCenter.hpp> 00036 00037 #include <sstream> 00038 00039 class ParameterCenter 00040 : public StaticBase<ParameterCenter> 00041 { 00042 private: 00043 typedef std::map <const char*, 00044 ReferenceCounting<ParametrizableObject>, 00045 StringEquality> ParameterSet; 00046 ParameterSet __parametersSet; 00047 00048 ReferenceCounting<Parameter> getParameter(const char* address); 00049 00050 public: 00051 00053 void get(IdentifierSet& I); 00054 00055 template <typename __GivenParameter> 00056 void subscribe(__GivenParameter* gp) 00057 { 00058 __parametersSet[__GivenParameter::identifier()] 00059 = dynamic_cast<ParametrizableObject*>(gp); 00060 } 00061 00062 ReferenceCounting<ParametrizableObject> get(const char* parameterName) 00063 { 00064 ParameterSet::iterator i = __parametersSet.find(parameterName); 00065 if (i != __parametersSet.end()) { 00066 return (*i).second; 00067 } else { 00068 std::stringstream errorMsg; 00069 errorMsg << "'" << parameterName << "' not found!\n"; 00070 errorMsg << "List of parameters:\n"; 00071 for (i = __parametersSet.begin(); i != __parametersSet.end(); 00072 ++i) { 00073 errorMsg << '\t' << (*i).first << '\n'; 00074 } 00075 errorMsg << std::ends; 00076 throw ErrorHandler(__FILE__,__LINE__, 00077 errorMsg.str(), 00078 ErrorHandler::normal); 00079 } 00080 return 0; 00081 } 00082 00083 void reset(); 00084 00085 template <typename t> 00086 void set(const char * address, const t& d) 00087 { 00088 ReferenceCounting<Parameter> p = getParameter(address); 00089 (*p).set(d); 00090 } 00091 00092 void get(const char* address, real_t& aDouble); 00093 void get(const char* address, int& anInteger); 00094 void get(const char* address, std::string& aString); 00095 00096 explicit ParameterCenter() 00097 { 00098 ; 00099 } 00100 00101 ~ParameterCenter() 00102 { 00103 ; 00104 } 00105 }; 00106 00107 #endif // PARAMETER_CENTER_HPP
1.5.6