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