X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d625e80d62fc8b98c18a95c65e6fa329b7fcc85b..5985f3c811497f87ac58b64695b6d28879f07c65:/projects/sgconf/actions.h?ds=sidebyside diff --git a/projects/sgconf/actions.h b/projects/sgconf/actions.h index 886e17e2..33a11347 100644 --- a/projects/sgconf/actions.h +++ b/projects/sgconf/actions.h @@ -89,6 +89,7 @@ class PARAM_ACTION : public ACTION virtual std::string DefaultDescription() const; virtual OPTION_BLOCK & Suboptions() { return m_suboptions; } virtual PARSER_STATE Parse(int argc, char ** argv); + virtual void ParseValue(const std::string & value); private: RESETABLE & m_param; @@ -118,6 +119,10 @@ template inline PARSER_STATE PARAM_ACTION::Parse(int argc, char ** argv) { +if (argc == 0 || + argv == NULL || + *argv == NULL) + throw ERROR("Missing argument."); T value; if (str2x(*argv, value)) throw ERROR(std::string("Bad argument: '") + *argv + "'"); @@ -125,10 +130,33 @@ m_param = value; return PARSER_STATE(false, --argc, ++argv); } +template +inline +void PARAM_ACTION::ParseValue(const std::string & stringValue) +{ +if (stringValue.empty()) + throw ERROR("Missing value."); +T value; +if (str2x(stringValue, value)) + throw ERROR(std::string("Bad value: '") + stringValue + "'"); +m_param = value; +} + +template <> +inline +void PARAM_ACTION::ParseValue(const std::string & stringValue) +{ +m_param = stringValue; +} + template <> inline PARSER_STATE PARAM_ACTION::Parse(int argc, char ** argv) { +if (argc == 0 || + argv == NULL || + *argv == NULL) + throw ERROR("Missing argument."); m_param = *argv; return PARSER_STATE(false, --argc, ++argv); }