#!/usr/bin/perl
# -----------------------------------------------------------------------------
# TWC
# Treuwert-Computer GmbH
# Schloßbergring 9
# 79098 Freiburg
#
# Author: Klaus Reger <K.Reger@twc.de>
#
# -----------------------------------------------------------------------------
# Program-Data
# -----------------------------------------------------------------------------
# Project  :
# System   :
# Program  :
# Module   : $RCSfile: Hash.pm,v $
# Version  : $Revision: 1.2 $
# Date     : $Date: 2002/02/25 10:50:44 $
# State    : $State: Exp $
#
# Description:
#   This module handles all the things of WWWdb, which have
#   to do with Hashes
#
# Change-log (See at end of this file)
#
# --- Known Bugs -------------
# please look at the BUGS-File
# --- TODO -------------------
# please look at the TODO-File
# ----------------------------------------------------------------------------

=head1 NAME

WWWdb::Hash - Hashes for WWWdb

=head1 SYNOPSIS

 use WWWdb::Hash;

 $oHash     = Hash->new();

 $cResult   = $oHash->Get($cKey);

 $cResult   = $oHash->Set($cKey, $cValue);

 $cResult   = $oHash->Delete($cKey);

 $iResult   = $oHash->Count();

=cut

# The POD text continues at the end of the file.



use WWWdb::Base;


# --------------------------------------------------------------------
# Hash
# --------------------------------------------------------------------
package Hash;
use vars qw(%hMethods %hAttribs);

use English;
use strict;

@Hash::ISA = qw(Base);

{
   %hAttribs =
       (
        Hash         => ["h", "private", "rw", undef],
        );
}

# --- constructor ---------------------------------------------------
sub Hash::new()
{
   my ($cPkgPI)      = shift;

   my $cClass   = ref($cPkgPI) || $cPkgPI;

   my $hSelf   = $cClass->SUPER::new(@_);

   $hSelf->{"Hash"} = ();

   bless ($hSelf, $cClass);

   return $hSelf;
}


# --- Get the value of a Hash-element ------------------------------------
sub Hash::Get($)
{
   my $hSelfPI = shift;
   my $cKeyPI  = shift;

   return (defined $cKeyPI?
           $hSelfPI->{"Hash"}->{$cKeyPI}:
           keys %{$hSelfPI->{"Hash"}});

}



# --- Get the value of a Hash-element ------------------------------------
sub Hash::Delete($)
{
   my $hSelfPI = shift;
   my $cKeyPI  = shift;

   return delete $hSelfPI->{"Hash"}->{$cKeyPI};
}



# --- Set the value of a Hash-element ------------------------------------
sub Hash::Set($$)
{
   my $hSelfPI   = shift;
   my $cKeyPI  = shift;
   my $cValuePI  = shift;

   $hSelfPI->{"Hash"}->{$cKeyPI} = $cValuePI;

   return $cValuePI;
}

# --- Get the number of Hash-elements ------------------------------------
sub Hash::Count()
{
   my $hSelfPI   = shift;
   my $iResult   = scalar($hSelfPI->{"Hash"});

   return $iResult;
}



1;


__END__


=head1 DESCRIPTION

=head1 The Hash class

Perl is I<the> language for Hash-manipulation. Neverthless I wished
some funktionality for imbedded class-elements in Hash-form. That was
the main reason, for developing this class.

=head2 Note

=over 4

none

=back

=head2 Class Methods

=over 4


=item B<new>

 $oHash     = Hash->new();

Create a new empty Hash.


=item B<Get>

 $bResult   = $oHash->Get($cKey);

Returns the element with the Key I<cKey>.


=item B<Set>

 $cResult   = $oHash->Set($cKey, $cValue);

Sets the value of the element with the Key I<cKey>.

=item B<Delete>

 $cResult   = $oHash->Delete($cKey);

Deletes the element at Key I<cKey>. The value of the deleted element
will be returned.



=item B<Count>

 $iResult   = $oHash->Count();

Returns the number of elements, the Hash contains.

=back

=head2 Class Attributes

=over 4

none

=back





