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