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.6 by williamc, Tue Feb 8 13:53:22 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 +        print "$obj @_\n";
52 +          $obj->alias(@{$aliaskeys});
53 +        }
54 + }
55 +
56 + sub unalias {
57 +        my $self=shift;
58 +        my @keys=@_;
59 +
60 +        my @objs=$self->match(@keys);
61 +        foreach $obj ( @objs ) {
62 +          $obj->unalias(@_);
63 +        }
64 + }
65 +
66   sub items {
67          my $self=shift;
68          return $#{$self->{dataitems}};
# Line 83 | Line 109 | sub store {
109          my $filename=shift;
110  
111          my $fh=FileHandle->new();
112 +        $fh->autoflush(1);
113          open ($fh, ">$filename") or die "Unable to open file $filename\n $!\n";
114          foreach $object ( @{$self->{dataitems}} ) {
115 <          # print the keys first then the data item
116 <          foreach $key ( $object->keys() ) {
90 <            print $fh "#".$key."\n";
91 <          }
92 <          print $fh ">".$object->data()."\n";
115 >          print $fh "\n";
116 >          $object->store($fh);
117          }
118          close $fh;
119   }
# Line 103 | Line 127 | sub restore {
127          my $fh=FileHandle->new();
128          open ($fh, "<$filename") or die "Unable to open file $filename\n $!\n";
129          while ( <$fh> ) {
130 <          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 <          }
130 >          push @{$self->{dataitems}}, Utilities::DataItem->restore($fh);
131          }
132          close $fh;
133   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines