mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
gst/gststructure.c: Remove that ugly if-then thing in the code that converts between strings and types.
Original commit message from CVS: * gst/gststructure.c: (gst_structure_get_abbrs), (gst_structure_from_abbr), (gst_structure_to_abbr): Remove that ugly if-then thing in the code that converts between strings and types.
This commit is contained in:
parent
3207eb2f42
commit
824c331e32
2 changed files with 72 additions and 47 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2004-11-02 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
|
* gst/gststructure.c: (gst_structure_get_abbrs),
|
||||||
|
(gst_structure_from_abbr), (gst_structure_to_abbr):
|
||||||
|
Remove that ugly if-then thing in the code that converts
|
||||||
|
between strings and types.
|
||||||
|
|
||||||
2004-11-02 Wim Taymans <wim@fluendo.com>
|
2004-11-02 Wim Taymans <wim@fluendo.com>
|
||||||
|
|
||||||
* gst/gstscheduler.c: (gst_scheduler_add_element),
|
* gst/gstscheduler.c: (gst_scheduler_add_element),
|
||||||
|
|
|
@ -987,50 +987,75 @@ typedef struct _GstStructureAbbreviation
|
||||||
}
|
}
|
||||||
GstStructureAbbreviation;
|
GstStructureAbbreviation;
|
||||||
|
|
||||||
static GstStructureAbbreviation gst_structure_abbrs[] = {
|
static GstStructureAbbreviation *
|
||||||
{"int", G_TYPE_INT},
|
gst_structure_get_abbrs (gint * n_abbrs)
|
||||||
{"i", G_TYPE_INT},
|
{
|
||||||
{"float", G_TYPE_FLOAT},
|
static GstStructureAbbreviation *abbrs = NULL;
|
||||||
{"f", G_TYPE_FLOAT},
|
static gint num = 0;
|
||||||
{"double", G_TYPE_DOUBLE},
|
|
||||||
{"d", G_TYPE_DOUBLE},
|
if (abbrs == NULL) {
|
||||||
/* these are implemented with strcmp below */
|
/* dynamically generate the array */
|
||||||
//{ "buffer", GST_TYPE_BUFFER },
|
GstStructureAbbreviation dyn_abbrs[] = {
|
||||||
//{ "fourcc", GST_TYPE_FOURCC },
|
{"int", G_TYPE_INT}
|
||||||
//{ "4", GST_TYPE_FOURCC },
|
,
|
||||||
//{ "fraction", GST_TYPE_FRACTION },
|
{"i", G_TYPE_INT}
|
||||||
{"boolean", G_TYPE_BOOLEAN},
|
,
|
||||||
{"bool", G_TYPE_BOOLEAN},
|
{"float", G_TYPE_FLOAT}
|
||||||
{"b", G_TYPE_BOOLEAN},
|
,
|
||||||
{"string", G_TYPE_STRING},
|
{"f", G_TYPE_FLOAT}
|
||||||
{"str", G_TYPE_STRING},
|
,
|
||||||
{"s", G_TYPE_STRING}
|
{"double", G_TYPE_DOUBLE}
|
||||||
};
|
,
|
||||||
|
{"d", G_TYPE_DOUBLE}
|
||||||
|
,
|
||||||
|
{"buffer", GST_TYPE_BUFFER}
|
||||||
|
,
|
||||||
|
{"fourcc", GST_TYPE_FOURCC}
|
||||||
|
,
|
||||||
|
{"4", GST_TYPE_FOURCC}
|
||||||
|
,
|
||||||
|
{"fraction", GST_TYPE_FRACTION}
|
||||||
|
,
|
||||||
|
{"boolean", G_TYPE_BOOLEAN}
|
||||||
|
,
|
||||||
|
{"bool", G_TYPE_BOOLEAN}
|
||||||
|
,
|
||||||
|
{"b", G_TYPE_BOOLEAN}
|
||||||
|
,
|
||||||
|
{"string", G_TYPE_STRING}
|
||||||
|
,
|
||||||
|
{"str", G_TYPE_STRING}
|
||||||
|
,
|
||||||
|
{"s", G_TYPE_STRING}
|
||||||
|
};
|
||||||
|
num = G_N_ELEMENTS (dyn_abbrs);
|
||||||
|
/* permanently allocate and copy the array now */
|
||||||
|
abbrs = g_new0 (GstStructureAbbreviation, num);
|
||||||
|
memcpy (abbrs, dyn_abbrs, sizeof (GstStructureAbbreviation) * num);
|
||||||
|
}
|
||||||
|
*n_abbrs = num;
|
||||||
|
|
||||||
|
return abbrs;
|
||||||
|
}
|
||||||
|
|
||||||
static GType
|
static GType
|
||||||
gst_structure_from_abbr (const char *type_name)
|
gst_structure_from_abbr (const char *type_name)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
GstStructureAbbreviation *abbrs;
|
||||||
|
gint n_abbrs;
|
||||||
|
|
||||||
g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
|
g_return_val_if_fail (type_name != NULL, G_TYPE_INVALID);
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (gst_structure_abbrs); i++) {
|
abbrs = gst_structure_get_abbrs (&n_abbrs);
|
||||||
if (strcmp (type_name, gst_structure_abbrs[i].type_name) == 0) {
|
|
||||||
return gst_structure_abbrs[i].type;
|
for (i = 0; i < n_abbrs; i++) {
|
||||||
|
if (strcmp (type_name, abbrs[i].type_name) == 0) {
|
||||||
|
return abbrs[i].type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME shouldn't be a special case */
|
/* this is the fallback */
|
||||||
if (strcmp (type_name, "fourcc") == 0 || strcmp (type_name, "4") == 0) {
|
|
||||||
return GST_TYPE_FOURCC;
|
|
||||||
}
|
|
||||||
if (strcmp (type_name, "buffer") == 0) {
|
|
||||||
return GST_TYPE_BUFFER;
|
|
||||||
}
|
|
||||||
if (strcmp (type_name, "fraction") == 0) {
|
|
||||||
return GST_TYPE_FRACTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_type_from_name (type_name);
|
return g_type_from_name (type_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1038,24 +1063,17 @@ static const char *
|
||||||
gst_structure_to_abbr (GType type)
|
gst_structure_to_abbr (GType type)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
GstStructureAbbreviation *abbrs;
|
||||||
|
gint n_abbrs;
|
||||||
|
|
||||||
g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
|
g_return_val_if_fail (type != G_TYPE_INVALID, NULL);
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (gst_structure_abbrs); i++) {
|
abbrs = gst_structure_get_abbrs (&n_abbrs);
|
||||||
if (type == gst_structure_abbrs[i].type) {
|
|
||||||
return gst_structure_abbrs[i].type_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME shouldn't be a special case */
|
for (i = 0; i < n_abbrs; i++) {
|
||||||
if (type == GST_TYPE_FOURCC) {
|
if (type == abbrs[i].type) {
|
||||||
return "fourcc";
|
return abbrs[i].type_name;
|
||||||
}
|
}
|
||||||
if (type == GST_TYPE_BUFFER) {
|
|
||||||
return "buffer";
|
|
||||||
}
|
|
||||||
if (type == GST_TYPE_FRACTION) {
|
|
||||||
return "fraction";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_type_name (type);
|
return g_type_name (type);
|
||||||
|
|
Loading…
Reference in a new issue