home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
PSetDict.hxx
< prev
next >
Wrap
Text File
|
1996-05-31
|
3KB
|
130 lines
/*---------------------------------------------------------------------------
*
* (c) Westmount Technology 1993
*
* File: @(#)PSetDict.hxx 1.3
* Author: peku
* Description: dictionary of pointer sets
* expects that class Value_PtrSet exists
*---------------------------------------------------------------------------
SccsId = @(#)PSetDict.hxx 1.3 22 Feb 1994 Copyright 1993 Westmount Technology */
#ifndef PSETDICT_HXX
#define PSETDICT_HXX
#ifndef PTRSET_HXX
#include "PtrSet.hxx"
#endif
#ifndef PTRDICT_HXX
#include "PtrDict.hxx"
#endif
#if HAS_TEMPLATES
template<class Key, class Value>
class PSetDict : private GenPtrDict {
public:
void add(const Key &key, Value *value)
{
PtrSet<Value> *vptr;
if (!(vptr = (PtrSet<Value> *)GenPtrDict::get(key))) {
vptr = new PtrSet<Value>;
GenPtrDict::set(new Key(key), (void *)vptr);
}
vptr->add(value);
}
PtrSet<Value> *get(const Key &key) const
{
return (PtrSet<Value> *) GenPtrDict::get(key);
}
void remove(const Key &key, Value *value)
{
PtrSet<Value> *vptr;
if (vptr = (PtrSet<Value> *)GenPtrDict::get(key)) {
vptr->remove(value);
if (!vptr->first()) {
GenPtrDict::remove(key);
delete vptr;
}
}
}
int isPresent(const Key &key) const
{
return GenPtrDict::isPresent(key);
}
const Key *firstKey()
{
return (Key *) GenPtrDict::firstKey();
}
const Key *nextKey()
{
return (Key *) GenPtrDict::nextKey();
}
PtrSet<Value> *firstValue()
{
return (PtrSet<Value> *) GenPtrDict::firstValue();
}
PtrSet<Value> *nextValue()
{
return (PtrSet<Value> *) GenPtrDict::nextValue();
}
};
#else
#define PSetDict_(key,value) name3(key,value,_PSetDict)
#define PSetDictdeclare2(Key,Value) \
class PSetDict_(Key,Value) : private GenPtrDict { \
public: \
void add(const Key &key, Value *value) \
{ \
PtrSet_(Value) *vptr; \
if (!(vptr = (PtrSet_(Value) *)GenPtrDict::get(key))) { \
vptr = new PtrSet_(Value); \
GenPtrDict::set(new Key(key), (void *)vptr); \
} \
vptr->add(value); \
} \
PtrSet_(Value) *get(const Key &key) const \
{ \
return (PtrSet_(Value) *) GenPtrDict::get(key); \
} \
void remove(const Key &key, Value *value) \
{ \
PtrSet_(Value) *vptr; \
if (vptr = (PtrSet_(Value) *)GenPtrDict::get(key)) { \
vptr->remove(value); \
if (!vptr->first()) { \
GenPtrDict::remove(key); \
delete vptr; \
} \
} \
} \
int isPresent(const Key &key) const \
{ \
return GenPtrDict::isPresent(key); \
} \
const Key *firstKey() \
{ \
return (Key *) GenPtrDict::firstKey(); \
} \
const Key *nextKey() \
{ \
return (Key *) GenPtrDict::nextKey(); \
} \
PtrSet_(Value) *firstValue() \
{ \
return (PtrSet_(Value) *) GenPtrDict::firstValue(); \
} \
PtrSet_(Value) *nextValue() \
{ \
return (PtrSet_(Value) *) GenPtrDict::nextValue(); \
} \
}
#endif /* HAS_TEMPLATES */
#endif /* PSETDICT_HXX */