| 1 | =head1 LICENSE | ||
| 2 | |||
| 3 | See the NOTICE file distributed with this work for additional information | ||
| 4 | regarding copyright ownership. | ||
| 5 | |||
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 7 | you may not use this file except in compliance with the License. | ||
| 8 | You may obtain a copy of the License at | ||
| 9 | |||
| 10 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 11 | |||
| 12 | Unless required by applicable law or agreed to in writing, software | ||
| 13 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 15 | See the License for the specific language governing permissions and | ||
| 16 | limitations under the License. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | |||
| 21 | =head1 CONTACT | ||
| 22 | |||
| 23 | Please email comments or questions to the public Ensembl | ||
| 24 | developers list at <http://lists.ensembl.org/mailman/listinfo/dev>. | ||
| 25 | |||
| 26 | Questions may also be sent to the Ensembl help desk at | ||
| 27 | <http://www.ensembl.org/Help/Contact>. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | =head1 NAME | ||
| 32 | |||
| 33 | Bio::EnsEMBL::Utils::BitString - bitstring object implementation | ||
| 34 | |||
| 35 | =head1 DESCRIPTION | ||
| 36 | |||
| 37 | This is an implementation of a bitstring object, taken from Damian | ||
| 38 | Convey's book "Object Oriented Perl". | ||
| 39 | |||
| 40 | =head1 METHODS | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | |||
| 45 | package Bio::EnsEMBL::Utils::BitString; | ||
| 46 | $Bio::EnsEMBL::Utils::BitString::VERSION = '114.0.0'; | ||
| 47 | use strict; | ||
| 48 | use warnings; | ||
| 49 | no warnings 'uninitialized'; | ||
| 50 | |||
| 51 | |||
| 52 | sub new { | ||
| 53 | my $class = ref($_[0])||$_[0]; | ||
| 54 | my $initbits = join '', map {$_?1:0} @_[1..$#_]; | ||
| 55 | my $bs = pack 'b*', $initbits; | ||
| 56 | bless \$bs, $class; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | sub get { | ||
| 61 | my ($self, $bitnum) = @_; | ||
| 62 | return vec($$self,$bitnum,1); | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | sub set { | ||
| 67 | my ($self, $bitnum, $newval) = @_; | ||
| 68 | vec($$self,$bitnum,1) = $newval?1:0; | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | sub bitcount { | ||
| 73 | 8 * length ${$_[0]}; | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | sub complement { | ||
| 78 | my ($self) = @_; | ||
| 79 | my $complement = ~$$self; | ||
| 80 | bless \$complement, ref($self); | ||
| 81 | } | ||
| 82 | |||
| 83 | |||
| 84 | sub print_me { | ||
| 85 | my ($self) = @_; | ||
| 86 | for (my $i=0; $i < $self->bitcount(); $i++) | ||
| 87 | { | ||
| 88 | print $self->get($i); | ||
| 89 | print ' ' unless ($i+1)%8; | ||
| 90 | print "\n" unless ($i+1)%64; | ||
| 91 | } | ||
| 92 | print "\n"; | ||
| 93 | } | ||
| 94 | |||
| 95 | |||
| 96 | 1; | ||
| 97 |