]> git.draconx.ca Git - gob-dx.git/blob - examples/my-person.gob
Release 0.92.4
[gob-dx.git] / examples / my-person.gob
1 require 0.92.1
2
3 %{
4 #include <time.h>
5 #include "my-person.h"
6 #include "my-person-private.h"
7 %}
8
9 class My:Person from Gtk:Object {
10         public char *name;
11         public long dob; /* date of birth as a time_t */
12         public long dod; /* date of death as a time_t */
13
14         private int rounds_in_shotgun; /* number of rounds in our shotgun */
15
16         argument POINTER (type char *) name
17         get {
18                 if(self->name)
19                         ARG = g_strdup(self->name);
20                 else
21                         ARG = NULL;
22         }
23         set {
24                 g_free(self->name);
25                 if(ARG)
26                         self->name = g_strdup(ARG);
27                 else
28                         self->name = NULL;
29         };
30
31         argument LONG dob get { ARG = self->dob; } set { self->dob = ARG; };
32         argument LONG dod get { ARG = self->dod; } set { self->dod = ARG; };
33
34         init(self)
35         {
36                 self->name = g_strdup("Nobody");
37                 self->dob = 0;
38                 self->dod = 0;
39                 
40                 /* initially we have no rounds in the shotgun */
41                 self->_priv->rounds_in_shotgun = 0;
42         }
43
44         /* when the person gets born, sends out a signal, the caller
45            of the signal should provide the date of birth */
46         signal last NONE (LONG)
47         void
48         birth(self, long dob)
49         {
50                 self->dob = dob;
51         }
52         
53         /* when the person dies, sends out a signal, the caller
54            of the signal should provide the date of death */
55         signal last NONE (LONG)
56         void
57         death(self, long dod)
58         {
59                 self->dod = dod;
60         }
61
62         public
63         void
64         load_shotgun(self)
65         {
66                 /* add a round to our shotgun */
67                 self->_priv->rounds_in_shotgun++;
68         }
69
70         public
71         void
72         shoot_oneself_in_the_head(self)
73         {
74                 if(self->_priv->rounds_in_shotgun==0) {
75                         g_warning("No rounds in the shotgun!");
76                         return;
77                 }
78                 
79                 /* one round was fired */
80                 self->_priv->rounds_in_shotgun--;
81
82                 /* death is imminent if we shoot oneself in the head */
83                 death(self,(long)time(NULL));
84         }
85 }