ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ObjectUtilities/StorableObject.pm
Revision: 1.7
Committed: Fri Jan 21 09:59:50 2000 UTC (25 years, 3 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.6: +5 -5 lines
Log Message:
new store faclilities added

File Contents

# User Rev Content
1 williamc 1.1 #
2     # StorableObject.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     #
8     # Interface
9     # ---------
10     # new(ObjectStore) : A new object
11     # openfile(filename) : return a filhandle object opened on the file filename
12     # ObjectStore() : Get/Set ObjectStore object
13     # sequencenumber() : return the sequence number
14 williamc 1.2 # meta() : return a descriptive string of the object
15     # store(location)
16     # restore(location)
17 williamc 1.3 # savevar(fh,name,value) : save a var to a fielhandle
18 williamc 1.7 # restorevars(fh, hashref) : restore variables form a filehandle into
19     # the supplied hash
20 williamc 1.1
21     package ObjectUtilities::StorableObject;
22     require 5.004;
23    
24     sub new {
25     my $class=shift;
26     my $Os=shift;
27     $self={};
28     bless $self, $class;
29     $self->{ObjectStore}=$Os;
30     $self->_init();
31     return $self;
32     }
33    
34     sub openfile {
35     my $self=shift;
36     my $filename=shift;
37    
38     local $fh=FileHandle->new();
39     open ( $fh, $filename) or die "Unable to open $filename\n $!\n";
40     return $fh;
41     }
42    
43     sub ObjectStore {
44     my $self=shift;
45     @_ ? $self->{ObjectStore}=shift
46     : $self->{ObjectStore};
47     }
48    
49     sub _init {
50     # dummy - override
51 williamc 1.2 }
52    
53     sub store {
54     print "Store Dummy not overridden"
55     }
56    
57     sub restore {
58     print "restore Dummy not overridden"
59     }
60    
61     sub meta {
62     my $self=shift;
63    
64     # by default just the class type
65     return ref($self);
66 williamc 1.1 }
67 williamc 1.3
68     sub savevar {
69     my $self=shift;
70     my $fh=shift;
71     my $name=shift;
72     my $val=shift;
73 williamc 1.4 print $fh "#".$name."\n";
74 williamc 1.3 print $fh $val."\n";
75     }
76    
77     sub restorevars {
78 williamc 1.5 my $self=shift;
79 williamc 1.3 my $fh=shift;
80 williamc 1.7 my $varhash=shift;
81 williamc 1.3
82 williamc 1.7 print $varhash;
83 williamc 1.6 while ( <$fh>=~/^#(.*)/ ) {
84     $name=$1;
85 williamc 1.3 chomp $name;
86 williamc 1.4 $value=<$fh>;
87 williamc 1.3 chomp $value;
88 williamc 1.7 $$varhash{$name}=$value;
89 williamc 1.6 #print "Restoring ".$name."=".$value."\n";
90 williamc 1.3 }
91     }
92