summaryrefslogtreecommitdiff
path: root/tools/m4/member.m4
blob: 9dec2d660b284edbc9930f12f2522e7f0fee72ac (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
dnl
dnl --------------------------- Accessors ----------------------------
dnl


dnl Get:


dnl Creates accessors for simple types:
dnl _MEMBER_GET(cpp_name, c_name, cpp_type, c_type, deprecated (optional))
define(`_MEMBER_GET',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
$3 get_$1() const;
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
$3 __CPPNAME__::get_$1() const
{
  return _CONVERT($4,$3,`gobj()->$2');
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')

dnl Creates two accessors for pointer types, one const and one non-const:
define(`_MEMBER_GET_PTR',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
$3 get_$1();
  const $3 get_$1() const;
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
$3 __CPPNAME__::get_$1()
{
  return _CONVERT($4,$3,`gobj()->$2');
}

const $3 __CPPNAME__::get_$1() const
{
  return _CONVERT($4,const $3,`gobj()->$2');
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')

dnl Creates accessors for GObject-derived types that must be ref()ed.
define(`_MEMBER_GET_GOBJECT',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
Glib::RefPtr<$3> get_$1();
  Glib::RefPtr<const $3> get_$1() const;
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
Glib::RefPtr<$3> __CPPNAME__::get_$1()
{
  Glib::RefPtr<$3> ref_ptr(_CONVERT($4,Glib::RefPtr<$3>,`gobj()->$2'));

dnl We could use the bool with Glib::wrap(), but we want to share the m4 type-conversion map.
  if(ref_ptr)
    ref_ptr->reference();

  return ref_ptr;
}

Glib::RefPtr<const $3> __CPPNAME__::get_$1() const
{
  Glib::RefPtr<const $3> ref_ptr(_CONVERT($4,Glib::RefPtr<const $3>,`gobj()->$2'));

dnl We could use the bool with Glib::wrap(), but we want to share the m4 type-conversion map.
  if(ref_ptr)
    ref_ptr->reference();

  return ref_ptr;
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')


dnl Set:

dnl Creates accessors for simple types:
define(`_MEMBER_SET',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void set_$1(const $3`'& value);
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void __CPPNAME__::set_$1(const $3`'& value)
{
  gobj()->$2 = _CONVERT($3,$4,`value');
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')

dnl Creates setters for a member which is of char* type:
dnl The convenient way to use this macro is to pair it with
dnl _CONVERSION(`Glib::ustring', `const gchar*', `($3).c_str()')
dnl or similar conversion.
dnl There is no _MEMBER_GET_STR. With a suitable _CONVERSION,
dnl _MEMBER_GET can be used as the corresponding getter.
define(`_MEMBER_SET_STR',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void set_$1(const $3`'& value);
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void __CPPNAME__::set_$1(const $3`'& value)
{
  g_free((char*)gobj()->$2); // Cast away const, if any
  gobj()->$2 = g_strdup(_CONVERT($3,$4,`value'));
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')

dnl Creates accessors for pointer types:
define(`_MEMBER_SET_PTR',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void set_$1($3 value);
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void __CPPNAME__::set_$1($3 value)
{
  gobj()->$2 = _CONVERT($3,$4,`value');
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')

dnl Creates accessors for GObject-derived types that must be ref()ed.
define(`_MEMBER_SET_GOBJECT',`dnl
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void set_$1(const Glib::RefPtr<$3>& value);
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl
_PUSH(SECTION_CC)
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_START  ')dnl
void __CPPNAME__::set_$1(const Glib::RefPtr<$3>& value)
{
  Glib::RefPtr<$3> valueOld(_CONVERT($4,Glib::RefPtr<$3>,`gobj()->$2')); //Take possession of the old one, unref-ing it in the destructor.

  if(value)
    value->reference(); //Ref once for the recipient.

  gobj()->$2 = _CONVERT(const Glib::RefPtr<$3>&,$4,`value');
}
ifelse(`$5',`deprecated',`_DEPRECATE_IFDEF_END  ')dnl

_POP()')