Matt Spinler | 7cde008 | 2017-07-24 13:48:44 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <getopt.h> |
| 4 | #include <map> |
| 5 | #include <string> |
| 6 | |
| 7 | namespace witherspoon |
| 8 | { |
| 9 | namespace power |
| 10 | { |
| 11 | |
| 12 | /** @brief Class - Encapsulates parsing command line options and |
| 13 | * populating arguments |
| 14 | */ |
| 15 | class ArgumentParser |
| 16 | { |
| 17 | public: |
| 18 | ArgumentParser() = delete; |
| 19 | ~ArgumentParser() = default; |
| 20 | ArgumentParser(const ArgumentParser&) = delete; |
| 21 | ArgumentParser& operator=(const ArgumentParser&) = delete; |
| 22 | ArgumentParser(ArgumentParser&&) = default; |
| 23 | ArgumentParser& operator=(ArgumentParser&&) = default; |
| 24 | |
Gunnar Mills | cab4834 | 2018-06-13 15:57:13 -0500 | [diff] [blame^] | 25 | /** @brief Constructs Argument object |
Matt Spinler | 7cde008 | 2017-07-24 13:48:44 -0500 | [diff] [blame] | 26 | * |
| 27 | * @param[in] argc - the main function's argc passed as is |
| 28 | * @param[in] argv - the main function's argv passed as is |
| 29 | * @return Object constructed |
| 30 | */ |
| 31 | ArgumentParser(int argc, char** argv); |
| 32 | |
| 33 | /** @brief Given an option, returns its argument(optarg) |
| 34 | * |
| 35 | * @param[in] opt - command line option string |
| 36 | * |
| 37 | * @return argument which is a standard optarg |
| 38 | */ |
| 39 | const std::string& operator[](const std::string& opt); |
| 40 | |
| 41 | /** @brief Displays usage |
| 42 | * |
| 43 | * @param[in] argv - the main function's argv passed as is |
| 44 | */ |
| 45 | static void usage(char** argv); |
| 46 | |
| 47 | /** @brief Set to 'true' when an option is passed */ |
| 48 | static const std::string trueString; |
| 49 | |
| 50 | /** @brief Set to '' when an option is not passed */ |
| 51 | static const std::string emptyString; |
| 52 | |
| 53 | private: |
| 54 | /** @brief Option to argument mapping */ |
| 55 | std::map<const std::string, std::string> arguments; |
| 56 | |
| 57 | /** @brief Array of struct options as needed by getopt_long */ |
| 58 | static const option options[]; |
| 59 | |
| 60 | /** @brief optstring as needed by getopt_long */ |
| 61 | static const char* optionStr; |
| 62 | }; |
| 63 | |
| 64 | } |
| 65 | } |