Commit 6fa5b4f3 authored by aligungr's avatar aligungr

Options parser improvement

parent 70485c2c
...@@ -48,8 +48,9 @@ opt::OptionsResult::OptionsResult(const std::vector<std::string> &args, const op ...@@ -48,8 +48,9 @@ opt::OptionsResult::OptionsResult(const std::vector<std::string> &args, const op
{ {
} }
opt::OptionsResult::OptionsResult(int argc, char **argv, const opt::OptionsDescription &desc, bool freeArgv) opt::OptionsResult::OptionsResult(int argc, char **argv, const opt::OptionsDescription &desc, bool freeArgv,
: m_description{desc} std::unique_ptr<IOptionsHandler> handler)
: m_handler{std::move(handler)}, m_description{desc}
{ {
argc--; argc--;
argv++; argv++;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <cstring> #include <cstring>
#include <istream> #include <istream>
#include <memory>
#include <optional> #include <optional>
#include <ostream> #include <ostream>
#include <stdexcept> #include <stdexcept>
...@@ -80,15 +81,24 @@ struct OptionsDescription ...@@ -80,15 +81,24 @@ struct OptionsDescription
} }
}; };
class IOptionsHandler
{
virtual std::istream istream() = 0;
virtual std::ostream ostream() = 0;
virtual void status(int code) = 0;
};
class OptionsResult class OptionsResult
{ {
private: private:
std::vector<std::string> m_positionalParams{}; std::vector<std::string> m_positionalParams{};
std::unordered_map<std::string, std::string> m_options{}; std::unordered_map<std::string, std::string> m_options{};
std::unique_ptr<IOptionsHandler> m_handler;
OptionsDescription m_description; OptionsDescription m_description;
public: public:
OptionsResult(int argc, char **argv, const OptionsDescription &desc, bool freeArgv = false); OptionsResult(int argc, char **argv, const OptionsDescription &desc, bool freeArgv = false,
std::unique_ptr<IOptionsHandler> handler = nullptr);
OptionsResult(const std::vector<std::string> &args, const OptionsDescription &desc); OptionsResult(const std::vector<std::string> &args, const OptionsDescription &desc);
public: public:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment