ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/HashDB.pm
(Generate patch)

Comparing COMP/SCRAM/src/Utilities/HashDB.pm (file contents):
Revision 1.5 by williamc, Thu Oct 21 16:37:50 1999 UTC vs.
Revision 1.7 by williamc, Tue Feb 8 13:59:20 2000 UTC

# Line 15 | Line 15
15   # items()                : return the number of seperate items in the store
16   # store(filename)        : dump to file
17   # restore(filename)      : restore from file
18 + # alias(\@refofkeys,\@aliaskeys) : attatch another set of keys to items that
19 + #                                  match the refopfkeys
20 + #                                  note that these are references to the arrays
21 + # unalias(@aliaskeys) :remove an alias
22  
23   package Utilities::HashDB;
24   use Utilities::DataItem;
# Line 37 | Line 41 | sub setdata {
41          push @{$self->{dataitems}}, Utilities::DataItem->new($data, @keys);
42   }
43  
44 + sub alias {
45 +        my $self=shift;
46 +        my $keyref=shift;
47 +        my $aliaskeys=shift;
48 +
49 +        my @objs=$self->match(@{$keyref});
50 +        foreach $obj ( @objs ) {
51 +          $obj->alias(@{$aliaskeys});
52 +        }
53 + }
54 +
55 + sub unalias {
56 +        my $self=shift;
57 +        my @keys=@_;
58 +
59 +        my @objs=$self->match(@keys);
60 +        foreach $obj ( @objs ) {
61 +          $obj->unalias(@_);
62 +        }
63 + }
64 +
65   sub items {
66          my $self=shift;
67          return $#{$self->{dataitems}};
# Line 83 | Line 108 | sub store {
108          my $filename=shift;
109  
110          my $fh=FileHandle->new();
111 +        $fh->autoflush(1);
112          open ($fh, ">$filename") or die "Unable to open file $filename\n $!\n";
113          foreach $object ( @{$self->{dataitems}} ) {
114 <          # print the keys first then the data item
115 <          foreach $key ( $object->keys() ) {
90 <            print $fh "#".$key."\n";
91 <          }
92 <          print $fh ">".$object->data()."\n";
114 >          print $fh "\n";
115 >          $object->store($fh);
116          }
117          close $fh;
118   }
# Line 103 | Line 126 | sub restore {
126          my $fh=FileHandle->new();
127          open ($fh, "<$filename") or die "Unable to open file $filename\n $!\n";
128          while ( <$fh> ) {
129 <          if ( $_=~/^#(.*)/ ) {
107 <            push @arr, $1;      
108 <          }
109 <          if ( $_=~/^>(.*)/ ) {
110 <            $data=$1;
111 <            if ( $#arr >= 0 ) {
112 <             $self->setdata($data,@arr);
113 <            }
114 <            undef @arr;
115 <          }
129 >          push @{$self->{dataitems}}, Utilities::DataItem->restore($fh);
130          }
131          close $fh;
132   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines