From 7aae399239d02e48de9060dded1d0232310d2141 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 6 Aug 2012 17:45:17 +0200 Subject: m_config: support auto-allocated sub-structs Given your option struct has a field that is a pointer to another struct, this commit allows you to declare options that write into that other struct. The code in m_config will dereference the pointer field on its own if such an option is accessed. If the field is NULL on initialization of the containing m_config, the struct is automatically allocated. OPT_SUBSTRUCT() can be used to declare such a field. struct m_sub_options is used to describe the pointed-to struct, and includes size and defaults if the struct has to be allocated by m_config. --- m_config.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'm_config.h') diff --git a/m_config.h b/m_config.h index beeab80a53..80897ce0e4 100644 --- a/m_config.h +++ b/m_config.h @@ -30,6 +30,7 @@ typedef struct m_profile m_profile_t; struct m_option; struct m_option_type; +struct m_sub_options; // Config option struct m_config_option { @@ -38,6 +39,8 @@ struct m_config_option { char *name; // Option description. const struct m_option *opt; + // Raw value of the option. + void *data; // Raw value of the backup of the global value (or NULL). void *global_backup; // See \ref ConfigOptionFlags. @@ -198,4 +201,7 @@ int m_config_set_profile_option(struct m_config *config, struct m_profile *p, */ void m_config_set_profile(struct m_config *config, struct m_profile *p); +void *m_config_alloc_struct(void *talloc_parent, + const struct m_sub_options *subopts); + #endif /* MPLAYER_M_CONFIG_H */ -- cgit v1.2.3