1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
# -*- perl -*-
#
# Copyright (C) Heinz-Josef Claes (2000)
# hjclaes@web.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
push @::VERSION, '$Id: checkObjPar.pl,v 1.12 2002/03/26 18:44:04 hjc Exp $ ';
use strict;
# falls gesetzt, werden die Parameter fr 'configtool' angepat
$::checkObjectParams_configtool = undef;
# falls ebenfalls gesetzt, werden bei Configtool Objekte bergeben
$::checkObjectParams_getObjects = undef;
$::checkObjectParams_Trace = 0; # Default: kein Trace schreiben
$::checkObjectParams_TracePre = 'COP: ';
sub checkObjectParamsTraceOn
{
$::checkObjectParams_Trace = 1;
}
sub checkObjectParamsTraceOff
{
$::checkObjectParams_Trace = 0;
}
sub checkObjectParamsSetTracePre
{
$::checkObjectParams_TracePre = shift;
}
sub checkObjectParams
{
my $defaults = shift; # Zeiger auf Hash mit Defaultwerten
my $params = shift; # Zeiger auf Parameterliste
my $nameOfMethod = shift; # Name der Methode
my $mustBe = shift; # Zeiger auf Liste mit Parametern,
# die gesetzt werden mssen
my $i;
my $error = 0;
# Bercksichtigung von $checkObjectParams_configtool
if ($::checkObjectParams_configtool)
{
for ($i = 0 ; $i < @$params ; $i += 2)
{
$$params[$i] = $$params[$i][0]; # Bezeichner entvektoriesieren
$$params[$i+1] = $$params[$i+1][0]
unless (ref($$defaults{$$params[$i]}) eq 'ARRAY');
unless ($::checkObjectParams_getObjects)
{
my $o = $$params[$i+1];
if (ref($o) eq 'ARRAY')
{
my ($o1, @n);
foreach $o1 (@$o)
{
push @n, $o1->{'value'};
}
$$params[$i+1] = \@n;
}
else # not type ARRAY
{
$$params[$i+1] = $o->{'value'};
}
}
}
$::checkObjectParams_getObjects = undef;
$::checkObjectParams_configtool = undef;
}
# berprfen, ob alle zu setzenden Argumente auch gesetzt wurden
if (@$mustBe > 0)
{
my (%hash) = @$params;
my ($k);
foreach $k (@$mustBe)
{
unless (exists $hash{$k})
{
print STDERR "missing param <$k> in $nameOfMethod\n";
$error = 1;
}
}
}
# Defaultwerte mit den aktuellen Parametern berschreiben
my ($key, %flag);
foreach $key (keys %$defaults)
{
$flag{$key} = 1;
}
for ($i = 0 ; $i < @$params ; $i += 2)
{
if (defined($flag{$$params[$i]}))
{
$$defaults{$$params[$i]} = $$params[$i+1];
}
else
{
print STDERR "unknown param <$$params[$i]> in $nameOfMethod\n";
$error = 1;
}
}
if ($::checkObjectParams_Trace)
{
my $p = $::checkObjectParams_TracePre;
print "${p}calling $nameOfMethod with parameters\n";
foreach $key (keys %$defaults)
{
my $r = $$defaults{$key};
if (ref($r) eq 'ARRAY')
{
print "$p <$key> => (", scalar(@$r), ") -> <",
join('> <', @$r), ">\n";
}
else
{
print "$p <$key> => <$r>\n";
}
}
}
return $error;
}
# Variante 1: speichert alle Werte im Objekthash (keine gesondert angegeben
# Variante 2: speichert die angegebenen Werte im Objekthash
sub setParamsDirect # Das Minus-Zeichen der Parameter wird entfernt
{
my $self = shift; # Zeiger auf den Hash, in den eingehngt werden soll
my $params = shift; # Zeiger auf die einzuhngende Parameter
my $p;
foreach $p (@_ > 0 ? @_ : keys %$params)
{
my ($pn) = $p =~ /^-?(.*)$/; # fhrendes Minuszeichen entfernen
$self->{$pn} = $params->{$p};
}
}
1
|