xref: /openbmc/witherspoon-pfault-analysis/argument.hpp (revision f0f02b9ae21ece3d691c1bbea348b468787ed2ff)
17cde0082SMatt Spinler #pragma once
27cde0082SMatt Spinler 
37cde0082SMatt Spinler #include <getopt.h>
4*f0f02b9aSMatt Spinler 
57cde0082SMatt Spinler #include <map>
67cde0082SMatt Spinler #include <string>
77cde0082SMatt Spinler 
87cde0082SMatt Spinler namespace witherspoon
97cde0082SMatt Spinler {
107cde0082SMatt Spinler namespace power
117cde0082SMatt Spinler {
127cde0082SMatt Spinler 
137cde0082SMatt Spinler /** @brief Class - Encapsulates parsing command line options and
147cde0082SMatt Spinler  *                 populating arguments
157cde0082SMatt Spinler  */
167cde0082SMatt Spinler class ArgumentParser
177cde0082SMatt Spinler {
187cde0082SMatt Spinler   public:
197cde0082SMatt Spinler     ArgumentParser() = delete;
207cde0082SMatt Spinler     ~ArgumentParser() = default;
217cde0082SMatt Spinler     ArgumentParser(const ArgumentParser&) = delete;
227cde0082SMatt Spinler     ArgumentParser& operator=(const ArgumentParser&) = delete;
237cde0082SMatt Spinler     ArgumentParser(ArgumentParser&&) = default;
247cde0082SMatt Spinler     ArgumentParser& operator=(ArgumentParser&&) = default;
257cde0082SMatt Spinler 
26cab48342SGunnar Mills     /** @brief Constructs Argument object
277cde0082SMatt Spinler      *
287cde0082SMatt Spinler      *  @param[in] argc - the main function's argc passed as is
297cde0082SMatt Spinler      *  @param[in] argv - the main function's argv passed as is
307cde0082SMatt Spinler      *  @return Object constructed
317cde0082SMatt Spinler      */
327cde0082SMatt Spinler     ArgumentParser(int argc, char** argv);
337cde0082SMatt Spinler 
347cde0082SMatt Spinler     /** @brief Given an option, returns its argument(optarg)
357cde0082SMatt Spinler      *
367cde0082SMatt Spinler      *  @param[in] opt - command line option string
377cde0082SMatt Spinler      *
387cde0082SMatt Spinler      *  @return argument which is a standard optarg
397cde0082SMatt Spinler      */
407cde0082SMatt Spinler     const std::string& operator[](const std::string& opt);
417cde0082SMatt Spinler 
427cde0082SMatt Spinler     /** @brief Displays usage
437cde0082SMatt Spinler      *
447cde0082SMatt Spinler      *  @param[in] argv - the main function's argv passed as is
457cde0082SMatt Spinler      */
467cde0082SMatt Spinler     static void usage(char** argv);
477cde0082SMatt Spinler 
487cde0082SMatt Spinler     /** @brief Set to 'true' when an option is passed */
497cde0082SMatt Spinler     static const std::string trueString;
507cde0082SMatt Spinler 
517cde0082SMatt Spinler     /** @brief Set to '' when an option is not passed */
527cde0082SMatt Spinler     static const std::string emptyString;
537cde0082SMatt Spinler 
547cde0082SMatt Spinler   private:
557cde0082SMatt Spinler     /** @brief Option to argument mapping */
567cde0082SMatt Spinler     std::map<const std::string, std::string> arguments;
577cde0082SMatt Spinler 
587cde0082SMatt Spinler     /** @brief Array of struct options as needed by getopt_long */
597cde0082SMatt Spinler     static const option options[];
607cde0082SMatt Spinler 
617cde0082SMatt Spinler     /** @brief optstring as needed by getopt_long */
627cde0082SMatt Spinler     static const char* optionStr;
637cde0082SMatt Spinler };
647cde0082SMatt Spinler 
65*f0f02b9aSMatt Spinler } // namespace power
66*f0f02b9aSMatt Spinler } // namespace witherspoon
67