Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-release > by-pkgid > baa1b6b975b415d3262338338273c075 > files > 20

gob2-2.0.20-3.mga5.i586.rpm

/*
 * This file is a basic example of how a .gob file would be constructed,
 * how to add data members, properties and methods
 */
requires 2.0.0

%{
#include <time.h>
#include "my-person.h"
#include "my-person-private.h"
%}

class My:Person from G:Object {
	/* the name of the person */
	private char *name = {g_strdup("Nobody")}
		destroywith g_free;
	property STRING name
		(nick = "Name",
		 blurb = "Name of the person",
		 default_value = "Nobody",
		 /* Export get/set functions for this property */
		 export,
		 /* link to the data memeber 'name' */
		 link);

	/* date of birth as a time_t */
	private long dob = 0;
	property LONG dob
		(nick = "Date of birth",
		 blurb = "Date of birth of the person",
		 minimum = 0,
		 maximum = LONG_MAX,
		 default_value = 0,
		 export)
		/* We could use 'link' as above, but the code below
		 * shows how to do this without linking */
		set {
			self->_priv->dob = g_value_get_long (VAL);
		}
		get {
			g_value_set_long (VAL, self->_priv->dob);
		};

	/* date of death as a time_t */
	private long dod = 0;
	property LONG dod
		(nick = "Date of death",
		 blurb = "Date of death of the person",
		 minimum = 0,
		 maximum = LONG_MAX,
		 default_value = 0,
		 export,
		 link);

	/* number of rounds in our shotgun */
	private int rounds_in_shotgun = 0;

	/* when the person gets born, sends out a signal, the caller
	   of the signal should provide the date of birth */
	signal last NONE (LONG)
	void
	birth (self, long dob)
	{
		g_object_set (G_OBJECT (self),
			      "dob", dob,
			      NULL);
	}
	
	/* when the person dies, sends out a signal, the caller
	   of the signal should provide the date of death */
	signal last NONE (LONG)
	void
	death (self, long dod)
	{
		g_object_set (G_OBJECT (self),
			      "dod", dod,
			      NULL);
	}

	public
	void
	load_shotgun (self)
	{
		/* add a round to our shotgun */
		self->_priv->rounds_in_shotgun++;
	}

	public
	void
	shoot_oneself_in_the_head (self)
	{
		if (self->_priv->rounds_in_shotgun == 0) {
			g_warning ("No rounds in the shotgun!");
			return;
		}
		
		/* one round was fired */
		self->_priv->rounds_in_shotgun--;

		/* death is imminent if we shoot oneself in the head */
		self_death (self, (long)time (NULL));
	}

	public GObject *
	new (void)
	{
		return (GObject *)GET_NEW;
	}
}