ezp
lightweight C++ wrapper for selected distributed solvers for linear systems
Loading...
Searching...
No Matches
parser.hpp
1/*******************************************************************************
2 * Copyright (C) 2025-2026 Theodore Chang
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17
18#ifndef PARSER_HPP
19#define PARSER_HPP
20
21#include <iterator>
22#include <sstream>
23#include <vector>
24
25namespace ezp {
26 namespace detail {
27 struct cli_arg {
28 std::string token;
29 int value;
30 };
31
32 inline auto parse(const std::string& command) {
33 std::istringstream iss(command);
34 auto current = std::istream_iterator<std::string>(iss);
35 const auto end = std::istream_iterator<std::string>();
36
37 std::vector<cli_arg> args;
38
39 while(current != end) {
40 cli_arg arg{*current++, 0};
41 if(!arg.token.starts_with("--")) continue;
42 if(current == end) break;
43 try {
44 arg.value = std::stoi(*current);
45 args.push_back(arg);
46 ++current;
47 }
48 catch(...) {
49 }
50 }
51
52 return args;
53 }
54 } // namespace detail
55} // namespace ezp
56
57#endif
58
Definition parser.hpp:27