ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ObjectUtilities/StorableObject.pm
Revision: 1.9
Committed: Wed Mar 29 09:47:35 2000 UTC (25 years, 1 month ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_19_0, V0_18_5, V0_18_4, V_18_3_TEST, VO_18_3, V0_18_2, BuildSystemProto1, V0_18_1, V0_18_0, V0_18_0model, V0_17_1, V0_18_0alpha, V0_17_0, V0_16_4, V0_16_3, V0_16_2, V0_16_1, V0_16_0, V0_15_1, V0_15_0, ProtoEnd, V0_15_0beta
Branch point for: V0_17branch, V0_16branch, V0_15branch, HPWbranch
Changes since 1.8: +1 -0 lines
Log Message:
remove debug line

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.8 # savevararray(fh,"label",@array) : save the contents of the given array
21     # restorevararray(fh,\@array) : Restore the array values into array
22     # returns label
23 williamc 1.1 package ObjectUtilities::StorableObject;
24     require 5.004;
25    
26     sub new {
27     my $class=shift;
28     my $Os=shift;
29     $self={};
30     bless $self, $class;
31     $self->{ObjectStore}=$Os;
32     $self->_init();
33     return $self;
34     }
35    
36     sub openfile {
37     my $self=shift;
38     my $filename=shift;
39    
40     local $fh=FileHandle->new();
41     open ( $fh, $filename) or die "Unable to open $filename\n $!\n";
42     return $fh;
43     }
44    
45     sub ObjectStore {
46     my $self=shift;
47     @_ ? $self->{ObjectStore}=shift
48     : $self->{ObjectStore};
49     }
50    
51     sub _init {
52     # dummy - override
53 williamc 1.2 }
54    
55     sub store {
56     print "Store Dummy not overridden"
57     }
58    
59     sub restore {
60     print "restore Dummy not overridden"
61     }
62    
63     sub meta {
64     my $self=shift;
65    
66     # by default just the class type
67     return ref($self);
68 williamc 1.1 }
69 williamc 1.3
70     sub savevar {
71     my $self=shift;
72     my $fh=shift;
73     my $name=shift;
74     my $val=shift;
75 williamc 1.4 print $fh "#".$name."\n";
76 williamc 1.3 print $fh $val."\n";
77     }
78    
79 williamc 1.8 sub savevararray {
80     my $self=shift;
81     my $fh=shift;
82     my $label=shift;
83    
84     print $fh "_##$label\n";
85     foreach $val ( @_ ) {
86 williamc 1.9 # print $label." ".$val."\n";
87 williamc 1.8 print $fh $val."\n";
88     }
89     print $fh "_##\n";
90     }
91    
92     sub restorevararray {
93     my $self=shift;
94     my $fh=shift;
95     my $arr=shift;
96    
97     my ($label, $value);
98     ($label=<$fh>)=~s/^_##(.*)/$1/;
99     chomp $label;
100     while ( ($value=<$fh>)!~/^_##/ ) {
101     chomp $value;
102     push @$arr, $value;
103     }
104     return $label;
105     }
106    
107 williamc 1.3 sub restorevars {
108 williamc 1.5 my $self=shift;
109 williamc 1.3 my $fh=shift;
110 williamc 1.7 my $varhash=shift;
111 williamc 1.3
112 williamc 1.6 while ( <$fh>=~/^#(.*)/ ) {
113     $name=$1;
114 williamc 1.3 chomp $name;
115 williamc 1.4 $value=<$fh>;
116 williamc 1.3 chomp $value;
117 williamc 1.7 $$varhash{$name}=$value;
118 williamc 1.6 #print "Restoring ".$name."=".$value."\n";
119 williamc 1.3 }
120     }
121