diff options
author | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-11-05 12:40:56 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@gmail.com> | 2012-11-05 12:40:56 +0100 |
commit | e0421f87636741286488c903f37712b5c5038d3c (patch) | |
tree | ee26d617e1928ba9a224bd615f72fee7f607c2f5 /tools | |
parent | 471acd3dd41caab2fad0ec62cd746aafc9a5d5b1 (diff) | |
download | uca-e0421f87636741286488c903f37712b5c5038d3c.tar.gz uca-e0421f87636741286488c903f37712b5c5038d3c.tar.bz2 uca-e0421f87636741286488c903f37712b5c5038d3c.tar.xz uca-e0421f87636741286488c903f37712b5c5038d3c.zip |
Output default value and possible value ranges
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gen-doc.c | 81 |
1 files changed, 75 insertions, 6 deletions
diff --git a/tools/gen-doc.c b/tools/gen-doc.c index f555a5f..eb61cc9 100644 --- a/tools/gen-doc.c +++ b/tools/gen-doc.c @@ -67,9 +67,9 @@ print_property_toc (GParamSpec **pspecs, guint n_props) g_print ("<h2>Properties</h2><ul id=\"toc\">"); for (guint i = 0; i < n_props; i++) { - GParamSpec *pspec = pspecs[i]; + GParamSpec *pspec = pspecs[i]; const gchar *name = g_param_spec_get_name (pspec); - + g_print ("<li><code><a href=#%s>\"%s\"</a></code></li>", name, name); } @@ -77,21 +77,90 @@ print_property_toc (GParamSpec **pspecs, guint n_props) } static void +print_value_info (GParamSpec *pspec) +{ + gchar *default_value = NULL; + GString *range = g_string_new(""); + +#define MAKE_RANGE(spec_type, fmt) \ + { \ + spec_type *spec = (spec_type *) pspec; \ + g_string_printf (range, \ + fmt" ≤ <em>%s</em> ≤ "fmt, \ + spec->minimum, \ + g_param_spec_get_name (pspec), \ + spec->maximum); \ + default_value = g_strdup_printf (fmt, spec->default_value); \ + } + + switch (pspec->value_type) { + case G_TYPE_BOOLEAN: + { + GParamSpecBoolean *spec = (GParamSpecBoolean *) pspec; + default_value = spec->default_value ? g_strdup ("<code>TRUE</code>") : g_strdup ("<code>FALSE</code>"); + } + break; + + case G_TYPE_UINT: + MAKE_RANGE (GParamSpecUInt, "%i"); + break; + + case G_TYPE_FLOAT: + MAKE_RANGE (GParamSpecFloat, "%.1e"); + break; + + case G_TYPE_DOUBLE: + MAKE_RANGE (GParamSpecDouble, "%.1e"); + break; + } + +#undef MAKE_RANGE + + if (g_type_is_a (pspec->value_type, G_TYPE_ENUM)) { + GParamSpecEnum *spec = (GParamSpecEnum *) pspec; + + if (spec->enum_class->n_values > 0) { + g_string_printf (range, "<table><tr><th>Enum name</th><th>Value</th>"); + + for (guint i = 0; i < spec->enum_class->n_values; i++) { + GEnumValue *v = &spec->enum_class->values[i]; + g_string_append_printf (range, + "<tr><td><code>%s</code></td><td>%i</td></tr>", + v->value_name, v->value); + } + + g_string_append_printf (range, "</table>"); + } + } + + if (range->len > 0) + g_print ("<p>Possible values: %s</p>", range->str); + + if (default_value != NULL) { + g_print ("<p>Default value: %s</p>", default_value); + g_free (default_value); + } + + g_string_free (range, TRUE); +} + +static void print_property_descriptions (GParamSpec **pspecs, guint n_props) { g_print ("<h2>Details</h2><dl>"); for (guint i = 0; i < n_props; i++) { - GParamSpec *pspec = pspecs[i]; + GParamSpec *pspec = pspecs[i]; const gchar *name = g_param_spec_get_name (pspec); g_print ("<dt id=\"%s\"><a href=\"#toc\">%s</a></dt>\n", name, name); g_print ("<dd>"); - g_print ("<pre><code class=\"prop-type\">\"%s\" : %s : %s</code></pre>\n", - name, + g_print ("<pre><code class=\"prop-type\">\"%s\" : %s : %s</code></pre>\n", + name, g_type_name (pspec->value_type), get_flags_description (pspec)); g_print ("<p>%s</p>\n", g_param_spec_get_blurb (pspec)); + print_value_info (pspec); g_print ("</dd>"); } @@ -104,7 +173,7 @@ print_properties (UcaCamera *camera) GObjectClass *oclass; GParamSpec **pspecs; guint n_props; - + oclass = G_OBJECT_GET_CLASS (camera); pspecs = g_object_class_list_properties (oclass, &n_props); |