diff options
| author | Joel Klinghed <the_jk@yahoo.com> | 2017-02-28 21:50:44 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@yahoo.com> | 2017-02-28 21:50:44 +0100 |
| commit | c029d90d1975e124d237605f1edb2be16bd05b5d (patch) | |
| tree | 9df87ffb365354bdb74a969440b32c8304bdbcb7 /src/args.hh | |
Initial commit
Diffstat (limited to 'src/args.hh')
| -rw-r--r-- | src/args.hh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/args.hh b/src/args.hh new file mode 100644 index 0000000..10c56b3 --- /dev/null +++ b/src/args.hh @@ -0,0 +1,60 @@ +// -*- mode: c++; c-basic-offset: 2; -*- + +#ifndef ARGS_HH +#define ARGS_HH + +#include <iostream> +#include <string> +#include <vector> + +class Args { +public: + virtual ~Args() {} + + static Args* create(); + + virtual void add(char short_opt, std::string const& long_opt, + std::string const& argument, std::string const& help) = 0; + void add(char short_opt, std::string const& long_opt, + std::string const& help) { + add(short_opt, long_opt, "", help); + } + void add(std::string const& long_opt, std::string const& help) { + add('\0', long_opt, "", help); + } + void add(std::string const& long_opt, std::string const& argument, + std::string const& help) { + add('\0', long_opt, argument, help); + } + + bool run(int argc, char** argv) { + return run(argc, argv, std::cerr); + } + virtual bool run(int argc, char** argv, std::ostream& out) = 0; + bool run(std::string const& prg, int argc, char** argv) { + return run(prg, argc, argv, std::cerr); + } + virtual bool run( + std::string const& prg, int argc, char** argv, std::ostream& out) = 0; + virtual bool good() const = 0; + + virtual bool is_set(char short_opt) const = 0; + virtual bool is_set(std::string const& long_opt) const = 0; + virtual char const* arg(char short_opt, char const* fallback) const = 0; + virtual char const* arg(std::string const& long_opt, + char const* fallback) const = 0; + + virtual std::vector<std::string> const& arguments() const = 0; + + void print_help() const { + print_help(std::cout); + } + virtual void print_help(std::ostream& out) const = 0; + virtual void print_help(std::ostream& out, size_t width) const = 0; + +protected: + Args() {} + Args(Args const&) = delete; +}; + +#endif // ARGS_HH |
