MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
cmdline.hpp
1#ifndef MSTL_CORE_SYSTEM_CMDLINE_HPP__
2#define MSTL_CORE_SYSTEM_CMDLINE_HPP__
3#include "../container/unordered_map.hpp"
4#include "../container/vector.hpp"
5#include "../string/string.hpp"
7
8MSTL_ERROR_BUILD_FINAL_CLASS(cmdline_exception, system_exception, "CmdLine Operation Failed.")
9
10
11class MSTL_API cmdline {
12public:
13 struct option {
14 string long_name;
15 char short_name = 0;
16 string description;
17 bool requires_value = false;
18 bool allow_multiple = false;
19 string default_value;
20
21 _MSTL vector<string> values;
22
23 option() = default;
24 option(string lname, char sname, string desc,
25 bool req_val, bool allow_multi, string def_val);
26 };
27
28 void add_option(const string& long_name, char short_name,
29 const string& description, bool requires_value = false,
30 bool allow_multiple = false, const string& default_value = "");
31
32 void parse_os_args();
33 void parse(int argc, char* argv[]);
34 void parse(const _MSTL vector<string>& args);
35
36 string get(const string& long_name, size_t index = 0) const;
37 bool has(const string& long_name) const;
38 size_t count(const string& long_name) const;
39
40 const _MSTL vector<string>& positional_args() const { return positional_; }
41 string program_name() const { return program_name_; }
42
43 void print_help() const;
44
45 static _MSTL vector<string> get_os_argv();
46
47private:
48 string program_name_;
49 _MSTL vector<option> options_;
50 _MSTL unordered_map<string, option*> options_long_;
51 _MSTL unordered_map<char, option*> options_short_;
52 _MSTL vector<string> positional_;
53
54 option* find_option_long(const string& name);
55 option* find_option_short(char name);
56
57 void parse_long_option(const string& arg, const _MSTL vector<string>& args, size_t& i);
58 void parse_short_options(const string& arg, const _MSTL vector<string>& args, size_t& i);
59};
60
62#endif // MSTL_CORE_SYSTEM_CMDLINE_HPP__
MSTL_ALWAYS_INLINE enable_if_t< is_void_v< T >, future_result_t< T > > get(future< T > &f)
通用future结果获取函数
constexpr iter_difference_t< Iterator > count(Iterator first, Iterator last, const T &value)
统计范围内等于指定值的元素数量
#define MSTL_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO)
构建最终异常类宏
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
系统访问异常