ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ObjectUtilities/StorableObject.pm
Revision: 1.10
Committed: Tue Dec 11 10:05:05 2001 UTC (23 years, 5 months ago) by sashby
Content type: text/plain
Branch: MAIN
CVS Tags: V1_2_1b, V1_2_1a, V1_2_3, V1_2_2, V1_2_2_relcand2, V1_2_1, V1_2_0, V1_2_0-cand11, V1_1_7, V1_1_6, V1_2_0-cand10, V1_1_5, V1_2_0-cand9, V1_2_0-cand8, V1_2_0-cand7, V1_2_0-cand6, V1_2_0-cand5, V1_2_0-cand4, V1_2_0-cand3, V1_2_0-cand2, V1_2_0-cand1, V1_1_4, V1_1_3, V1_1_2, V1_1_0_reltag8, V1_1_0_reltag7, V1_1_0_reltag6, V1_1_1, V1_1_0_reltag5, V1_1_0_reltag4, V1_1_0_reltag3, V1_1_0_reltag2, V1_1_0_reltag1, V1_1_0_reltag, V1_0_3-p4, V1_1_0_cand3, V1_1_0_cand2, V1_1_0_cand1, HEAD_SM_071214, forV1_1_0, v103_xml_071106, V1_0_3-p3, V1_0_3-p2, V1_1_0, v110p1, V110p6, V110p5, V110p4, V110p3, before110xmlBRmerge, V110p2, V110p1, V1_0_4p1, V1_0_3-p1, V1_0_3, V1_0_2, V1_0_2_p1, v102p1, V1_0_1, V1_0_0, V1_pre0, SCRAM_V1, SCRAMV1_IMPORT, V0_19_7, V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2, V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1
Branch point for: forBinLess_SCRAM, HEAD_BRANCH_SM_071214, v200branch, v103_with_xml, v103_branch, V1_pre1, SCRAM_V1_BRANCH, V0_19_4_B
Changes since 1.9: +0 -2 lines
Log Message:
*** empty log message ***

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     print $fh $val."\n";
87     }
88     print $fh "_##\n";
89     }
90    
91     sub restorevararray {
92     my $self=shift;
93     my $fh=shift;
94     my $arr=shift;
95    
96     my ($label, $value);
97     ($label=<$fh>)=~s/^_##(.*)/$1/;
98     chomp $label;
99     while ( ($value=<$fh>)!~/^_##/ ) {
100     chomp $value;
101     push @$arr, $value;
102     }
103     return $label;
104     }
105    
106 williamc 1.3 sub restorevars {
107 williamc 1.5 my $self=shift;
108 williamc 1.3 my $fh=shift;
109 williamc 1.7 my $varhash=shift;
110 williamc 1.3
111 williamc 1.6 while ( <$fh>=~/^#(.*)/ ) {
112     $name=$1;
113 williamc 1.3 chomp $name;
114 williamc 1.4 $value=<$fh>;
115 williamc 1.3 chomp $value;
116 williamc 1.7 $$varhash{$name}=$value;
117 williamc 1.3 }
118     }
119