- Fixed some bugs in command processing, added the configure-cpu-policy command

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@748 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-07-10 22:28:51 +00:00
parent 1a6805afc4
commit 6150af3d30
8 changed files with 196 additions and 77 deletions

View file

@ -72,8 +72,9 @@ string_to_int(const ustring& str, int& num)
return true;
}
int
string_to_int(const ustring& str) throw(domain_error)
template <typename T>
T
string_to(const ustring& str) throw(domain_error)
{
if(tokenize(str).size() != 1)
throw domain_error("too few or too many tokens");
@ -82,17 +83,24 @@ string_to_int(const ustring& str) throw(domain_error)
iss.exceptions(ios_base::failbit | ios_base::badbit);
int value;
T value;
try
{
iss >> value;
}
catch(ios_base::failure& e)
catch(ios_base::failure e)
{
throw domain_error(e.what());
}
// disable exceptions, otherwise peek() will throw them!
// how useless!!!
iss.exceptions(ios_base::goodbit);
if(iss.peek() != istringstream::traits_type::eof())
throw domain_error("incorrect number format");
return value;
}
@ -187,4 +195,7 @@ tokenize(const ustring& str)
return tokens;
}
template int string_to<int>(const Glib::ustring&);
template float string_to<float>(const Glib::ustring&);
}

View file

@ -45,8 +45,8 @@ namespace sgpem
*/
bool SG_DLLEXPORT string_to_int(const Glib::ustring&, int&);
int SG_DLLEXPORT string_to_int(const Glib::ustring&) throw(std::domain_error);
template <typename T>
T SG_DLLEXPORT string_to(const Glib::ustring&) throw(std::domain_error);
/**\brief This function converts an integer value into a string.