1 #ifndef __ARGUMENT_H
2 #define __ARGUMENT_H
3 #include <getopt.h>
4 
5 #include <map>
6 #include <string>
7 
8 namespace phosphor
9 {
10 namespace led
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 
25     /** @brief Constructs Argument object
26      *
27      *  @param argc - the main function's argc passed as is
28      *  @param argv - the main function's argv passed as is
29      *  @return Object constructed
30      */
31     ArgumentParser(int argc, char** argv);
32 
33     /** @brief Given a option, returns its argument(optarg) */
34     const std::string& operator[](const std::string& opt);
35 
36     /** @brief Displays usage */
37     static void usage(char** argv);
38 
39     /** @brief Set to 'true' when an option is passed */
40     static const std::string true_string;
41 
42     /** @brief Set to '' when an option is not passed */
43     static const std::string empty_string;
44 
45   private:
46     /** @brief Option to argument mapping */
47     std::map<const std::string, std::string> arguments;
48 
49     /** @brief Array of struct options as needed by getopt_long */
50     static const option options[];
51 
52     /** @brief optstring as needed by getopt_long */
53     static const char* optionstr;
54 };
55 
56 } // namespace led
57 } // namespace phosphor
58 
59 #endif
60