One Framework 0.1.0
RoboMaster嵌入式框架“一键”解决方案,为你的“创意”服务。
载入中...
搜索中...
未找到
ArgParser.hpp
浏览该文件的文档.
1#ifndef ARGPARSER_HPP
2#define ARGPARSER_HPP
3
4#include <string>
5
6template <size_t I, typename Tuple>
8{
9 static bool parse(Tuple& tup, const std::vector<std::string_view>& opts)
10 {
11 if constexpr (I == std::tuple_size_v<Tuple>)
12 {
13 return true;
14 }
15 else
16 {
17 auto& [name, type] = Prts::PrtsManager::getCommands().back().options[I];
18 using T = std::tuple_element_t<I, Tuple>;
19 for (size_t i = 0; i + 1 < opts.size(); ++i)
20 {
21 if (opts[i] == "--" + std::string(name))
22 {
23 if constexpr (std::is_same_v<T, int>)
24 {
25 std::get<I>(tup) = std::stoi(std::string(opts[i + 1]));
26 }
27 else if constexpr (std::is_same_v<T, double>)
28 {
29 std::get<I>(tup) = std::stod(std::string(opts[i + 1]));
30 }
31 else
32 std::get<I>(tup) = opts[i + 1];
33 return ArgParser<I + 1, Tuple>::parse(tup, opts);
34 }
35 }
36 return false;
37 }
38 }
39};
40
41#endif //ARGPARSER_HPP
定义 ArgParser.hpp:8
static bool parse(Tuple &tup, const std::vector< std::string_view > &opts)
定义 ArgParser.hpp:9