#!/usr/bin/perl -w
#
# $Id: EventGroup.pm,v 1.2 2002/03/14 15:02:25 fpmip Exp $
#
# EventGroup object (a number of Events)
#
# Author : Tycho Fruru <tycho@fruru.com>
#
# Copyright (C) 2001 Tycho Fruru <tycho@fruru.com>
# Copyright (C) 2001 Conostix S.A. Luxembourg - Tycho Fruru <tycho@conostix.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
package IPFC::EventGroup;

use strict;
use warnings;

use Storable;

sub new() {
	my $proto = shift;
	my $class = ref($proto) || $proto;
	my $self = {};
	bless ($self,$class);
	return $self;
}

sub clone() {
	my $self = shift;
	my $class = ref($self);
	my $new;
	
	$new = Storable::dclone($self);
	
	bless ($new,$class);
	return $new;
}

sub add_event($) {
	my $self = shift;
	my $event = shift; # an IPFC::Event
	if ($event->isa("IPFC::Event")) {
		push @{$self->{"event"}} , $event;
		return 1;
	} else {
		warn "The object was not an IPFC::Event !";
		return 0;
	}
}

sub add_eventgroup($) {
	my $self = shift;
	my $eventgroup = shift; # an IPFC::Eventgroup
	if ($eventgroup->isa("IPFC::EventGroup")) {
		push @{$self->{"event"}}, @{$eventgroup->{"event"}};
		return 1;
	} else {
		warn "The object was not an IPFC::Eventgroup !";
		return 0;
	}
}

sub count_events() {
	my $self = shift;
	return ( $#{$self->{"event"}} + 1 );
}

sub get_all_events($) {
	my $self = shift;
	return ( $self->{"event"} );
}

sub get_event($) {
# takes as parameter the number of the event in the EventGroup (starting from 0) - this has nothing to do with the event's event_id
	my $self = shift;
	my $i = shift;
	return ( $self->{"event"}->[$i] );
}

return 1;
