00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <ParameterCenter.hpp>
00021
00022 #include <list>
00023
00024 ReferenceCounting<Parameter> ParameterCenter::getParameter(const char* address)
00025 {
00026 std::string a = address;
00027 typedef std::list<std::string> StringList;
00028 StringList name;
00029
00030 size_t begin = 0;
00031 size_t end = begin;
00032 do {
00033 end = a.find("::", begin);
00034 name.push_back(a.substr(begin,end-begin));
00035 if (end <= a.size()) {
00036 begin = end + 2;
00037 } else {
00038 break;
00039 }
00040 } while (true);
00041
00042 if(name.size()>2) {
00043 fferr(2) << '\n' << __FILE__ << ':' << __LINE__ << ": not implemented\n";
00044 }
00045 StringList::iterator iName = name.begin();
00046 ParameterSet::iterator object = __parametersSet.find((*iName).c_str());
00047 if(object != __parametersSet.end()) {
00048 ++iName;
00049 ReferenceCounting<Parameter> p = (*(*object).second).get((*iName).c_str());
00050 return p;
00051 } else {
00052 std::stringstream errorMsg;
00053 errorMsg << "no option named " << *iName << '\n'
00054 << "availables options are:";
00055 for(object = __parametersSet.begin();
00056 object != __parametersSet.end(); ++object) {
00057 errorMsg << (*object).first << std::ends;
00058 }
00059
00060 throw ErrorHandler(__FILE__,__LINE__,
00061 errorMsg.str(),
00062 ErrorHandler::normal);
00063 return 0;
00064 }
00065 }
00066
00067 void ParameterCenter::get(const char * address, real_t& d)
00068 {
00069 ReferenceCounting<Parameter> p = getParameter(address);
00070 switch ((*p).type()) {
00071 case Parameter::Double: {
00072 d = static_cast<real_t&>(dynamic_cast<DoubleParameter&>(*p));
00073 break;
00074 }
00075 default: {
00076 throw ErrorHandler(__FILE__,__LINE__,
00077 "wrong parameter type reading "+stringify(address),
00078 ErrorHandler::normal);
00079 }
00080 }
00081 }
00082
00083 void ParameterCenter::get(const char * address, int& integer)
00084 {
00085 ReferenceCounting<Parameter> p = getParameter(address);
00086 switch ((*p).type()) {
00087 case Parameter::Double: {
00088 integer = static_cast<int&>(dynamic_cast<IntegerParameter&>(*p));
00089 break;
00090 }
00091 default: {
00092 throw ErrorHandler(__FILE__,__LINE__,
00093 "wrong parameter type reading "+stringify(address),
00094 ErrorHandler::normal);
00095 }
00096 }
00097 }
00098
00099 void ParameterCenter::get(const char * address, std::string& aString)
00100 {
00101 ReferenceCounting<Parameter> p = getParameter(address);
00102 switch ((*p).type()) {
00103 case Parameter::String: {
00104 aString = static_cast<std::string&>(dynamic_cast<StringParameter&>(*p));
00105 break;
00106 }
00107 default: {
00108 throw ErrorHandler(__FILE__,__LINE__,
00109 "wrong parameter type reading "+stringify(address),
00110 ErrorHandler::normal);
00111 }
00112 }
00113 }
00114
00115 void ParameterCenter::reset()
00116 {
00117 for(ParameterSet::iterator i = __parametersSet.begin();
00118 i != __parametersSet.end(); ++i) {
00119 (*(*i).second).reset();
00120 }
00121 }
00122
00123 void ParameterCenter::get(IdentifierSet& I)
00124 {
00125 for (ParameterCenter::ParameterSet::iterator i = __parametersSet.begin();
00126 i != __parametersSet.end(); ++i) {
00127 I.insert((*i).first);
00128 (*(*i).second).get(I);
00129 }
00130 }
00131