jtag memory interface working
This commit is contained in:
63
tools/argparse.hpp
Normal file
63
tools/argparse.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class ArgParser {
|
||||
public:
|
||||
struct StringOption {
|
||||
std::string name;
|
||||
std::string default_value;
|
||||
std::string help;
|
||||
bool required;
|
||||
};
|
||||
|
||||
struct IntOption {
|
||||
std::string name;
|
||||
int default_value;
|
||||
std::string help;
|
||||
bool required;
|
||||
};
|
||||
|
||||
explicit ArgParser(std::string program_name);
|
||||
|
||||
void addString(const std::string &name,
|
||||
const std::string &default_value,
|
||||
const std::string &help,
|
||||
bool required = false);
|
||||
|
||||
void addInt(const std::string &name,
|
||||
int default_value,
|
||||
const std::string &help,
|
||||
bool required = false);
|
||||
|
||||
bool parse(int argc, char **argv, std::string *error);
|
||||
|
||||
bool has(const std::string &name) const;
|
||||
std::string getString(const std::string &name) const;
|
||||
int getInt(const std::string &name) const;
|
||||
|
||||
std::string helpText() const;
|
||||
|
||||
private:
|
||||
enum class OptionType {
|
||||
kString,
|
||||
kInt
|
||||
};
|
||||
|
||||
struct OptionMeta {
|
||||
OptionType type;
|
||||
std::string help;
|
||||
bool required;
|
||||
};
|
||||
|
||||
std::string program_name_;
|
||||
std::vector<std::string> order_;
|
||||
std::unordered_map<std::string, OptionMeta> meta_;
|
||||
|
||||
std::unordered_map<std::string, std::string> string_values_;
|
||||
std::unordered_map<std::string, int> int_values_;
|
||||
std::unordered_map<std::string, bool> provided_;
|
||||
};
|
||||
Reference in New Issue
Block a user