#ifndef MSP_CORE_GETOPT_H_
#define MSP_CORE_GETOPT_H_
+#include <list>
#include <sstream>
+#include <stdexcept>
#include <string>
#include <vector>
-#include "except.h"
namespace Msp {
+class usage_error: public std::runtime_error
+{
+private:
+ std::string help_;
+
+public:
+ usage_error(const std::string &w, const std::string &h = std::string()): std::runtime_error(w), help_(h) { }
+ ~usage_error() throw() { }
+
+ const char *help() const throw() { return help_.c_str(); }
+};
+
+
class GetOpt
{
public:
std::istringstream ss(a);
ss>>tmp;
if(ss.fail())
- throw UsageError("Invalid argument for --"+lng);
+ throw usage_error("Invalid argument for --"+lng);
data = tmp;
}
{
public:
ListOption(char s, const std::string &l, T &d, ArgType a): OptBase(s, l, a), data(d)
- { if(arg_type!=REQUIRED_ARG) throw Exception("ListOption with arg_type!=REQUIRED makes no sense"); }
+ { if(arg_type!=REQUIRED_ARG) throw std::invalid_argument("ListOption arg_type!=REQUIRED"); }
virtual void store() { }
std::istringstream ss(a);
ss>>tmp;
if(ss.fail())
- throw UsageError("Invalid argument for --"+lng);
+ throw usage_error("Invalid argument for --"+lng);
data.push_back(tmp);
}
T &data;
};
+ bool help;
std::list<OptBase *> opts;
std::vector<std::string> args;
public:
+ GetOpt();
~GetOpt();
const std::vector<std::string> &get_args() const { return args; }