NAME

Bit::Vector::Named - Named bit vectors

DESCRIPTION

Allows user-defined labels to be used to describe bit vectors. Derived from Bit::Vector.

SYNOPSIS

use Bit::Vector::Named;
my $labels = {
	'read' => 1,
	'write' => 2,
	'execute' => 4,
	'rw' => 3,
	'all4' => 15,
};
my $vector = new Bit::Vector::Named(size => 8, labels => $labels);

$vector->set('all4');
unless($vector->has('rw')) { print "bizzare vector math!" }

METHODS

new
my $labels = {
	'read' => 1,
	'write' => 2,
	'execute' => 4,
	'rw' => 3,
	'all4' => 15,
};
my $vector = new Bit::Vector::Named(size=>16, labels => $labels, value => 127);

Creates a new bit vector of size size. The 'labels' argument takes a 
reference to a hash of names and corresponding values, which are then 
used as aliases for those values. Size is rounded up to a multiple of 8.
The initial value is set to the value of the value key or to 0 by default.
set
$vector->set('rw');

Sets the vector bits corresponding to those set in the named argument. 
If the argument is not a label hash key, assumes the argument is a numeric
decimal literal and passes it to the underlying Bit::Vector.
clear
$vector->clear('read');

Clears the vector bits corresponding to those set in the named argument.
If the argument is not a label hash key, assumes the argument is a numeric
decimal literal and passes it to the underlying Bit::Vector.
is
if( $vector->is('w') ) { print "The vector equals 2." }

Returns true if the vector equals the value of the label argument.
If the argument is not a label hash key, assumes the argument is a numeric
decimal literal and passes it to the underlying Bit::Vector.
has
unless($vector->has('r') { print "Vector 1 bit not set." }

Returns true if the vector contians the bit pattern given by the argument.
If the argument is not a label hash key, assumes the argument is a numeric
decimal literal and passes it to the underlying Bit::Vector.
equal
if($vec1->equal($vec2)) { do_stuff() }

Returns true if $vec1 is equal to $vec2
Clone
my $vec2 = $vector->Clone();

Copying constructor.
to_Hash
print join(' ', keys $vector->to_Hash);

Returns a reference to a hash of label => value pairs corresponding to bits 
which are set in the vector, ONLY IF they have corresponding labels in the 
labels assigned in the object constructor. 

See also Bit::Vector->as_Enum, which can print all bits in the vector, 
eg. print $vector->as_Enum
label_hash
my $href = $vector->label_hash;

$vector->label_hash($labels);

Gets or sets a reference to the hash label list used by the object.
Other methods

Functionally, if not via the usual mechanisms, this class is derived from Bit::Vector. The package will therefore pass method calls it does not overload to the base class for processing. This means a bad function call may die as a call to Bit::Vector, with error messages from that package.

SEE ALSO

Bit::Vector

AUTHOR

William Herrera (wherrera@skylightview.com)

SUPPORT

Questions, feature requests and bug reports should go to wherrera@skylightview.com

COPYRIGHT

Copyright (C) 2004 William Hererra.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.