blob: a33a3b1775c2a343bae72349c2c9c6013f445c1e [file] [log] [blame]
<!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.75.2">
<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.14 (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" title="Boilerplate code">
<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" 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.
</p>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.14</div>
</body>
</html>