home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
PtrDict.hxx
< prev
next >
Wrap
Text File
|
1996-05-31
|
3KB
|
122 lines
/*---------------------------------------------------------------------------
*
* (c) Westmount Technology 1993
*
* File: @(#)PtrDict.hxx 1.6
* Author: frmo
* Description: PtrDict (A map of key-value pairs),
* value is a pointer
*---------------------------------------------------------------------------
SccsId = @(#)PtrDict.hxx 1.6 11 Nov 1993 Copyright 1993 Westmount Technology */
#ifndef PTRDICT_HXX
#define PTRDICT_HXX
#ifndef TEMPLCONF_HXX
#include "TemplConf.hxx"
#endif
#ifndef HASHTBL_HXX
#include "HashTbl.hxx"
#endif
// A slot in the dictionary
class DictSlot : public Hashable {
Hashable *key;
void *value;
public:
DictSlot(Hashable *aKey, void *aValue) :
key(aKey), value(aValue) {}
~DictSlot();
unsigned hash() const;
int isEqual(const Hashable &other) const;
Hashable *getKey() const { return key; }
void *getValue() const { return value; }
void setValue(void *newValue) { value = newValue; }
};
#if HAS_TEMPLATES
typedef hashTbl<Hashable, DictSlot> DictSlotTbl;
#else
declare2(HashTbl,Hashable,DictSlot);
typedef hashTbl(Hashable,DictSlot) DictSlotTbl;
#endif /* HAS_TEMPLATES */
class GenPtrDict: private DictSlotTbl {
public:
void set(Hashable *key, void *value);
void *get(const Hashable &key) const;
void remove(const Hashable &key);
int isPresent(const Hashable &key) const;
const Hashable *firstKey();
const Hashable *nextKey();
void *firstValue();
void *nextValue();
};
#if HAS_TEMPLATES
template<class Key, class Value>
class PtrDict : private GenPtrDict {
public:
void set(const Key &key, Value *value)
{ GenPtrDict::set(new Key(key), value); }
Value *get(const Key &key) const
{ return (Value *) GenPtrDict::get(key); }
void remove(const Key &key)
{ GenPtrDict::remove(key); }
int isPresent(const Key &key) const
{ return GenPtrDict::isPresent(key); }
const Key *firstKey()
{ return (Key *) GenPtrDict::firstKey(); }
const Key *nextKey()
{ return (Key *) GenPtrDict::nextKey(); }
Value *firstValue()
{ return (Value *) GenPtrDict::firstValue(); }
Value *nextValue()
{ return (Value *) GenPtrDict::nextValue(); }
};
#else
#define PtrDict_(key,value) name3(key,value,_PtrDict)
#define PtrDictdeclare2(Key,Value) \
class PtrDict_(Key,Value) : private GenPtrDict { \
public: \
void set(const Key &key, Value *value) \
{ GenPtrDict::set(new Key(key), value); } \
Value *get(const Key &key) const \
{ return (Value *) GenPtrDict::get(key); } \
void remove(const Key &key) \
{ GenPtrDict::remove(key); } \
int isPresent(const Key &key) const \
{ return GenPtrDict::isPresent(key); } \
\
const Key *firstKey() \
{ return (Key *) GenPtrDict::firstKey(); } \
const Key *nextKey() \
{ return (Key *) GenPtrDict::nextKey(); } \
\
Value *firstValue() \
{ return (Value *) GenPtrDict::firstValue(); } \
Value *nextValue() \
{ return (Value *) GenPtrDict::nextValue(); } \
}
#endif /* HAS_TEMPLATES */
#endif /* PTRDICT_HXX */