From e5551f775dcdd1ab535f34171eb7f352443332fd Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 20 Mar 2021 11:50:22 -0700 Subject: options: Add validation macro for int type As an illustrative example. --- options/m_option.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'options/m_option.h') diff --git a/options/m_option.h b/options/m_option.h index e7446ce663..322f120a06 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -195,6 +195,9 @@ typedef int (*m_opt_generic_validate_fn)(struct mp_log *log, const m_option_t *o typedef int (*m_opt_string_validate_fn)(struct mp_log *log, const m_option_t *opt, struct bstr name, const char **value); +typedef int (*m_opt_int_validate_fn)(struct mp_log *log, const m_option_t *opt, + struct bstr name, const int *value); + // m_option.priv points to this if OPT_SUBSTRUCT is used struct m_sub_options { @@ -674,6 +677,11 @@ extern const char m_option_path_separator; #define OPT_CHANNELS(field) \ OPT_TYPED_FIELD(m_option_type_channels, struct m_channels, field) +#define OPT_INT_VALIDATE(field, validate_fn) \ + OPT_TYPED_FIELD(m_option_type_int, int, field), \ + .validate = (m_opt_generic_validate_fn) \ + MP_EXPECT_TYPE(m_opt_int_validate_fn, validate_fn) + #define OPT_STRING_VALIDATE(field, validate_fn) \ OPT_TYPED_FIELD(m_option_type_string, char*, field), \ .validate = (m_opt_generic_validate_fn) \ -- cgit v1.2.3