| 1 | # | ||
| 2 | # $Id: Property.pm,v 1.1.1.1 1998/02/25 21:13:00 schwartz Exp $ | ||
| 3 | # | ||
| 4 | # OLE::Storage::Property | ||
| 5 | # | ||
| 6 | # Copyright (C) 1996, 1997, 1998 Martin Schwartz | ||
| 7 | # | ||
| 8 | # This program is free software; you can redistribute it and/or modify | ||
| 9 | # it under the terms of the GNU General Public License as published by | ||
| 10 | # the Free Software Foundation; either version 2 of the License, or | ||
| 11 | # (at your option) any later version. | ||
| 12 | # | ||
| 13 | # This program is distributed in the hope that it will be useful, | ||
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | # GNU General Public License for more details. | ||
| 17 | # | ||
| 18 | # You should have received a copy of the GNU General Public License | ||
| 19 | # along with this program; if not, you should find it at: | ||
| 20 | # | ||
| 21 | # http://wwwwbs.cs.tu-berlin.de/~schwartz/pmh/COPYING | ||
| 22 | # | ||
| 23 | # Contact: schwartz@cs.tu-berlin.de | ||
| 24 | # | ||
| 25 | package OLE::Storage::Property; | ||
| 26 | use strict; | ||
| 27 | my $VERSION=do{my@R=('$Revision: 1.1.1.1 $'=~/\d+/g);sprintf"%d."."%d"x$#R,@R}; | ||
| 28 | |||
| 29 | # | ||
| 30 | # Restrict OLE::Storage::Std imports, as name space mismatch could occur! | ||
| 31 | # | ||
| 32 | use OLE::Storage::Std qw(get_long); | ||
| 33 | use vars qw($AUTOLOAD); | ||
| 34 | |||
| 35 | sub AUTOLOAD { | ||
| 36 | # | ||
| 37 | # $string = $Property->string | ||
| 38 | # @strings = string { @Properties } | ||
| 39 | # | ||
| 40 | (my $to = $AUTOLOAD) =~ s/.*://; | ||
| 41 | if (wantarray) { | ||
| 42 | map ( $_->_var->_RETRIEVE( $_->type, $to, $_->_data), @_) | ||
| 43 | } else { | ||
| 44 | return $_[0]->_var->_RETRIEVE($_[0]->type, $to, $_[0]->_data); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | sub cast { | ||
| 49 | # | ||
| 50 | # new Property = $Property -> cast ($type) | ||
| 51 | # | ||
| 52 | my ($S, $type) = @_; | ||
| 53 | $S->_var()->property (\$S->$type(), 0, $type); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub array { $_[0]->_data } | ||
| 57 | sub is_scalar { $_[0]->_var()->_IS_SCALAR($_[0]->type()) } | ||
| 58 | sub is_array { $_[0]->_var()->_IS_ARRAY($_[0]->type()) } | ||
| 59 | sub is_varray { $_[0]->_var()->_IS_VARRAY($_[0]->type()) } | ||
| 60 | sub stype { $_[0]->_var()->_TO_SCALAR($_[0]->type()) } | ||
| 61 | sub type { $_[0]->_type } | ||
| 62 | sub typestr { | ||
| 63 | my $S=shift; | ||
| 64 | my $str = $S->_var->_TYPESTR($S->stype); | ||
| 65 | $str .= "[]" if $S->is_array; | ||
| 66 | $str; | ||
| 67 | } | ||
| 68 | sub var { $_[0]->_var } | ||
| 69 | |||
| 70 | # | ||
| 71 | # -- Private --------------------------------------------------------------- | ||
| 72 | # | ||
| 73 | |||
| 74 | sub new { | ||
| 75 | # | ||
| 76 | # $Property = new Property ($Var, \$buf, $o||\$o [,$type]) | ||
| 77 | # | ||
| 78 | my ($proto, $Var, $bufR, $o, $type) = @_; | ||
| 79 | my $class = ref($proto) || $proto; | ||
| 80 | my $S = { | ||
| 81 | V => $Var, # _var, Variable Handler | ||
| 82 | T => undef, # _type, Property Type | ||
| 83 | D => undef, # _data, Property Data, maintained by $Var | ||
| 84 | }; | ||
| 85 | bless ($S, $class) -> | ||
| 86 | _property($bufR, ref($o) ? $o : \$o, $type) | ||
| 87 | ; | ||
| 88 | } | ||
| 89 | |||
| 90 | sub dump { | ||
| 91 | my $S = $_[0]; | ||
| 92 | my ($k, $v); | ||
| 93 | print "$S\n"; | ||
| 94 | while ( ($k, $v) = each %$S ) { | ||
| 95 | print " {$k} = $v\n"; | ||
| 96 | if (($k eq "D") && ref($v)) { | ||
| 97 | printf " [0] = %s\n", $v->[0]; | ||
| 98 | printf " [1] = %s (%s)\n", $v->[1], ${$v->[1]}; | ||
| 99 | } | ||
| 100 | } | ||
| 101 | print "\n"; | ||
| 102 | } | ||
| 103 | |||
| 104 | sub DESTROY { | ||
| 105 | #print "Deleting "; shift->dump(); | ||
| 106 | } | ||
| 107 | |||
| 108 | sub _property { | ||
| 109 | # | ||
| 110 | # $Prop = _property(\$buf, $oR [,$type]) | ||
| 111 | # | ||
| 112 | # Structure: | ||
| 113 | # | ||
| 114 | # Error_Property = { T=>error, D=>$errstr } | ||
| 115 | # Standard_Property = { T=>$type, D=>$data } | ||
| 116 | # Vector_Property = { T=>$type, D=>[$Property, $Property, ... ] } | ||
| 117 | # | ||
| 118 | my $S = shift; | ||
| 119 | my ($bufR, $oR, $type) = @_; | ||
| 120 | $type = get_long($bufR, $oR) if !defined $type; | ||
| 121 | |||
| 122 | if ($S->is_scalar($S->_type($type))) { | ||
| 123 | $S->_data($S->_var->_STORE($bufR, $oR, $type)); | ||
| 124 | } else { | ||
| 125 | if ($S->is_varray) { | ||
| 126 | $type = undef; | ||
| 127 | } else { | ||
| 128 | $type = $S->stype; | ||
| 129 | } | ||
| 130 | $S->_data([map( | ||
| 131 | $S->_var->property($bufR, $oR, $type), (1 .. get_long($bufR, $oR)) | ||
| 132 | )]); | ||
| 133 | } | ||
| 134 | $S} | ||
| 135 | |||
| 136 | # | ||
| 137 | # Member methods | ||
| 138 | # | ||
| 139 | |||
| 140 | sub _data { my $S=shift; $S->{D}=shift if @_; $S->{D} } | ||
| 141 | sub _type { my $S=shift; $S->{T}=shift if @_; $S->{T} } | ||
| 142 | sub _var { my $S=shift; $S->{V}=shift if @_; $S->{V} } | ||
| 143 | |||
| 144 | "Atomkraft? Nein, danke!" | ||
| 145 | |||
| 146 | __END__ |