blob: b6681d91c14093f583fb039d3d160c89486d0ce7 [file] [log] [blame]
Matt Spinler7cde0082017-07-24 13:48:44 -05001#pragma once
2
3#include <getopt.h>
Matt Spinlerf0f02b92018-10-25 16:12:43 -05004
Matt Spinler7cde0082017-07-24 13:48:44 -05005#include <map>
6#include <string>
7
8namespace witherspoon
9{
10namespace power
11{
12
13/** @brief Class - Encapsulates parsing command line options and
14 * populating arguments
15 */
16class ArgumentParser
17{
Matt Spinlerf0f02b92018-10-25 16:12:43 -050018 public:
19 ArgumentParser() = delete;
20 ~ArgumentParser() = default;
21 ArgumentParser(const ArgumentParser&) = delete;
22 ArgumentParser& operator=(const ArgumentParser&) = delete;
23 ArgumentParser(ArgumentParser&&) = default;
24 ArgumentParser& operator=(ArgumentParser&&) = default;
Matt Spinler7cde0082017-07-24 13:48:44 -050025
Matt Spinlerf0f02b92018-10-25 16:12:43 -050026 /** @brief Constructs Argument object
27 *
28 * @param[in] argc - the main function's argc passed as is
29 * @param[in] argv - the main function's argv passed as is
30 * @return Object constructed
31 */
32 ArgumentParser(int argc, char** argv);
Matt Spinler7cde0082017-07-24 13:48:44 -050033
Matt Spinlerf0f02b92018-10-25 16:12:43 -050034 /** @brief Given an option, returns its argument(optarg)
35 *
36 * @param[in] opt - command line option string
37 *
38 * @return argument which is a standard optarg
39 */
40 const std::string& operator[](const std::string& opt);
Matt Spinler7cde0082017-07-24 13:48:44 -050041
Matt Spinlerf0f02b92018-10-25 16:12:43 -050042 /** @brief Displays usage
43 *
44 * @param[in] argv - the main function's argv passed as is
45 */
46 static void usage(char** argv);
Matt Spinler7cde0082017-07-24 13:48:44 -050047
Matt Spinlerf0f02b92018-10-25 16:12:43 -050048 /** @brief Set to 'true' when an option is passed */
49 static const std::string trueString;
Matt Spinler7cde0082017-07-24 13:48:44 -050050
Matt Spinlerf0f02b92018-10-25 16:12:43 -050051 /** @brief Set to '' when an option is not passed */
52 static const std::string emptyString;
Matt Spinler7cde0082017-07-24 13:48:44 -050053
Matt Spinlerf0f02b92018-10-25 16:12:43 -050054 private:
55 /** @brief Option to argument mapping */
56 std::map<const std::string, std::string> arguments;
Matt Spinler7cde0082017-07-24 13:48:44 -050057
Matt Spinlerf0f02b92018-10-25 16:12:43 -050058 /** @brief Array of struct options as needed by getopt_long */
59 static const option options[];
Matt Spinler7cde0082017-07-24 13:48:44 -050060
Matt Spinlerf0f02b92018-10-25 16:12:43 -050061 /** @brief optstring as needed by getopt_long */
62 static const char* optionStr;
Matt Spinler7cde0082017-07-24 13:48:44 -050063};
64
Matt Spinlerf0f02b92018-10-25 16:12:43 -050065} // namespace power
66} // namespace witherspoon