⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.83
Server IP:
157.245.101.34
Server:
Linux skvinfotech-website 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64
Server Software:
Apache/2.4.41 (Ubuntu)
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
doc
/
libpango1.0-doc
/
gobject
/
View File Name :
howto-gobject-code.html
<!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: GObject Reference Manual</title> <meta name="generator" content="DocBook XSL Stylesheets V1.79.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.32 (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="5"><tr valign="middle"> <td width="100%" align="left" class="shortcuts"></td> <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td> <td><a accesskey="u" href="howto-gobject.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td> <td><a accesskey="p" href="howto-gobject.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td> <td><a accesskey="n" href="howto-gobject-construction.html"><img src="right.png" width="16" height="16" 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 <code class="function">#include</code> the needed headers: </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15</pre></td> <td class="listing_code"><pre class="programlisting"><span class="cm">/*</span> <span class="cm"> * Copyright information</span> <span class="cm"> */</span> <span class="cp">#include</span> <span class="cpf">"viewer-file.h"</span><span class="cp"></span> <span class="cm">/* Private structure definition. */</span> <span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span> <span class="n">gchar</span> <span class="o">*</span><span class="n">filename</span><span class="p">;</span> <span class="cm">/* stuff */</span> <span class="p">}</span> <span class="n">ViewerFilePrivate</span><span class="p">;</span> <span class="cm">/* </span> <span class="cm"> * forward definitions</span> <span class="cm"> */</span></pre></td> </tr> </tbody> </table> </div> <p> </p> <p> If the class is being declared as final using <code class="function">G_DECLARE_FINAL_TYPE</code>, its instance structure should be defined in the C file: </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">struct</span> <span class="n">_ViewerFile</span> <span class="p">{</span> <span class="n">GObject</span> <span class="n">parent_instance</span><span class="p">;</span> <span class="cm">/* Other members, including private data. */</span> <span class="p">};</span></pre></td> </tr> </tbody> </table> </div> <p> </p> <p> Call the <code class="function">G_DEFINE_TYPE</code> macro (or <code class="function">G_DEFINE_TYPE_WITH_PRIVATE</code> if your class needs private data — final types do <span class="emphasis"><em>not</em></span> need private data) 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">viewer_file_get_type</code> function</li> <li class="listitem">define a parent class pointer accessible from the whole .c file</li> <li class="listitem">add private instance data to the type (if using <code class="function">G_DEFINE_TYPE_WITH_PRIVATE</code>)</li> </ul></div> <p> </p> <p> If the class has been declared as final using <code class="function">G_DECLARE_FINAL_TYPE</code> (see <a class="xref" href="howto-gobject.html#howto-gobject-header" title="Boilerplate header code">the section called “Boilerplate header code”</a>), private data should be placed in the instance structure, <span class="type">ViewerFile</span>, and <code class="function">G_DEFINE_TYPE</code> should be used instead of <code class="function">G_DEFINE_TYPE_WITH_PRIVATE</code>. The instance structure for a final class is not exposed publicly, and is not embedded in the instance structures of any derived classes (because the class is final); so its size can vary without causing incompatibilities for code which uses the class. Conversely, private data for derivable classes <span class="emphasis"><em>must</em></span> be included in a private structure, and <code class="function">G_DEFINE_TYPE_WITH_PRIVATE</code> must be used. </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1</pre></td> <td class="listing_code"><pre class="programlisting"><span class="n">G_DEFINE_TYPE</span> <span class="p">(</span><span class="n">ViewerFile</span><span class="p">,</span> <span class="n">viewer_file</span><span class="p">,</span> <span class="n">G_TYPE_OBJECT</span><span class="p">)</span></pre></td> </tr> </tbody> </table> </div> <p> or </p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1</pre></td> <td class="listing_code"><pre class="programlisting"><span class="n">G_DEFINE_TYPE_WITH_PRIVATE</span> <span class="p">(</span><span class="n">ViewerFile</span><span class="p">,</span> <span class="n">viewer_file</span><span class="p">,</span> <span class="n">G_TYPE_OBJECT</span><span class="p">)</span></pre></td> </tr> </tbody> </table> </div> <p> </p> <p> It is also possible to use the <code class="function">G_DEFINE_TYPE_WITH_CODE</code> macro to control the <code class="function">get_type</code> function implementation — for instance, to add a call to the <code class="function">G_IMPLEMENT_INTERFACE</code> macro to implement an interface. </p> </div> <div class="footer"> <hr>Generated by GTK-Doc V1.32</div> </body> </html>