X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fgetopt.h;h=bfa2ef2092feb82d62a0f9ced8655df48d67941e;hp=d45e888692ea9f96d2947180f19de75f6652eabb;hb=967785734be5c3fc6f75da122c2d93ebbb338271;hpb=c2eeec205dbf17f6ca38fda2671c6aaf2d1c505f diff --git a/source/core/getopt.h b/source/core/getopt.h index d45e888..bfa2ef2 100644 --- a/source/core/getopt.h +++ b/source/core/getopt.h @@ -1,18 +1,11 @@ -/* $Id$ - -This file is part of libmspcore -Copyright © 2006-2009, 2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef MSP_CORE_GETOPT_H_ #define MSP_CORE_GETOPT_H_ #include -#include #include #include #include +#include namespace Msp { @@ -79,13 +72,14 @@ private: virtual void store(const std::string &a) { - T tmp; - std::istringstream ss(a); - ss>>tmp; - if(ss.fail()) - throw usage_error("Invalid argument for --"+lng); - - data = tmp; + try + { + data = lexical_cast(a); + } + catch(const lexical_error &e) + { + throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")"); + } } private: T &data; @@ -102,13 +96,14 @@ private: virtual void store(const std::string &a) { - typename T::value_type tmp; - std::istringstream ss(a); - ss>>tmp; - if(ss.fail()) - throw usage_error("Invalid argument for --"+lng); - - data.push_back(tmp); + try + { + data.push_back(lexical_cast(a)); + } + catch(const lexical_error &e) + { + throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")"); + } } private: T &data;