mirror of
https://git.lynn.is/Gwen/argparser.git
synced 2024-04-29 13:53:44 +02:00
62 lines
1.7 KiB
C++
62 lines
1.7 KiB
C++
#ifndef ARGPARSER_PARSE_RESULT_H
|
|
#define ARGPARSER_PARSE_RESULT_H
|
|
|
|
#include <any>
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
#include "defs.h"
|
|
|
|
namespace argparser {
|
|
|
|
class parse_result {
|
|
internal::string_map<std::any> opts{};
|
|
internal::string_map<std::any> args{};
|
|
std::vector<std::string> remaining_args{};
|
|
|
|
public:
|
|
void set_opt(const std::string &name, std::any value) {
|
|
opts[name] = std::move(value);
|
|
}
|
|
[[nodiscard]] std::any get_opt(const std::string &name) const {
|
|
if (opts.find(name) != opts.end()) {
|
|
return opts.at(name);
|
|
} else {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
[[nodiscard]] bool has_opt(const std::string &name) const {
|
|
return opts.find(name) != opts.end();
|
|
}
|
|
|
|
void set_arg(const std::string &name, std::any value) {
|
|
args[name] = std::move(value);
|
|
}
|
|
[[nodiscard]] std::any get_arg(const std::string &name) const {
|
|
if (args.find(name) != args.end()) {
|
|
return args.at(name);
|
|
} else {
|
|
return {};
|
|
}
|
|
}
|
|
[[nodiscard]] bool has_arg(const std::string &name) const {
|
|
auto argit = args.find(name);
|
|
if (argit == args.end())
|
|
return false;
|
|
return argit != args.end() && argit->second.has_value();
|
|
}
|
|
|
|
void set_remaining(std::vector<std::string> remaining) {
|
|
remaining_args = std::move(remaining);
|
|
}
|
|
|
|
[[nodiscard]] std::vector<std::string> remaining() const {
|
|
return remaining_args;
|
|
}
|
|
};
|
|
}// namespace argparser
|
|
|
|
#endif//ARGPARSER_PARSE_RESULT_H
|