WarpX
QedTablesArgParser.H
Go to the documentation of this file.
1 #ifndef QED_TABLES_ARG_PARSER_
2 #define QED_TABLES_ARG_PARSER_
3 
4 #include <optional>
5 #include <string>
6 #include <tuple>
7 #include <unordered_map>
8 #include <utility>
9 #include <variant>
10 #include <vector>
11 
12 namespace ArgParser
13 {
14  /* Possible types of parameters of command line arguments (no argument, int, double, or std::string) */
15  enum class ArgType { NoArg, Integer, Double, String };
16 
17  /* This type represents the type of a command line argument: if it exists it is either an int, a double, or a std::string */
18  using ArgVal = std::optional<std::variant<int, double, std::string>>;
19 
20  /* The type of a possible command line argument */
21  using Key = std::tuple<std::string, ArgType, std::string>;
22 
23  /* The type of the map of the parsed command line arguments */
24  using ParsedArgs = std::unordered_map<std::string, ArgVal>;
25 
33  template <typename T>
34  T GetVal(const ArgVal& arg_val)
35  {
36  return std::get<T>(*arg_val);
37  }
38 
47  ParsedArgs ParseArgs (const std::vector<Key>& keys, const int argc, char const* const* argv);
48 
54  void PrintHelp (const std::vector<Key>& cmd_list);
55 };
56 
57 
58 #endif //QED_TABLES_ARG_PARSER_
Definition: QedTablesArgParser.H:13
T GetVal(const ArgVal &arg_val)
Gets the value out of an ArgVal (std::optional<std::variant<int, double, std::string>>) object.
Definition: QedTablesArgParser.H:34
void PrintHelp(const std::vector< Key > &cmd_list)
Prints the command line options.
Definition: QedTablesArgParser.cpp:86
std::unordered_map< std::string, ArgVal > ParsedArgs
Definition: QedTablesArgParser.H:24
std::optional< std::variant< int, double, std::string > > ArgVal
Definition: QedTablesArgParser.H:18
std::tuple< std::string, ArgType, std::string > Key
Definition: QedTablesArgParser.H:21
ParsedArgs ParseArgs(const std::vector< Key > &keys, const int argc, char const *const *argv)
Function to parse the command line arguments.
Definition: QedTablesArgParser.cpp:62
ArgType
Definition: QedTablesArgParser.H:15