blob: 8716927fff1912360987a5b26b11411275d260e6 (
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Boilerplate code</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GObject Reference Manual">
<link rel="up" href="howto-gobject.html" title="How to define and implement a new GObject">
<link rel="prev" href="howto-gobject.html" title="How to define and implement a new GObject">
<link rel="next" href="howto-gobject-construction.html" title="Object Construction">
<meta name="generator" content="GTK-Doc V1.19 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="howto-gobject.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="howto-gobject.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GObject Reference Manual</th>
<td><a accesskey="n" href="howto-gobject-construction.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="howto-gobject-code"></a>Boilerplate code</h2></div></div></div>
<p>
In your code, the first step is to #include the needed headers: depending
on your header include strategy, this can be as simple as
<code class="literal">#include "maman-bar.h"</code> or as complicated as tens
of #include lines ending with <code class="literal">#include "maman-bar.h"</code>:
</p>
<pre class="programlisting">
/*
* Copyright information
*/
#include "maman-bar.h"
/* If you use Pimpls, include the private structure
* definition here. Some people create a maman-bar-private.h header
* which is included by the maman-bar.c file and which contains the
* definition for this private structure.
*/
struct _MamanBarPrivate {
int member_1;
/* stuff */
};
/*
* forward definitions
*/
</pre>
<p>
</p>
<p>
Call the <code class="function">G_DEFINE_TYPE</code> macro using the name
of the type, the prefix of the functions and the parent GType to
reduce the amount of boilerplate needed. This macro will:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">implement the <code class="function">maman_bar_get_type</code>
function</li>
<li class="listitem">define a parent class pointer accessible from
the whole .c file</li>
</ul></div>
<p>
</p>
<pre class="programlisting">
G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT)
</pre>
<p>
</p>
<p>
It is also possible to use the
<code class="function">G_DEFINE_TYPE_WITH_CODE</code> macro to control the
get_type function implementation - for instance, to add a call to
<code class="function">G_IMPLEMENT_INTERFACE</code> macro which will
call the <code class="function">g_type_implement_interface</code> function,
or call the <code class="function">G_ADD_PRIVATE</code> macro will add an
instance private data structure.
</p>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.19</div>
</body>
</html>
|