[util] Rework post_parse() handling

This commit is contained in:
Behdad Esfahbod 2021-08-05 11:43:25 -06:00
parent 3362b48f5a
commit 8588173ee6
1 changed files with 10 additions and 6 deletions

View File

@ -56,8 +56,6 @@ void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GN
struct option_group_t struct option_group_t
{ {
virtual ~option_group_t () {} virtual ~option_group_t () {}
virtual void post_parse (GError **error G_GNUC_UNUSED) {}
}; };
@ -82,6 +80,12 @@ struct option_parser_t
void add_main_options (); void add_main_options ();
static void
post_parse_ (void *thiz, GError **error) {}
template <typename Type>
static auto
post_parse_ (Type *thiz, GError **error) -> decltype (thiz->post_parse (error))
{ thiz->post_parse (error); }
template <typename Type> template <typename Type>
static gboolean static gboolean
post_parse (GOptionContext *context G_GNUC_UNUSED, post_parse (GOptionContext *context G_GNUC_UNUSED,
@ -89,8 +93,7 @@ struct option_parser_t
gpointer data, gpointer data,
GError **error) GError **error)
{ {
auto *thiz = static_cast<Type *>(data); option_parser_t::post_parse_ (static_cast<Type *> (data), error);
thiz->post_parse (error);
return !*error; return !*error;
} }
@ -512,7 +515,8 @@ struct text_options_t : option_group_t
void add_options (option_parser_t *parser); void add_options (option_parser_t *parser);
void post_parse (GError **error G_GNUC_UNUSED) override { void post_parse (GError **error G_GNUC_UNUSED)
{
if (text && text_file) if (text && text_file)
g_set_error (error, g_set_error (error,
G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
@ -548,7 +552,7 @@ struct output_options_t : option_group_t
void add_options (option_parser_t *parser, void add_options (option_parser_t *parser,
const char **supported_formats = nullptr); const char **supported_formats = nullptr);
void post_parse (GError **error G_GNUC_UNUSED) override void post_parse (GError **error G_GNUC_UNUSED)
{ {
if (output_format) if (output_format)
explicit_output_format = true; explicit_output_format = true;