2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gstutils.h: Header for various utility functions
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #ifndef __GST_UTILS_H__
25 #define __GST_UTILS_H__
28 #include <gst/gstelement.h>
32 void gst_util_set_value_from_string (GValue *value, const gchar *value_str);
33 void gst_util_set_object_arg (GObject *object, const gchar *name, const gchar *value);
35 void gst_util_dump_mem (const guchar *mem, guint size);
37 void gst_print_pad_caps (GString *buf, gint indent, GstPad *pad);
38 void gst_print_element_args (GString *buf, gint indent, GstElement *element);
41 /* Macros for defining classes. Ideas taken from Bonobo, which took theirs
42 from Nautilus and GOB. */
44 /* Define the boilerplate type stuff to reduce typos and code size. Defines
45 the get_type method and the parent_class static variable.
46 void additional_initializations (GType type) is for initializing interfaces
47 and stuff like that */
49 #define GST_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations) \
51 static void type_as_function ## _base_init (gpointer g_class); \
52 static void type_as_function ## _class_init (type ## Class *g_class); \
53 static void type_as_function ## _init (type *object); \
54 static parent_type ## Class *parent_class = NULL; \
56 type_as_function ## _class_init_trampoline (gpointer g_class, \
59 parent_class = (parent_type ## Class *) g_type_class_peek_parent (g_class); \
60 type_as_function ## _class_init ((type ## Class *)g_class); \
64 type_as_function ## _get_type (void) \
66 static GType object_type = 0; \
67 if (object_type == 0) { \
68 static const GTypeInfo object_info = { \
69 sizeof (type ## Class), \
70 type_as_function ## _base_init, \
71 NULL, /* base_finalize */ \
72 type_as_function ## _class_init_trampoline, \
73 NULL, /* class_finalize */ \
74 NULL, /* class_data */ \
76 0, /* n_preallocs */ \
77 (GInstanceInitFunc) type_as_function ## _init \
79 object_type = g_type_register_static (parent_type_macro, #type, \
80 &object_info, (GTypeFlags) 0); \
81 additional_initializations (object_type); \
86 #define __GST_DO_NOTHING(type) /* NOP */
87 #define GST_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro) \
88 GST_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro, \
91 /* Just call the parent handler. This assumes that there is a variable
92 * named parent_class that points to the (duh!) parent class. Note that
93 * this macro is not to be used with things that return something, use
94 * the _WITH_DEFAULT version for that */
95 #define GST_CALL_PARENT(parent_class_cast, name, args) \
96 ((parent_class_cast(parent_class)->name != NULL) ? \
97 parent_class_cast(parent_class)->name args : (void) 0)
99 /* Same as above, but in case there is no implementation, it evaluates
101 #define GST_CALL_PARENT_WITH_DEFAULT(parent_class_cast, name, args, def_return) \
102 ((parent_class_cast(parent_class)->name != NULL) ? \
103 parent_class_cast(parent_class)->name args : def_return)
108 #endif /* __GST_UTILS_H__ */