Argx 1.0.0-build
Simple argument parser made in C++
 
Loading...
Searching...
No Matches
Argx.hpp
Go to the documentation of this file.
1/* inc/argx.hpp
2 * Owned and created by: pcannon09
3 */
4
5#pragma once
6
7#include "../inc/macros.hpp"
8
9#if __cplusplus >= 201103L
10#include <string>
11#include <vector>
12
13#include "../inc/types.hpp"
14
15namespace argx
16{
17 class Argx
18 {
19 private:
20 std::string id;
21
22 static std::vector<ARGXOptions> options;
23 static std::vector<std::string> *mainArgs;
24
25 static unsigned int mainArgc;
26
27 public:
28 /**
29 * @brief Create Argx with the specific `id`, `argc` and `argv`
30 * @param id Set the ID of the Argx
31 * @param argc Set the `argc` of the `main()` function
32 * @param argv Set the `argv` of the `main()` function
33 */
34 Argx(const std::string &id, int argc, char *argv[]);
35 Argx();
36 ~Argx();
37
38 /**
39 * @brief Add param options
40 * @param option Add the option to the main params
41 */
42 void add(ARGXOptions option) const;
43
44 /**
45 * @brief Get the param from `id`
46 * @param id The ID to get
47 * @return ARGXParam Returnted parameter to get
48 */
49 ARGXParam getParam(const std::string& id);
50
51 /**
52 * @brief Create documentation for the parameters with the specific style, title and main information
53 * @param style Set the style using ARGXStyle
54 * @param title Title for docs
55 * @param Main information
56 * @return std::string Documentation as a string
57 */
58 std::string createDocs(ARGXStyle style, const std::string &title, const std::string &mainInfo);
59
60 /**
61 * @brief Find parameter index
62 */
63 int findParam(const std::string& id);
64
65 /**
66 * @brief Get the main options from the `main()` function as argc
67 * @return int Number of params including the executable param
68 */
69 int getArgc() const;
70
71 /**
72 * @brief Get if param exists in the param options
73 * @param id ID to get
74 * @return bool
75 */
76 bool paramExists(const std::string &id);
77
78 /**
79 * @brief Compare if `options` contains the required `id`, if the ID does not exist, return false
80 * @param options Return ARGXOptions vector
81 * @param id ID to find
82 * @return bool
83 */
84 bool compareArgs(std::vector<ARGXOptions> options, std::vector<std::string> argv);
85
86 /**
87 * @brief Get the sub-param from `id`
88 * @param param Original param
89 * @param id The ID to get
90 * @return bool
91 */
92 bool getSubParam(const argx::ARGXParam &param, const std::string &id);
93
94 /**
95 * @brief Get main arguments from `main()` function `argv`
96 * @return std::vector<std::string> Vector of strings for main arguments from `argv`
97 */
98 std::vector<std::string> getMainArgs() const;
99
100 /**
101 * @brief Get main set options as ARGXOptions
102 * @return std::vector<ARGXOptions> Options to return
103 */
104 std::vector<ARGXOptions> getOptions() const;
105
106 /**
107 * @brief Get Argx ID
108 * @return std::string Argx ID
109 */
110 std::string getID() const;
111 };
112}
113
114#else
115# error "Must compile with C++11 support or newer"
116# pragma message("Current standard is " ARGX_TOSTRING(__cplusplus))
117#endif
Argx(const std::string &id, int argc, char *argv[])
Create Argx with the specific id, argc and argv
Definition Argx.cpp:23
ARGXParam getParam(const std::string &id)
Get the param from id
Definition Argx.cpp:103
static unsigned int mainArgc
Definition Argx.hpp:25
std::vector< ARGXOptions > getOptions() const
Get main set options as ARGXOptions.
Definition Argx.cpp:323
static std::vector< std::string > * mainArgs
Definition Argx.hpp:23
std::vector< std::string > getMainArgs() const
Get main arguments from main() function argv
Definition Argx.cpp:317
std::string getID() const
Get Argx ID.
Definition Argx.cpp:326
int getArgc() const
Get the main options from the main() function as argc.
Definition Argx.cpp:320
bool paramExists(const std::string &id)
Get if param exists in the param options.
Definition Argx.cpp:94
int findParam(const std::string &id)
Find parameter index.
Definition Argx.cpp:48
std::string createDocs(ARGXStyle style, const std::string &title, const std::string &mainInfo)
Create documentation for the parameters with the specific style, title and main information.
Definition Argx.cpp:225
void add(ARGXOptions option) const
Add param options.
Definition Argx.cpp:38
static std::vector< ARGXOptions > options
Definition Argx.hpp:22
bool compareArgs(std::vector< ARGXOptions > options, std::vector< std::string > argv)
Compare if options contains the required id, if the ID does not exist, return false.
Definition Argx.cpp:293
bool getSubParam(const argx::ARGXParam &param, const std::string &id)
Get the sub-param from id
Definition Argx.cpp:222
std::string id
Definition Argx.hpp:20
Definition Argx.hpp:16
ARGXStyle
Definition types.hpp:10