Skip to content

Commit

Permalink
docs(gui): Argparser
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelR-T committed May 20, 2024
1 parent 30896f1 commit 163db38
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
zappy_server
zappy_ai
zappy_gui

doc/html
*.o
.cache
compile_commands.json
Expand Down
54 changes: 53 additions & 1 deletion gui/src/ArgParser/ArgParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,44 @@

#include "ArgParserException.hpp"

/**
* @class ArgParser
* @brief A class to parse and handle command-line arguments.
*
* This class provides methods to parse command-line arguments, set default
* values for parameters, check for the presence of parameters, and retrieve
* parameter values with type safety.
*/
class ArgParser {
public:
ArgParser() = default;
~ArgParser() = default;

/**
* @brief Parses command-line arguments.
*
* @param argc The number of command-line arguments.
* @param argv The array of command-line arguments.
*/
void parse(int argc, char *argv[]);

/**
* @brief Checks if a parameter is present.
*
* @param param The name of the parameter to check.
* @return true if the parameter is present, false otherwise.
*/
bool has(const std::string &param) const;

/**
* @brief Sets a default value for a parameter.
*
* @tparam T The type of the parameter value.
* @param param The name of the parameter.
* @param value The default value of the parameter.
* @param mandatory Whether the parameter is mandatory (default is false).
* @return A reference to the ArgParser object.
*/
template <typename T>
ArgParser &setDefault(
const std::string &param,
Expand All @@ -40,6 +70,15 @@ class ArgParser {
return *this;
}

/**
* @brief Retrieves the value of a parameter.
*
* @tparam T The type of the parameter value.
* @param param The name of the parameter.
* @return The value of the parameter.
* @throws ArgParserException if the parameter is not found or if there is a
* type mismatch.
*/
template <typename T>
T get(const std::string &param) const
{
Expand All @@ -63,7 +102,20 @@ class ArgParser {
std::map<std::string, std::string> params_;
std::map<std::string, std::string> types_;
std::set<std::string> mandatoryArgs_;

/**
* @brief Checks if all mandatory arguments are provided.
*
* @param providedArgs The set of provided argument names.
* @throws ArgParserException if a mandatory argument is missing.
*/
void checkMandatoryArgs(const std::set<std::string> &providedArgs) const;

/**
* @brief Validates the type of a parameter value.
*
* @param key The name of the parameter.
* @param value The value of the parameter as a string.
* @return true if the type is valid, false otherwise.
*/
bool isValidType(const std::string &key, const std::string &value) const;
};

0 comments on commit 163db38

Please sign in to comment.