summaryrefslogtreecommitdiffstats
path: root/m_option.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-18 15:31:46 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:10:31 +0200
commit69ce4591d09f1fda85c6a71d452d26a2712cda4e (patch)
tree27284241b989d6d78710151617f98c698b4f6b69 /m_option.h
parentf607d104b60b48cd293fbc057ba0a4ddaf9f8a73 (diff)
downloadmpv-69ce4591d09f1fda85c6a71d452d26a2712cda4e.tar.bz2
mpv-69ce4591d09f1fda85c6a71d452d26a2712cda4e.tar.xz
commands: generally handle property formatting with m_option
Use the m_option code by default to format property values, instead of having separate code in m_property. To facilitate that, add a pretty_print callback to option types. These format values in a more human readable and user friendly way, as opposed to the print callback, which produces parseable values. This also changes the strings used with flags. Instead of "enabled" and "disabled", flags are formatted as "yes" and "no". (We could use the pretty_print callback to deal with this, but we don't for consistency.)
Diffstat (limited to 'm_option.h')
-rw-r--r--m_option.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/m_option.h b/m_option.h
index 75f9ee5925..acbbb3fd9f 100644
--- a/m_option.h
+++ b/m_option.h
@@ -209,6 +209,11 @@ struct m_option_type {
*/
char *(*print)(const m_option_t *opt, const void *val);
+ // Print the value in a human readable form. Unlike print(), it doesn't
+ // necessarily return the exact value, and is generally not parseable with
+ // parse().
+ char *(*pretty_print)(const m_option_t *opt, const void *val);
+
// Copy data between two locations. Deep copy if the data has pointers.
/** \param opt The option to copy.
* \param dst Pointer to the destination memory.
@@ -413,6 +418,15 @@ static inline char *m_option_print(const m_option_t *opt, const void *val_ptr)
return NULL;
}
+static inline char *m_option_pretty_print(const m_option_t *opt,
+ const void *val_ptr)
+{
+ if (opt->type->pretty_print)
+ return opt->type->pretty_print(opt, val_ptr);
+ else
+ return m_option_print(opt, val_ptr);
+}
+
// Helper around \ref m_option_type::copy.
static inline void m_option_copy(const m_option_t *opt, void *dst,
const void *src)