#ifndef RADIX_RADIXCOMMAND_COMMANDLINE_HH_ #define RADIX_RADIXCOMMAND_COMMANDLINE_HH_ #include #include #include #include #include #include #include "radixcore/visibility.hh" namespace radix { class RADIX_PUBLIC CommandLine { public: CommandLine(int argc, char **argv); /** * @brief addOption Adds official option to this commandline * @param name key * @param description description of option * @param required whether it is required or not */ void addOption(const std::string &name, const std::string &description, bool required = false); // dumps all options to \code out void printParsedLine(std::ostream &out) const; // dumps the optional and required options to \code out void help(std::ostream &out) const; // does an option exist in this commandline bool exists(const std::string &name) const; // does an option exist in this commandline bool existsNotEmpty(const std::string &name) const; const std::vector &arguments() const; void setArguments(const std::vector &args); std::string executable() const; void setExecutable(const std::string &executable); void declareArgument(const std::string &id, const std::string &description = std::string()); /** * @brief get retrieve option value as type \code return_type * @param name key of command line option * @return \code return_type */ template return_type get(const std::string &name) const; /** * @brief get retrieve option value as type \code return_type * @param name key of command line option * @param defaultValue default return value in the event name was not provided * @return \code return_type */ template return_type get(const std::string &name, return_type defaultValue) const; /** * @brief arg retrieve argument as type \code return_type * @param i int index of argument [0,N) * @return \code return_type */ template return_type arg(size_t i) const; /** * @brief validate Checks for existince of required options * @param errors list of errors * @return success/failure */ bool validate(std::vector &errors) const; /** * @brief validate Checks for existince of required options * @param std::ostream& stream for errors * @return success/failure */ bool validate(std::ostream &out) const; private: int mArgc; char **mArgv; std::string mExecutable; std::vector mArgs; std::vector> mDeclArgs; std::unordered_map> mData; }; // class CommandLine // // Specialized get/arg method declarations template <> std::string RADIX_PUBLIC CommandLine::get(const std::string &name) const; template <> std::string RADIX_PUBLIC CommandLine::get(const std::string &name, std::string defaultValue) const; template <> std::string RADIX_PUBLIC CommandLine::arg(size_t i) const; } // namespace radix #include "radixcommand/commandline.i.hh" #endif /** RADIX_RADIXCOMMAND_COMMANDLINE_HH_ */