Solstice::Model::List - Superclass for classes that need to be both a List and a Model.


Solstice documentation Contained in the Solstice distribution.

Index


Code Index:

NAME

Top

Solstice::Model::List - Superclass for classes that need to be both a List and a Model.

SYNOPSIS

Top

    use Solstice::Model::List;; 

    my $model = Solstice::Model::List->new();

DESCRIPTION

Top

Export

None by default.

Methods

new ()

Creates and returns an empty Solstice::Model::List object.

clear()

Removes all entries from the List object.

reverse()

Reverse the order of the entries in the List.

push($element)

Adds an element to the end of the List.

pop()

Remove the last element in the List and return it.

unshift($element)

Adds an element to the front of the List.

shift()

Remove the first element in the List and return it.

add ([$index,] $element)

Adds an element to the List. If no index is given it will be added to the end of the List, otherwise it will be placed at the index given, and the other elements will be shifted out of the way. Passing $index equal to the list size is also permissible. It is 0 indexed.

addList($list)
replace($index, $element)

Replace an element in the List. It is 0 indexed. If successful, the replaced element is returned.

move ($oldindex, $newindex)

This will move an element from one position in the List to another. It is 0 indexed. Note: This will not reset any iterators, so there may be some confusion if you iterate over a List you are still manipulating.

onMove
remove ($index)

This will remove an element from the List, at the index given. It is 0 indexed. If successful, the removed element is returned.

onRemove

This is an empty method meant for overriding by subclasses

Private Methods

_clear()
_add([$position,] $element)
_addList($list)
_listChanged()

AUTHOR

Top

Catalyst Research & Development Group, <catalyst@u.washington.edu>

VERSION

Top

$Revision: 83 $

COPYRIGHT

Top


Solstice documentation Contained in the Solstice distribution.
package Solstice::Model::List;

# $Id: List.pm 83 2006-03-14 06:51:35Z jlaney $

use strict;
use warnings;
use 5.006_000;

use base qw( Solstice::Model Solstice::List );

our ($VERSION) = ('$Revision: 2065 $' =~ /^\$Revision:\s*([\d.]*)/);

use constant TRUE    => 1;
use constant FALSE   => 0;
use constant SUCCESS => 1;
use constant FAIL    => 0;

sub new {
    my ($class) = @_;
    
    my $self = $class->SUPER::new();
    $self->_clear();

    return $self;
}

sub clear {
    my ($self) = @_;
    $self->_listRead();
    $self->_listChanged();
    return $self->Solstice::List::clear();
}

sub reverse {
    my ($self) = @_;
    $self->_listRead();
    $self->_listChanged();
    return $self->Solstice::List::reverse();
}

sub push {
    my ($self, $element) = @_;
    $self->_listRead();
    $self->_listChanged();
    return $self->Solstice::List::push($element);
}

sub pop {
    my ($self) = @_;
    $self->_listRead();
    $self->_listChanged();
    return $self->Solstice::List::pop();
}

sub unshift {
    my ($self, $element) = @_;
    $self->_listRead();
    $self->_listChanged();
    return $self->Solstice::List::unshift($element);
}

sub shift {
    my ($self) = @_;
    $self->_listRead();
    $self->_listChanged();
    return $self->Solstice::List::shift();
}

sub add {
    my $self = CORE::shift;
    $self->_listRead();
    $self->onAdd();
    my $status = $self->Solstice::List::add(@_);
    $self->_listChanged() if $status;
    return $status;
}

sub onAdd {
    return TRUE;
}

sub addList {
    my $self = CORE::shift;
    $self->_listRead();
    my $status = $self->Solstice::List::addList(@_);
    $self->_listChanged() if $status;
    return $status;
}

sub replace {
    my ($self, $index, $element) = @_;
    $self->_listRead();
    $self->onReplace();
    my $return = $self->Solstice::List::replace($index, $element);
    $self->_listChanged();
    return $return;
}

sub onReplace {
    return TRUE;
}

sub exists {
    my ($self, $index) = @_;
    $self->_listRead();
    return $self->Solstice::List::exists($index);
}


sub get {
    my ($self, $index) = @_;
    $self->_listRead();
    return $self->Solstice::List::get($index);
}

sub getAll {
    my ($self) = @_;
    $self->_listRead();
    return $self->Solstice::List::getAll();
}


sub isEmpty {
    my ($self) = @_;
    $self->_listRead();
    return $self->Solstice::List::isEmpty();
}

sub size {
    my ($self) = @_;
    $self->_listRead();
    return $self->Solstice::List::size();
}

sub iterator {
    my ($self) = @_;
    $self->_listRead();
    return $self->Solstice::List::iterator();
}

sub move {
    my ($self, $oldindex, $newindex) = @_;
    $self->_listRead();
    $self->onMove();
    my $status = $self->Solstice::List::move($oldindex, $newindex);
    $self->_listChanged() if $status;
    return $status;
}
sub onMove {
    return TRUE;
}    
sub remove {
    my ($self, $index) = @_;
    $self->_listRead();
    $self->onRemove($index);
    my $return = $self->Solstice::List::remove($index);
    $self->_listChanged();
    return $return; 
}

sub onRemove {
    return TRUE;
}

sub _clear {
    my $self = CORE::shift;
    return $self->Solstice::List::clear();
}

sub _add {
    my $self = CORE::shift;
    return $self->Solstice::List::add(@_);
}

sub _addList {
    my $self = CORE::shift;
    return $self->Solstice::List::addList(@_);
}

sub _listChanged {
    my $self = CORE::shift;
    $self->_taint();
}

sub _listRead {
    #override me!
}


1;

__END__