X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/8c6fa3fbaccc22127280bf77a48fab5a3ee0716e..46b0747592074017ff0ea4b33d4a7194235886e5:/sgconf/api_action.cpp diff --git a/sgconf/api_action.cpp b/sgconf/api_action.cpp new file mode 100644 index 00000000..d5b1e8e6 --- /dev/null +++ b/sgconf/api_action.cpp @@ -0,0 +1,40 @@ +#include "api_action.h" + +#include "actions.h" +#include "parser_state.h" + +SGCONF::PARSER_STATE SGCONF::API_ACTION::Parse(int argc, char ** argv, void * /*data*/) +{ +PARSER_STATE state(false, argc, argv); +if (!m_argument.empty()) + { + if (argc == 0 || + argv == NULL || + *argv == NULL) + throw ERROR("Missing argument."); + m_argument = *argv; + --state.argc; + ++state.argv; + } +state = m_suboptions.Parse(state.argc, state.argv, &m_params); +m_commands.Add(m_funPtr, m_argument, m_params); +return state; +} + +SGCONF::API_ACTION::API_ACTION(COMMANDS & commands, + const std::string & paramDescription, + bool needArgument, + const std::vector & params, + API_FUNCTION funPtr) + : m_commands(commands), + m_description(paramDescription), + m_argument(needArgument ? "1" : ""), // Hack + m_funPtr(funPtr) +{ +std::vector::const_iterator it(params.begin()); +while (it != params.end()) + { + m_suboptions.Add(it->name, MakeKVAction(it->name, it->shortDescr), it->longDescr); + ++it; + } +}