Debian Codegraph @

tools/m4/plugingen_base.m4

raw
1 dnl Copyright 2008 The gstreamermm Development Team
2
3 divert(-1)
4 dnl
5 dnl Macros to translate from C to C++ types.
6 dnl
7
8 dnl __HASH variable borrowed form glibmm's convert_base.m4 file
9 define(`__HASH',`__`'translit(`$*',`ABCDEFGHIJKLMNOPQRSTUVWXYZ<>[]&*, ',`abcdefghijklmnopqrstuvwxyzVBNMRSC_')`'')
10
11 dnl _CAMEL_TO_UNDERSCORE(GtkWidget) -> gtk_widget. Adapted from glibmm's
12 dnl _GET_TYPE_FUNC() macro (see glibmm's convert_base.m4 file for docs).
13 define(`_CAMEL_TO_UNDERSCORE',`dnl
14 translit(substr(patsubst(patsubst(`$1',`[A-Z][A-Z]+',`_\&'),`[A-Z][a-z]',`_\&'),1),`[A-Z]',`[a-z]')`'dnl
15 ')
16
17 dnl _GET_TYPE_FUNC(GtkWidget) -> gtk_widget_get_type(). Borrowed from glibmm's convert_base.m4 file (see glibmm's m4 file for docs).
18 define(`_GET_TYPE_FUNC',`dnl
19 _CAMEL_TO_UNDERSCORE($1)_get_type()`'dnl
20 ')
21
22 dnl Macro to insert left quote
23 define(`_LQ',`changequote(<,>)`dnl'
24 changequote`'')
25
26 dnl Macro to insert right quote
27 define(`_RQ',`changequote(<,>)dnl`
28 'changequote`'')
29
30 dnl _TRANSLATION(ctype, cpptype, param cpptype, return cpptype, cppinclude)
31 dnl
32 dnl Records a translation from a C type to a C++ type. If a return cpptype is
33 dnl not given, it is assumed to be the same as the param cpptype. A cpp
34 dnl include need not be specified (the <> or "" are required though). If an
35 dnl include is specified, a C++ include directive may be generated with the
36 dnl _TRANSLATION_INCLUDE macro.
37 dnl
38 define(`_TRANSLATION',`dnl
39 define(`TFT'__HASH(`$1'),`$2')dnl
40 define(`TFP'__HASH(`$1'),`$3')dnl
41 ifelse(`$4',,`dnl
42 define(`TFR'__HASH(`$1'),`$3')',`dnl
43 define(`TFR'__HASH(`$1'),`$4')dnl
44 ')`'dnl
45 ifelse(`$5',,,`define(`IF'__HASH(`$1'),`$5')')`'dnl
46 ')dnl
47
48 dnl _TRANSLATION_INCLUDE(ctype)
49 dnl
50 dnl Produces a C++ include direcive of the C++ header for the ctype if a
51 dnl translation has been defined and an include parameter was included. Only
52 dnl one directive will be generated for multiple calls (i.e. none but the first
53 dnl call produces anything).
54 dnl
55 define(`_TRANSLATION_INCLUDE',`dnl
56 ifdef(`IFC'__HASH(`$1'),,`dnl
57 ifdef(`IF'__HASH(`$1'),`dnl
58 #include indir(`IF'__HASH(`$1'))
59 dnl
60 define(`IFC'__HASH(`$1'))dnl
61 ')`'dnl
62 ')`'dnl
63 ')dnl
64
65 dnl _TRANSLATE(ctype, translation type)
66 dnl
67 dnl Translates from a specified C type to a C++ type, param or return type.
68 dnl `translation type' may be:
69 dnl `type' - For a C to C++ type translation.
70 dnl `param' - For a C to C++ parameter translation.
71 dnl `return' - For a C to C++ return translation.
72 dnl
73 define(`_TRANSLATE',`dnl
74 ifelse(dnl
75 `$2',`type',`dnl
76 ifdef(`TFT'__HASH(`$1'), `indir(`TFT'__HASH(`$1'))',`dnl
77 errprint(`No C++ type translation from $1 is defined.
78 ')`'dnl
79 m4exit(1)`'dnl
80 ')',dnl
81 `$2',`param',`dnl
82 ifdef(`TFP'__HASH(`$1'), `indir(`TFP'__HASH(`$1'))',`dnl
83 errprint(`No C++ parameter translation from $1 is defined.
84 ')`'dnl
85 m4exit(1)`'dnl
86 ')',dnl
87 `$2',`return',`dnl
88 ifdef(`TFR'__HASH(`$1'), `indir(`TFR'__HASH(`$1'))',`dnl
89 ifdef(`TFP'__HASH(`$1'), `indir(`TFP'__HASH(`$1'))',`dnl
90 errprint(`No C++ return translation from $1 is defined.
91 ')`'dnl
92 m4exit(1)`'dnl
93 ')`'dnl
94 ')`'dnl
95 ')`'dnl
96 ')dnl
97
98 dnl _ENUM_IS_WRAPPED(CEnumType)
99 dnl
100 dnl Used to tell when an enum has been wrapped. When a _WRAP_PLUGIN_ENUM() is
101 dnl used to wrap enums used in plug-ins, the enum will be wrapped only if it
102 dnl hasn't been flagged as wrapped by this macro.
103 dnl
104 define(`_ENUM_IS_WRAPPED',`dnl
105 define(`EIW'__HASH(`$1'))dnl
106 ')dnl
107
108 dnl _WRAP_PLUGIN_ENUM(prefix, CppEnumType)
109 dnl
110 dnl Attempts to generate a _WRAP_ENUM() and a _TRANSLATION() macro for an enum
111 dnl used by a plug-in. If the enum has been flagged as wrapped by the
112 dnl _ENUM_IS_WRAPPED() macro nothing will be generated.
113 define(`_WRAP_PLUGIN_ENUM',`dnl
114 ifdef(`EIW'__HASH(`$1$2'),,`dnl
115 _TRANSLATION(`$1$2',`$1::$2',`$1::$2')dnl
116 _WRAP_ENUM($2,$1$2)
117 _CONV_ENUM($1,$2)
118
119 _ENUM_IS_WRAPPED($1$2)dnl
120 ')`'dnl
121 ')dnl
122
123 dnl _PLUGIN_ENUM_GET_TYPE_FUNC(CEnumType)
124 dnl
125 dnl Attempts to generate a *_get_type() function for an enum specific to a
126 dnl plug-in. If the enum has been flagged as wrapped by the
127 dnl _ENUM_IS_WRAPPED() macro it is taken taken to be a non-plugin enum and
128 dnl nothing will be generated. Only one function is generated no matter how
129 dnl many times the macro is used.
130 define(`_PLUGIN_ENUM_GET_TYPE_FUNC',`dnl
131 ifdef(`EIW'__HASH(`$1'),,`dnl
132 ifdef(`EGTF'__HASH(`$1'),,`dnl
133 static GType _GET_TYPE_FUNC($1)
134 {
135 static GType const type = g_type_from_name("$1");
136 return type;
137 }
138
139 define(`EGTF'__HASH(`$1'))dnl
140 ')`'dnl
141 ')`'dnl
142 ')dnl
143
144 dnl _C_ENUM_VALUES(CAPS_UNDERSCORE_C_ENUM_TYPE, nick1, val1, nick2, val2, ...)
145 dnl
146 dnl Generates the enum values of a C enum definition from the C enum type name
147 dnl and the list of nicknames and values of the enum. The enum type name must
148 dnl be converted from camel to caps/underscore format.
149 define(`_C_ENUM_VALUES',`dnl
150 ifelse(eval(`$# < 3'),`1',,eval(`$# == 3'),`1',`dnl
151 $1_`'translit(translit(`$2',`a-z',`A-Z'),`-',`_') = $3
152 ',`dnl
153 $1_`'translit(translit(`$2',`a-z',`A-Z'),`-',`_') = $3,
154 _C_ENUM_VALUES(`$1',shift(shift(shift($@))))dnl
155 ')`'dnl
156 ')dnl
157
158 dnl _C_ENUM_DEFINITION(CEnumType, nick1, val1, nick2, val2, ...)
159 dnl
160 dnl Generates a C enum definition from the C enum type name and the list of
161 dnl nicknames and values of the enum if the enum has not been flagged as
162 dnl wrapped with the _ENUM_IS_WRAPPED() macro. Only one definition is
163 dnl generated per multiple calls.
164 define(`_C_ENUM_DEFINITION',`dnl
165 ifdef(`EIW'__HASH(`$1'),,`dnl
166 ifdef(`CED'__HASH(`$1'),,`dnl
167 enum $1
168 {
169 _C_ENUM_VALUES(translit(_CAMEL_TO_UNDERSCORE(`$1'),`a-z',`A-Z'),shift($@))dnl
170 };
171
172 define(`CED'__HASH(`$1'))dnl
173 ')`'dnl
174 ')`'dnl
175 ')dnl
176
177 #Basic C to C++ translations
178 _TRANSLATION(`void',`void',`void')
179 _TRANSLATION(`gboolean',`bool',`bool')
180 _TRANSLATION(`gint',`int',`int')
181 _TRANSLATION(`guint',`guint',`guint')
182 _TRANSLATION(`gulong',`gulong',`gulong')
183 _TRANSLATION(`gint64',`gint64',`gint64')
184 _TRANSLATION(`guint64',`guint64',`guint64')
185 _TRANSLATION(`gfloat',`float',`float')
186 _TRANSLATION(`gdouble',`double',`double')
187
188 #String C to C++ translations
189 _TRANSLATION(`gchararray',`Glib::ustring',`const Glib::ustring&',`Glib::ustring')
190
191 include(plugingen.m4)
192 divert(0)dnl