]> git.draconx.ca Git - gob-dx.git/blob - examples/my-person.gob
Release 2.0.0
[gob-dx.git] / examples / my-person.gob
1 /*
2  * This file is a basic example of how a .gob file would be constructed,
3  * how to add data members, properties and methods
4  */
5 requires 2.0.0
6
7 %{
8 #include <time.h>
9 #include "my-person.h"
10 #include "my-person-private.h"
11 %}
12
13 class My:Person from G:Object {
14         /* the name of the person */
15         private char *name = {g_strdup(_("Nobody"))}
16                 destroywith g_free;
17         property STRING name
18                 (nick = _("Name"),
19                  blurb = _("Name of the person"),
20                  default_value = _("Nobody"),
21                  /* Export get/set functions for this property */
22                  export,
23                  /* link to the data memeber 'name' */
24                  link);
25
26         /* date of birth as a time_t */
27         private long dob = 0;
28         property LONG dob
29                 (nick = _("Date of birth"),
30                  blurb = _("Date of birth of the person"),
31                  minimum = 0,
32                  maximum = LONG_MAX,
33                  default_value = 0,
34                  export)
35                 /* We could use 'link' as above, but the code below
36                  * shows how to do this without linking */
37                 set {
38                         self->_priv->dob = g_value_get_long (VAL);
39                 }
40                 get {
41                         g_value_set_long (VAL, self->_priv->dob);
42                 };
43
44         /* date of death as a time_t */
45         private long dod = 0;
46         property LONG dod
47                 (nick = _("Date of death"),
48                  blurb = _("Date of death of the person"),
49                  minimum = 0,
50                  maximum = LONG_MAX,
51                  default_value = 0,
52                  export,
53                  link);
54
55         /* number of rounds in our shotgun */
56         private int rounds_in_shotgun = 0;
57
58         /* when the person gets born, sends out a signal, the caller
59            of the signal should provide the date of birth */
60         signal last NONE (LONG)
61         void
62         birth (self, long dob)
63         {
64                 g_object_set (G_OBJECT (self),
65                               "dob", dob);
66         }
67         
68         /* when the person dies, sends out a signal, the caller
69            of the signal should provide the date of death */
70         signal last NONE (LONG)
71         void
72         death (self, long dod)
73         {
74                 g_object_set (G_OBJECT (self),
75                               "dod", dod);
76         }
77
78         public
79         void
80         load_shotgun (self)
81         {
82                 /* add a round to our shotgun */
83                 self->_priv->rounds_in_shotgun++;
84         }
85
86         public
87         void
88         shoot_oneself_in_the_head (self)
89         {
90                 if (self->_priv->rounds_in_shotgun == 0) {
91                         g_warning (_("No rounds in the shotgun!"));
92                         return;
93                 }
94                 
95                 /* one round was fired */
96                 self->_priv->rounds_in_shotgun--;
97
98                 /* death is imminent if we shoot oneself in the head */
99                 death (self, (long)time (NULL));
100         }
101
102         public GObject *
103         new (void)
104         {
105                 return (GObject *)GET_NEW;
106         }
107 }