Initial commit
[platform/upstream/glib2.0.git] / docs / reference / gobject / html / howto-gobject-code.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Boilerplate code</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
7 <link rel="home" href="index.html" title="GObject Reference Manual">
8 <link rel="up" href="howto-gobject.html" title="How to define and implement a new GObject">
9 <link rel="prev" href="howto-gobject.html" title="How to define and implement a new GObject">
10 <link rel="next" href="howto-gobject-construction.html" title="Object Construction">
11 <meta name="generator" content="GTK-Doc V1.13 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 <link rel="preface" href="pr01.html" title="Introduction">
14 <link rel="part" href="pt01.html" title="Part I. Concepts">
15 <link rel="chapter" href="chapter-intro.html" title="Background">
16 <link rel="chapter" href="chapter-gtype.html" title="The GLib Dynamic Type System">
17 <link rel="chapter" href="chapter-gobject.html" title="The GObject base class">
18 <link rel="chapter" href="chapter-signal.html" title="The GObject messaging system">
19 <link rel="reference" href="rn01.html" title="API Reference">
20 <link rel="reference" href="rn02.html" title="Tools Reference">
21 <link rel="part" href="pt02.html" title="Part IV. Tutorial">
22 <link rel="chapter" href="howto-gobject.html" title="How to define and implement a new GObject">
23 <link rel="chapter" href="howto-interface.html" title="How to define and implement interfaces">
24 <link rel="chapter" href="howto-signals.html" title="How to create and use signals">
25 <link rel="part" href="pt03.html" title="Part V. Related Tools">
26 <link rel="chapter" href="tools-vala.html" title="Vala">
27 <link rel="chapter" href="tools-gob.html" title="GObject builder">
28 <link rel="chapter" href="tools-ginspector.html" title="Graphical inspection of GObjects">
29 <link rel="chapter" href="tools-refdb.html" title="Debugging reference count problems">
30 <link rel="chapter" href="tools-gtkdoc.html" title="Writing API docs">
31 <link rel="index" href="api-index-full.html" title="Index">
32 <link rel="index" href="api-index-deprecated.html" title="Index of deprecated symbols">
33 <link rel="index" href="api-index-2-2.html" title="Index of new symbols in 2.2">
34 <link rel="index" href="api-index-2-4.html" title="Index of new symbols in 2.4">
35 <link rel="index" href="api-index-2-6.html" title="Index of new symbols in 2.6">
36 <link rel="index" href="api-index-2-8.html" title="Index of new symbols in 2.8">
37 <link rel="index" href="api-index-2-10.html" title="Index of new symbols in 2.10">
38 <link rel="index" href="api-index-2-12.html" title="Index of new symbols in 2.12">
39 <link rel="index" href="api-index-2-14.html" title="Index of new symbols in 2.14">
40 <link rel="index" href="api-index-2-18.html" title="Index of new symbols in 2.18">
41 <link rel="index" href="api-index-2-22.html" title="Index of new symbols in 2.22">
42 <link rel="index" href="api-index-2-24.html" title="Index of new symbols in 2.24">
43 </head>
44 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
45 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
46 <td><a accesskey="p" href="howto-gobject.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
47 <td><a accesskey="u" href="howto-gobject.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
48 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
49 <th width="100%" align="center">GObject Reference Manual</th>
50 <td><a accesskey="n" href="howto-gobject-construction.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
51 </tr></table>
52 <div class="sect1" title="Boilerplate code">
53 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
54 <a name="howto-gobject-code"></a>Boilerplate code</h2></div></div></div>
55 <p>
56       In your code, the first step is to #include the needed headers: depending
57       on your header include strategy, this can be as simple as
58       <code class="literal">#include "maman-bar.h"</code> or as complicated as tens
59       of #include lines ending with <code class="literal">#include "maman-bar.h"</code>:
60 </p>
61 <pre class="programlisting">
62 /*
63  * Copyright information
64  */
65
66 #include "maman-bar.h"
67
68 /* If you use Pimpls, include the private structure 
69  * definition here. Some people create a maman-bar-private.h header
70  * which is included by the maman-bar.c file and which contains the
71  * definition for this private structure.
72  */
73 struct _MamanBarPrivate {
74   int member_1;
75   /* stuff */
76 };
77
78 /* 
79  * forward definitions
80  */
81 </pre>
82 <p>
83     </p>
84 <p>
85       Call the <code class="function">G_DEFINE_TYPE</code> macro using the name
86       of the type, the prefix of the functions and the parent GType to
87       reduce the amount of boilerplate needed. This macro will:
88
89       </p>
90 <div class="itemizedlist"><ul class="itemizedlist" type="disc">
91 <li class="listitem">implement the <code class="function">maman_bar_get_type</code>
92         function</li>
93 <li class="listitem">define a parent class pointer accessible from
94         the whole .c file</li>
95 </ul></div>
96 <p>
97
98 </p>
99 <pre class="programlisting">
100 G_DEFINE_TYPE (MamanBar, maman_bar, G_TYPE_OBJECT);
101 </pre>
102 <p>
103     </p>
104 <p>
105       It is also possible to use the
106       <code class="function">G_DEFINE_TYPE_WITH_CODE</code> macro to control the
107       get_type function implementation - for instance, to add a call to
108       <code class="function">G_IMPLEMENT_INTERFACE</code> macro which will
109       call the <code class="function">g_type_implement_interface</code> function.
110     </p>
111 </div>
112 <div class="footer">
113 <hr>
114           Generated by GTK-Doc V1.13</div>
115 </body>
116 </html>