mirror of
https://git.lynn.is/Gwen/argparser.git
synced 2024-04-29 14:43:46 +02:00
40 lines
917 B
C++
40 lines
917 B
C++
#ifndef ARGPARSER_OPTION_H
|
|
#define ARGPARSER_OPTION_H
|
|
|
|
#include "parse-result.h"
|
|
#include <any>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace argparser {
|
|
|
|
class option {
|
|
public:
|
|
explicit option(std::string name) : name(std::move(name)) {}
|
|
virtual ~option() = default;
|
|
|
|
void parse(std::optional<std::string> arg, std::any &val) {
|
|
return this->do_parse(std::move(arg), val);
|
|
}
|
|
|
|
[[nodiscard]] std::string get_name() {
|
|
return name;
|
|
}
|
|
|
|
[[nodiscard]] virtual bool consumes_value() const = 0;
|
|
|
|
virtual void validate(const parse_result &res) const = 0;
|
|
|
|
protected:
|
|
const std::string name;
|
|
|
|
private:
|
|
virtual void do_parse(std::optional<std::string> arg, std::any &val) = 0;
|
|
};
|
|
|
|
using option_handle = std::shared_ptr<option>;
|
|
}// namespace argparser
|
|
|
|
#endif//ARGPARSER_OPTION_H
|