Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > by-pkgid > 13aa745fa82315981ff58c83c7af0f46 > files > 19

gob-1.0.12-1mdk.i586.rpm

requires 0.93.0

/* this file requires 0.93.0 as it uses some of the new features to reduce
 * typing and generally make it easier to read I think.  Of course they're
 * optional to use so use the my-person.gob as an example of not using them.
 * These include data member initialization, automatic destructor calling
 * and automatic argument<->data member linking */

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

class My:Person2 from Gtk:Object {
	/* the name of the person */
	public char *name = {g_strdup("Nobody")}
		destroywith g_free;
	argument POINTER name stringlink;

	/* date of birth as a time_t */
	public long dob = 0;
	argument LONG dob link;

	/* date of death as a time_t */
	public long dod = 0;
	argument LONG dod 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)
	{
		self->dob = dob;
	}
	
	/* 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)
	{
		self->dod = dod;
	}

	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 */
		death(self, (long)time(NULL));
	}

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