Blame docs/reference/gobject/html/howto-gobject-code.html

Packit ae235b
Packit ae235b
<html>
Packit ae235b
<head>
Packit ae235b
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Packit ae235b
<title>Boilerplate code: GObject Reference Manual</title>
Packit ae235b
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
Packit ae235b
<link rel="home" href="index.html" title="GObject Reference Manual">
Packit ae235b
<link rel="up" href="howto-gobject.html" title="How to define and implement a new GObject">
Packit ae235b
<link rel="prev" href="howto-gobject.html" title="How to define and implement a new GObject">
Packit ae235b
<link rel="next" href="howto-gobject-construction.html" title="Object construction">
Packit ae235b
<meta name="generator" content="GTK-Doc V1.27 (XML mode)">
Packit ae235b
<link rel="stylesheet" href="style.css" type="text/css">
Packit ae235b
</head>
Packit ae235b
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
Packit ae235b
Packit ae235b
Packit ae235b
Home
Packit ae235b
Up
Packit ae235b
Prev
Packit ae235b
Next
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
Boilerplate code
Packit ae235b

Packit ae235b
      In your code, the first step is to #include the
Packit ae235b
      needed headers:
Packit ae235b

Packit ae235b
Packit ae235b
  
Packit ae235b
    
Packit ae235b
      
Packit ae235b
        
1
Packit ae235b
2
Packit ae235b
3
Packit ae235b
4
Packit ae235b
5
Packit ae235b
6
Packit ae235b
7
Packit ae235b
8
Packit ae235b
9
Packit ae235b
10
Packit ae235b
11
Packit ae235b
12
Packit ae235b
13
Packit ae235b
14
Packit ae235b
15
Packit ae235b
        
/*
Packit ae235b
 * Copyright information
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "viewer-file.h"
Packit ae235b
Packit ae235b
/* Private structure definition. */
Packit ae235b
typedef struct {
Packit ae235b
  gchar *filename;
Packit ae235b
  /* stuff */
Packit ae235b
} ViewerFilePrivate;
Packit ae235b
Packit ae235b
/* 
Packit ae235b
 * forward definitions
Packit ae235b
 */
Packit ae235b
      
Packit ae235b
    
Packit ae235b
  
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
    

Packit ae235b

Packit ae235b
      If the class is being declared as final using
Packit ae235b
      G_DECLARE_FINAL_TYPE, its instance structure should
Packit ae235b
      be defined in the C file:
Packit ae235b

Packit ae235b
Packit ae235b
  
Packit ae235b
    
Packit ae235b
      
Packit ae235b
        
1
Packit ae235b
2
Packit ae235b
3
Packit ae235b
4
Packit ae235b
5
Packit ae235b
6
Packit ae235b
        
struct _ViewerFile
Packit ae235b
{
Packit ae235b
  GObject parent_instance;
Packit ae235b
Packit ae235b
  /* Other members, including private data. */
Packit ae235b
}
Packit ae235b
      
Packit ae235b
    
Packit ae235b
  
Packit ae235b
Packit ae235b
Packit ae235b

Packit ae235b
    

Packit ae235b

Packit ae235b
      Call the G_DEFINE_TYPE macro (or
Packit ae235b
      G_DEFINE_TYPE_WITH_PRIVATE if your class needs
Packit ae235b
      private data — final types do not need private data)
Packit ae235b
      using the name
Packit ae235b
      of the type, the prefix of the functions and the parent GType to
Packit ae235b
      reduce the amount of boilerplate needed. This macro will:
Packit ae235b
Packit ae235b
      

Packit ae235b
    Packit ae235b
  • implement the viewer_file_get_type
  • Packit ae235b
            function
    Packit ae235b
  • define a parent class pointer accessible from
  • Packit ae235b
            the whole .c file
    Packit ae235b
  • add private instance data to the type (if using
  • Packit ae235b
            G_DEFINE_TYPE_WITH_PRIVATE)
    Packit ae235b
    Packit ae235b

    Packit ae235b
        

    Packit ae235b

    Packit ae235b
          If the class has been declared as final using
    Packit ae235b
          G_DECLARE_FINAL_TYPE (see
    Packit ae235b
          the section called “Boilerplate header code”), private data should be placed in
    Packit ae235b
          the instance structure, ViewerFile, and
    Packit ae235b
          G_DEFINE_TYPE should be used instead of
    Packit ae235b
          G_DEFINE_TYPE_WITH_PRIVATE. The instance structure
    Packit ae235b
          for a final class is not exposed publicly, and is not embedded in the
    Packit ae235b
          instance structures of any derived classes (because the class is final);
    Packit ae235b
          so its size can vary without causing incompatibilities for code which uses
    Packit ae235b
          the class. Conversely, private data for derivable classes
    Packit ae235b
          must be included in a private structure, and
    Packit ae235b
          G_DEFINE_TYPE_WITH_PRIVATE must be used.
    Packit ae235b
    Packit ae235b

    Packit ae235b
    Packit ae235b
      
    Packit ae235b
        
    Packit ae235b
          
    Packit ae235b
            
    1
    Packit ae235b
            
    G_DEFINE_TYPE (ViewerFile, viewer_file, G_TYPE_OBJECT)
    Packit ae235b
          
    Packit ae235b
        
    Packit ae235b
      
    Packit ae235b
    Packit ae235b
    Packit ae235b

    Packit ae235b
    or
    Packit ae235b

    Packit ae235b
    Packit ae235b
      
    Packit ae235b
        
    Packit ae235b
          
    Packit ae235b
            
    1
    Packit ae235b
            
    G_DEFINE_TYPE_WITH_PRIVATE (ViewerFile, viewer_file, G_TYPE_OBJECT)
    Packit ae235b
          
    Packit ae235b
        
    Packit ae235b
      
    Packit ae235b
    Packit ae235b
    Packit ae235b

    Packit ae235b
        

    Packit ae235b

    Packit ae235b
          It is also possible to use the
    Packit ae235b
          G_DEFINE_TYPE_WITH_CODE macro to control the
    Packit ae235b
          get_type function implementation — for instance, to
    Packit ae235b
          add a call to the G_IMPLEMENT_INTERFACE macro to
    Packit ae235b
          implement an interface.
    Packit ae235b
        

    Packit ae235b
    Packit ae235b
    Packit ae235b

    Generated by GTK-Doc V1.27
    Packit ae235b
    </body>
    Packit ae235b
    </html>