#define MSP_CORE_GETOPT_H_
#include <list>
-#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
+#include <msp/strings/lexicalcast.h>
namespace Msp {
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<T>(a);
+ }
+ catch(const lexical_error &e)
+ {
+ throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")");
+ }
}
private:
T &data;
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<typename T::value_type>(a));
+ }
+ catch(const lexical_error &e)
+ {
+ throw usage_error("Invalid argument for --"+lng+" ("+e.what()+")");
+ }
}
private:
T &data;