Text::Editor::Vip::Buffer::List - lines container


Text-Editor-Vip documentation Contained in the Text-Editor-Vip distribution.

Index


Code Index:

NAME

Top

Text::Editor::Vip::Buffer::List - lines container

SYNOPSIS

Top

  use Text::Editor::Vip::Buffer::List

DESCRIPTION

Top

Container class used by Text::Editor::Vip::Buffer to hold the buffers text. Elements aer accessed by index.

MEMBER FUNCTIONS

Top

new

Create an empty container. Takes no arguments.

GetNumberOfNodes

Returns the number of contained elements.

Push

Adds an element at the end of the the container. Returns it's index.

GetNodeData

Returns an element or undef if the element doesn't exist.

  $list = new Text::Editor::Vip::Buffer::List() ;
  $list->Push(['some_element']) ;
  my $element = $list->GetNodeData(0) ;

SetNodeData

Sets the element at the given index. The element must exist.

  my $index = 0 ;
  my $element = [] ;
  $list->SetNodeData($index, $element) ;

DeleteNode

Removes the lement at the given index. all elements after the given index are shifted up in the list. The element must exist.

  $list->DeleteNode($index) ;

InsertAfter

Creates and inserts an element in the list after the given index. The element at the given index must exist.

  $list->InsertAfter($index, $element_data) ;

InsertBefore

Creates and inserts an element in the list before the given index. The element at the given index must exist.

  $list->InsertBefore($index, $element_data) ;

AUTHOR

Top

	Khemir Nadim ibn Hamouda
	CPAN ID: NKH
	mailto:nadim@khemir.net
	http:// no web site

COPYRIGHT

Top


Text-Editor-Vip documentation Contained in the Text-Editor-Vip distribution.
package Text::Editor::Vip::Buffer::List;

use strict;
use warnings ;
use Carp qw(cluck) ;

BEGIN 
{
use Exporter ();
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION     = 0.01;
@ISA         = qw (Exporter);
@EXPORT      = qw ();
@EXPORT_OK   = qw ();
%EXPORT_TAGS = ();
}

#-------------------------------------------------------------------------------

sub new
{

my $invocant = shift ;
my $class = ref($invocant) || $invocant ;

return( bless [], $class );
}

#-------------------------------------------------------------------------------

sub GetNumberOfNodes
{

return(scalar(@{$_[0]})) ;
}

#-------------------------------------------------------------------------------

sub Push
{

push @{$_[0]}, $_[1] ;
return($#{$_[0]}) ;
}

#-------------------------------------------------------------------------------

sub GetNodeData
{

my $this         = shift ;
my $a_node_index = shift ;

if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
	{
	return($this->[$a_node_index]) ;
	}
else
	{
	cluck("$a_node_index is an invalide node index") ;
	return(undef) ;
	}
}

#-------------------------------------------------------------------------------

sub SetNodeData
{

my $this         = shift ;
my $a_node_index = shift ;
my $a_node_data  = shift ;

if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
	{
	$this->[$a_node_index] = $a_node_data ;
	}
else
	{
	cluck("$a_node_index is an invalide node index") ;
	return(undef) ;
	}

}

#-------------------------------------------------------------------------------

sub DeleteNode
{

my $this         = shift ;
my $a_node_index = shift ;

if(0 != $this->GetNumberOfNodes())
	{
	if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
		{
		splice 
			(
			@{$this}
			, $a_node_index
			, 1
			) ;
		}
	else
		{
		cluck("$a_node_index is an invalide node index") ;
		}
	}
else
	{
	cluck('List is empty, nothing to delete !!') ;
	}
}

#-------------------------------------------------------------------------------

sub InsertAfter
{

my $this         = shift ;
my $a_node_index = shift ;
my $a_node_data  = shift ;

if(0 != $this->GetNumberOfNodes())
	{
	if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
		{
		splice 
			(
			@{$this}
			, $a_node_index + 1
			, 0
			, $a_node_data
			) ;
			
		return($a_node_index + 1) ;
		}
	else
		{
		cluck("$a_node_index is an invalide node index") ;
		}
	}
else
	{
	cluck('List is empty !!') ;
	}
}

#-------------------------------------------------------------------------------

sub InsertBefore
{

my ($this, $a_node_index, $a_node_data) = @_ ;

if(0 != $this->GetNumberOfNodes())
	{
	if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
		{
		if(0 == $a_node_index)
			{
			unshift @{$this}, $a_node_data ;
			}
		else
			{
			splice 
				(
				@{$this}
				, $a_node_index
				, 0
				, $a_node_data
				) ;
				
			return($a_node_index) ;
			}
		}
	else
		{
		cluck("$a_node_index is an invalide node index") ;
		}
	}
else
	{
	cluck('List is empty !!') ;
	}
}

#-------------------------------------------------------------------------------

1;