blob: 71a2c761ac712ad01659c52cf309979fec30b066 [file] [log] [blame]
Matt Spinlerdd945862018-09-07 12:41:05 -05001#pragma once
2
3#include <getopt.h>
4
5#include <map>
6#include <string>
7
8/** @brief Class - Encapsulates parsing command line options and
9 * populating arguments
10 */
11class ArgumentParser
12{
13 public:
14 ArgumentParser() = delete;
15 ~ArgumentParser() = default;
16 ArgumentParser(const ArgumentParser&) = delete;
17 ArgumentParser& operator=(const ArgumentParser&) = delete;
18 ArgumentParser(ArgumentParser&&) = default;
19 ArgumentParser& operator=(ArgumentParser&&) = default;
20
21 /** @brief Constructs Argument object
22 *
23 * @param argc - the main function's argc passed as is
24 * @param argv - the main function's argv passed as is
25 * @return Object constructed
26 */
27 ArgumentParser(int argc, char** argv);
28
29 /** @brief Given a option, returns its argument(optarg) */
30 const std::string& operator[](const std::string& opt);
31
32 /** @brief Displays usage */
33 static void usage(char** argv);
34
35 /** @brief Set to 'true' when an option is passed */
36 static const std::string true_string;
37
38 /** @brief Set to '' when an option is not passed */
39 static const std::string empty_string;
40
41 private:
42 /** @brief Option to argument mapping */
43 std::map<const std::string, std::string> arguments;
44
45 /** @brief Array of struct options as needed by getopt_long */
46 static const option options[];
47
48 /** @brief optstring as needed by getopt_long */
49 static const char* optionstr;
50};