summaryrefslogtreecommitdiff
path: root/tools/m4/method.m4
blob: 3c48b3e10a5b450a74510a246870961d68371d37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
dnl $Id$

dnl
dnl
dnl  Code generation sections for making a method.
dnl
dnl


dnl
dnl method
dnl           $1       $2     $3         $4       $5        $6        $7         $8          $9     $10       $11       $12         $13       $14         $15               $16        $17              $18        $19        $20         $21
dnl  _METHOD(cppname,cname,cpprettype,crettype,arglist,cdeclarations,cargs,cinitializations,const,refreturn,errthrow,deprecated,constversion,ifdef,arglist_without_types,out_param,out_param_cpptype,slot_type,slot_name,no_slot_copy,wrap_line)
define(`_METHOD',`dnl
_PUSH(SECTION_CC)
ifelse(`$12',,,`_DEPRECATE_IFDEF_START
')dnl
ifelse(`$15',,,`#ifdef $15'
)dnl
$3 __CPPNAME__::$1`'($5)ifelse(`$9',1,` const')
{
ifelse(`$13',,dnl
`ifelse(`$10'`$11',,dnl If it is not errthrow or refreturn
dnl If a slot type has been specified insert a slot copy declaration.
`ifelse(`$18',,,dnl
dnl See if the slot should or should not be copied
`ifelse(`$20',,dnl
`  // Create a copy of the slot.
  $18* slot_copy = new $18($19); ',dnl
dnl
`  // Use the original slot (not a copy).
  $18* slot_copy = const_cast<$18*>(&$19);')

')`'dnl
dnl Insert the declarations for C output parameters
ifelse(`$6',,,`$6
')`'dnl
ifelse(`$16',,dnl If no C++ output parameter is specified
`ifelse(`$3',void,dnl If the C function returns voids:
`  $2(ifelse(`$9',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$7',,,`, ')$7);
dnl Insert the initializations for the C output parameters
ifelse(`$8',,,`$8
')dnl
',dnl If the C function returns non-void:
dnl Store the return if there are C output parameters.
`ifelse(`$6',,`  return ',`  `$3' retvalue = ')_CONVERT($4,`$3',`$2`'(ifelse(`$9',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$7',,,`, ')$7)');
dnl Insert the initializations for the C output parameters
ifelse(`$8',,,`$8
')dnl
dnl return the value
ifelse(`$6',,,`  return retvalue;
')dnl
')'dnl End if it returns voids.
dnl A C++ output parameter is specified:
,`  _INITIALIZE($17,$4,`$16',`$2`'(ifelse(`$9',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$7',,,`, ')$7)',$21);
dnl
dnl Insert the initializations for the C output parameters
ifelse(`$8',,,`$8
')dnl
')',dnl End if a C++ output parameter is specified.
dnl If is errthrow or refreturn
`ifelse(`$11',,,`  GError* gerror = 0;
')dnl
dnl If a slot type has been specified insert a slot copy declaration.
ifelse(`$18',,,dnl
dnl See if the slot should or should not be copied
`ifelse(`$20',,dnl
`  // Create a copy of the slot.
  $18* slot_copy = new $18($19); ',dnl
dnl
`  // Use the original slot (not a copy).
  $18* slot_copy = const_cast<$18*>(&$19);')

')`'dnl
dnl Insert the declarations for C output parameters
ifelse(`$6',,,`$6
')`'dnl
ifelse(`$16',,dnl If no C++ output parameter is specified:
`  ifelse(`$3',void,,``$3' retvalue = ')_CONVERT($4,`$3',`$2`'(ifelse(`$9',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$7',,,`, ')$7)');
'dnl
,dnl A C++ output parameter is specified:
`  _INITIALIZE($17,$4,`$16',`$2`'(ifelse(`$9',1,const_cast<__CNAME__*>(gobj()),gobj())`'ifelse(`$7',,,`, ')$7)',$21);
'dnl
)dnl
ifelse(`$11',,,`dnl
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
')dnl
ifelse(`$10',,,`dnl
  if(ifelse(`$16',,`retvalue',$16))
    ifelse(`$16',,`retvalue',$16)->reference(); //The function does not do a ref for us.
')dnl
dnl Insert the initializations for the C output parameters
ifelse(`$8',,,`$8
')`'dnl
ifelse(`$3',void,,`  return retvalue;
')dnl
')dnl End errthrow/refreturn
',`  return const_cast<__CPPNAME__*>(this)->$1($14);
')dnl
}

ifelse(`$15',,,`
#endif // $15
')dnl
ifelse(`$12',,,`_DEPRECATE_IFDEF_END
')dnl
_POP()')

dnl
dnl static method
dnl                  $1       $2     $3         $4      $5        $6         $7         $8            $9      $10         $11       $12     $13        $14         $15      $16          $17       $18
dnl  _STATIC_METHOD(cppname,cname,cpprettype,crettype,arglist,cdeclarations,cargs,cinitializations,refreturn,errthrow,deprecated,ifdef,out_param,out_param_type,slot_type,slot_name,no_slot_copy,wrap_line)
define(`_STATIC_METHOD',`dnl
_PUSH(SECTION_CC)
ifelse(`$11',,,`_DEPRECATE_IFDEF_START
')dnl
ifelse(`$12',,,`#ifdef $12'
)dnl
$3 __CPPNAME__::$1($5)
{
ifelse(`$9'`$10',,dnl
dnl If a slot type has been specified insert a slot copy declaration.
ifelse(`$15',,,dnl
dnl See if the slot should or should not be copied
`ifelse(`$17',,dnl
`  // Create a copy of the slot.
  $15* slot_copy = new $15($16); ',dnl
dnl
`  // Use the original slot (not a copy).
  $15* slot_copy = const_cast<$15*>(&$16);')

')`'dnl
dnl Insert declarations for C the output parameters
ifelse(`$6',,,`$6
')`'dnl
`ifelse(`$13',,
dnl If no C++ output parameter is specified.
`  ifelse(`$3',void,,dnl
dnl Returns non-void:
dnl Store the return if there are C output parameters
ifelse(`$6',,`return ',``$3' retval = '))_CONVERT($4,`$3',`$2`'($7)');'dnl
dnl A C++ output parameter is specified so initialize it from C return
,`  _INITIALIZE($14,$4,`$13',`$2`'($7)',$18);'dnl
)
dnl Insert the initializations for the C output parameters if there are any
ifelse(`$8',,,`$8
')`'dnl
dnl Return the value if it was stored and if the method returns something
ifelse(`$3',void,,`ifelse(`$6',,,`  return retval;
')')dnl
',dnl End if a C++ output parameter is specified.
`ifelse(`$10',,,`  GError* gerror = 0;')
dnl If a slot type has been specified insert a slot copy declaration.
ifelse(`$15',,,dnl
dnl See if the slot should or should not be copied
`ifelse(`$17',,dnl
`  // Create a copy of the slot.
  $15* slot_copy = new $15($16); ',dnl
dnl
`  // Use the original slot (not a copy).
  $15* slot_copy = const_cast<$15*>(&$16);')

')`'dnl
dnl Insert the declarations for the C output parameters
ifelse(`$6',,,`$6
')`'dnl
ifelse(`$13',,dnl If no C++ output parameter is specified:
  ifelse(`$3',void,,``$3' retvalue = ')_CONVERT($4,`$3',`$2`'($7)');dnl
dnl A C++ output parameter is specified:
,`  _INITIALIZE($14,$4,`$13',`$2`'($7)',$18);'dnl
)dnl
ifelse(`$10',,,`
  if(gerror)
    ::Glib::Error::throw_exception(gerror);
')dnl
dnl Insert the initializations for the C output parameters.
ifelse(`$8',,,`$8
')`'dnl
ifelse(`$9',,,`
  if(ifelse(`$13',,`retvalue',$13))
    ifelse(`$13',,`retvalue',$13)->reference(); //The function does not do a ref for us
')dnl
ifelse(`$3',void,,`  return retvalue;
')dnl
')dnl
}

ifelse(`$12',,,`
#endif // $12
')dnl
ifelse(`$11',,,`_DEPRECATE_IFDEF_END
')
_POP()')