Source: classlib/include/classlib/assoc.h
|
|
|
|
/* **************************************************************************
assocr.h - associazioni chiave valore
-------------------
begin : ven dic 7 17:40:01 CET 2001
copyright : (C) 2001 by Nicola De Nisco
email : nicola@winada.it
************************************************************************** */
/* *************************************************************************
* *
* 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. *
* *
************************************************************************* */
#if !defined( __CLASSLIB_ASSOC_H )
#define __CLASSLIB_ASSOC_H
#if !defined( __CLASSLIB_DEFS_H )
#include "classlib/defs.h"
#endif // __CLASSLIB_DEFS_H
#if !defined( __CLASSLIB_ALLOCTR_H )
#include "classlib/alloctr.h"
#endif // __CLASSLIB_ALLOCTR_H
#if !defined( __CLASSLIB_VOIDP_H )
#include "classlib/voidp.h"
#endif // __CLASSLIB_VOIDP_H
#if !defined( __CLASSLIB_HASHIMP_H )
#include "classlib/hashimp.h"
#endif // __CLASSLIB_HASHIMP_H
/**
template class TMDDAssociation
Managed association (direct key, direct value)
Implements a binding of a key (K) and value (V). Assumes that
K has a HashValue() member function or a global function with
the following prototype exists:
unsigned HashValue( K& );
*/
template class TMDDAssociation
{
public:
TMDDAssociation()
{
}
TMDDAssociation( const K& k, const V& v ) :
KeyData(k),
ValueData(v)
{
}
/** return the hash value of this association; pratically the hash value of the key value
*/
unsigned HashValue() const
{
return ::HashValue( KeyData );
}
const K& Key() const
{
return KeyData;
}
const V& Value() const
{
return ValueData;
}
/** convenience operator; compare the key of the association
*/
int operator == (const TMDDAssociation & a) const
{
return KeyData == a.KeyData;
}
void DeleteElements()
{
}
protected:
K KeyData;
V ValueData;
};
/**
template class TDDAssociation
Standard association (direct key, direct value)
*/
template class TDDAssociation :
public TMDDAssociation
{
public:
TDDAssociation() :
TMDDAssociation()
{
}
TDDAssociation( const K& k, const V& v ) :
TMDDAssociation( k, v )
{
}
};
/**
template class TMDIAssociation
Managed association (direct key, indirect value)
*/
template class TMDIAssociation :
protected TMDDAssociation
{
typedef TMDDAssociation Parent;
public:
TMDIAssociation() :
TMDDAssociation()
{
}
TMDIAssociation( const K& k, V *v ) :
TMDDAssociation( k, v )
{
}
const V *Value() const
{
return STATIC_CAST(V *,STATIC_CAST(void *,(TMDDAssociation::Value())));
}
int operator == (const TMDIAssociation & a) const
{
return Parent::operator ==(a);
}
Parent::HashValue;
Parent::Key;
void DeleteElements()
{
delete CONST_CAST(V *,Value());
}
};
/**
template class TDIAssociation
Standard association (direct key, indirect value)
*/
template class TDIAssociation :
public TMDIAssociation
{
public:
TDIAssociation() :
TMDIAssociation()
{
}
TDIAssociation( const K& k, V *v ) :
TMDIAssociation( k, v )
{
}
};
/**
template class TMIDAssociation
Managed association (indirect key, direct value)
*/
template class TMIDAssociation :
protected TMDDAssociation
{
typedef TMDDAssociation Parent;
public:
TMIDAssociation() :
TMDDAssociation()
{
}
TMIDAssociation( K *k, const V& v ) :
TMDDAssociation( k, v )
{
}
const K *Key() const
{
return STATIC_CAST(K *, STATIC_CAST(void *, Parent::Key()));
}
int operator == (const TMIDAssociation& a) const
{
return *Key() == *a.Key();
}
unsigned HashValue() const
{
return ::HashValue( *Key() );
}
Parent::Value;
void DeleteElements()
{
delete CONST_CAST(K *,Key());
}
};
/**
template class TIDAssociation
Standard association (indirect key, direct value)
*/
template class TIDAssociation :
public TMIDAssociation
{
public:
TIDAssociation() :
TMIDAssociation()
{
}
TIDAssociation( K *k, const V& v ) :
TMIDAssociation( k, v )
{
}
};
/**
template class TMIIAssociation
Managed association (indirect key, indirect value)
*/
template class TMIIAssociation :
protected TMDDAssociation
{
typedef TMDDAssociation Parent;
public:
TMIIAssociation() :
TMDDAssociation()
{
}
TMIIAssociation( K *k, V *v ) :
TMDDAssociation
( k, v )
{
}
const K *Key() const
{
return STATIC_CAST(K *, STATIC_CAST(void *, Parent::Key()));
}
const V *Value() const
{
return STATIC_CAST(V *, STATIC_CAST(void *, Parent::Value()));
}
int operator == (const TMIIAssociation& a) const
{
return *Key() == *a.Key();
}
unsigned HashValue() const
{
return ::HashValue( *Key() );
}
void DeleteElements()
{
delete CONST_CAST(K *,Key());
delete CONST_CAST(V *,Value());
}
};
/**
template class TIIAssociation
Standard association (indirect key, indirect value)
*/
template class TIIAssociation :
public TMIIAssociation
{
public:
TIIAssociation() :
TMIIAssociation()
{
}
TIIAssociation( K *k, V *v ) :
TMIIAssociation( k, v )
{
}
};
#endif // __CLASSLIB_ASSOC_H
Generated by: nicola on gulliver.wadahome.it on Sun May 25 13:54:34 2003, using kdoc 2.0a53. |