/*------------------------------------------------------------------------*/ /* */ /* ASSOC.H */ /* */ /* Copyright (c) 1993, 1994 Borland International */ /* All Rights Reserved */ /* */ /*------------------------------------------------------------------------*/ #if !defined( CLASSLIB_ASSOC_H ) #define CLASSLIB_ASSOC_H #if !defined( CLASSLIB_DEFS_H ) #include #endif #if !defined( CLASSLIB_ALLOCTR_H ) #include #endif #if !defined( CLASSLIB_VOIDP_H ) #include #endif #if !defined( CLASSLIB_HASHIMP_H ) #include #endif #pragma option -Vo- #if defined( BI_CLASSLIB_NO_po ) #pragma option -po- #endif /*------------------------------------------------------------------------*/ /* */ /* 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) { } unsigned HashValue() const { return ::HashValue( KeyData ); } const K& Key() const { return KeyData; } const V& Value() const { return ValueData; } 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 : private 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 : private 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 : private 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 ) { } }; #if defined( BI_CLASSLIB_NO_po ) #pragma option -po. #endif #pragma option -Vo. #endif // CLASSLIB_ASSOC_H