ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ObjectUtilities/StorableObject.pm
Revision: 1.4
Committed: Fri Jan 21 09:25:54 2000 UTC (25 years, 3 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.3: +3 -3 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     # restorevars(fh) : restore variables form a filehandle
19 williamc 1.1
20     package ObjectUtilities::StorableObject;
21     require 5.004;
22    
23     sub new {
24     my $class=shift;
25     my $Os=shift;
26     $self={};
27     bless $self, $class;
28     $self->{ObjectStore}=$Os;
29     $self->_init();
30     return $self;
31     }
32    
33     sub openfile {
34     my $self=shift;
35     my $filename=shift;
36    
37     local $fh=FileHandle->new();
38     open ( $fh, $filename) or die "Unable to open $filename\n $!\n";
39     return $fh;
40     }
41    
42     sub ObjectStore {
43     my $self=shift;
44     @_ ? $self->{ObjectStore}=shift
45     : $self->{ObjectStore};
46     }
47    
48     sub _init {
49     # dummy - override
50 williamc 1.2 }
51    
52     sub store {
53     print "Store Dummy not overridden"
54     }
55    
56     sub restore {
57     print "restore Dummy not overridden"
58     }
59    
60     sub meta {
61     my $self=shift;
62    
63     # by default just the class type
64     return ref($self);
65 williamc 1.1 }
66 williamc 1.3
67     sub savevar {
68     my $self=shift;
69     my $fh=shift;
70     my $name=shift;
71     my $val=shift;
72 williamc 1.4 print $fh "#".$name."\n";
73 williamc 1.3 print $fh $val."\n";
74     }
75    
76     sub restorevars {
77     my $fh=shift;
78     my $varhash;
79    
80     @_?$varhash=shift:$varhash={};
81     while ( <$fh>=~/^#/ ) {
82 williamc 1.4 ($name=$_)=~s/^#//;
83 williamc 1.3 chomp $name;
84 williamc 1.4 $value=<$fh>;
85 williamc 1.3 chomp $value;
86     $varhash{$name}=$value;
87     }
88     return $varhash;
89     }
90