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.4 by williamc, Thu Oct 21 09:59:44 1999 UTC vs.
Revision 1.7.4.1 by williamc, Fri Aug 4 08:27:56 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 <          my $temp=join '::', $object->keys();
115 <          $temp=$object->data()."::".$temp;
90 <          print $fh $temp."\n";
114 >          print $fh "\n";
115 >          $object->store($fh);
116          }
117          close $fh;
118   }
# Line 95 | Line 120 | sub store {
120   sub restore {
121          my $self=shift;
122          my $filename=shift;
123 <        my @arr;
123 >        my @arr=();
124 >        my $data;
125  
126          my $fh=FileHandle->new();
127          open ($fh, "<$filename") or die "Unable to open file $filename\n $!\n";
128          while ( <$fh> ) {
129 <          next if /^#/;
104 <          @arr=split ':', $_;  
105 <          $self->setdata(@arr);
129 >          push @{$self->{dataitems}}, Utilities::DataItem->restore($fh);
130          }
131          close $fh;
132   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines