23 Argx::Argx(
const std::string &
id,
int argc,
char *argv[])
26 this->
mainArgs =
new std::vector<std::string>(argv, argv + argc);
45 this->
options.emplace_back(option);
51 for (
size_t i = 0; i < this->
options.size(); i++)
56 for (
const std::string &arg : *this->
mainArgs)
58 if (arg == this->
options[i].param || arg == this->
options[i].sparam)
60 return static_cast<int>(i);
67 for (
const auto &opt : this->
options)
70 bool parentExists =
false;
72 for (
const std::string &arg : *this->
mainArgs)
74 if (arg == opt.param || arg == opt.sparam)
84 for (
size_t i = 0; i < opt.subParams.size(); i++)
86 if (opt.subParams[i].id ==
id)
return static_cast<int>(i);
96 if (this->
findParam(
id) >= 0)
return true;;
110 for (
const auto &opt : this->
options)
115 int mainOptionPos = -1;
117 for (
size_t i = 0; i < this->
mainArgs->size(); ++i)
119 if ((*this->
mainArgs)[i] == opt.param || (*this->mainArgs)[i] == opt.sparam)
129 if (opt.hasSubParams)
132 for (
const auto &sub : opt.subParams)
134 bool subMatched =
false;
137 for (
size_t i = mainOptionPos + 1; i < this->
mainArgs->size(); ++i)
139 if ((*this->
mainArgs)[i] == sub.param || (*this->mainArgs)[i] == sub.sparam)
156 for (
const auto &opt : this->options)
159 size_t parentPos = -1;
161 for (
size_t i = 0; i < this->
mainArgs->size(); ++i)
163 if ((*this->
mainArgs)[i] == opt.param || (*this->mainArgs)[i] == opt.sparam)
170 if (parentPos > -1 && opt.hasSubParams)
173 for (
const auto &sub : opt.subParams)
177 for (
size_t i = parentPos + 1; i < this->
mainArgs->size(); ++i)
179 if ((*this->
mainArgs)[i] == sub.param || (*this->mainArgs)[i] == sub.sparam)
186 if (!result.
exists && parentPos + 1 < this->mainArgs->size())
188 std::string nextArg = (*this->
mainArgs)[parentPos + 1];
190 if (nextArg == sub.param || nextArg == sub.sparam) result.
exists =
true;
194 if (result.
exists && sub.hasSubParams)
196 for (
const auto &subsub : sub.subParams)
198 bool subsubMatched =
false;
200 for (
size_t i = 0; i < this->
mainArgs->size(); ++i)
202 if ((*this->
mainArgs)[i] == subsub.param || (*this->mainArgs)[i] == subsub.sparam)
204 subsubMatched =
true;
209 result.
subExists.push_back(subsubMatched);
227 std::string contentStr;
231 for (
const auto &x : this->
options)
234 contentStr +=
"ID: " + x.id +
"\n";
235 contentStr +=
"[ " + x.sparam +
" | " + x.param;
237 if (x.hasSubParams && !x.subParams.empty())
241 for (
size_t i = 0; i < x.subParams.size(); ++i)
243 const auto &sub = x.subParams[i];
245 contentStr += sub.param;
247 if (i < x.subParams.size() - 1) contentStr +=
" | ";
248 else if (i <= x.subParams.size()) contentStr +=
' ';
251 contentStr +=
"] ] ";
254 else contentStr +=
" ] ";
256 contentStr += x.info +
"\n";
259 if (x.hasSubParams && !x.subParams.empty())
261 for (
const auto &sub : x.subParams)
264 std::wstring wideSpaces(x.param.size(), L
'\u3000');
265 std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
266 std::string spacing = converter.to_bytes(wideSpaces);
268 contentStr += spacing +
" [ " + sub.sparam +
" | " + sub.param +
" ] " + sub.info +
"\n";
276 for (
const auto &x : this->
options)
278 contentStr += x.sparam +
", " + x.param +
" - " + x.info +
"\n";
280 if (x.hasSubParams && !x.subParams.empty())
282 for (
const auto &sub : x.subParams)
284 contentStr +=
" " + sub.sparam +
", " + sub.param +
" - " + sub.info +
"\n";
290 return title +
"\n" + mainInfo +
"\n" + contentStr;
296 for (
size_t i = 1 ; i < argv.size() ; ++i)
298 const std::string &arg = argv[i];
301 for (
const auto &option :
options)
303 if (option.sparam == arg || option.param == arg)
ARGXParam getParam(const std::string &id)
Get the param from id
static unsigned int mainArgc
std::vector< ARGXOptions > getOptions() const
Get main set options as ARGXOptions.
static std::vector< std::string > * mainArgs
std::vector< std::string > getMainArgs() const
Get main arguments from main() function argv
std::string getID() const
Get Argx ID.
int getArgc() const
Get the main options from the main() function as argc.
bool paramExists(const std::string &id)
Get if param exists in the param options.
int findParam(const std::string &id)
Find parameter index.
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.
void add(ARGXOptions option) const
Add param options.
static std::vector< ARGXOptions > options
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.
bool getSubParam(const argx::ARGXParam ¶m, const std::string &id)
Get the sub-param from id
std::vector< bool > subExists