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);
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.
- 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 constuctor.
- Other methods
-
Functionally, if not via the usual mechanisms, this class is a 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
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.