home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
PtrSet.hxx
< prev
next >
Wrap
Text File
|
1996-05-31
|
2KB
|
88 lines
/*---------------------------------------------------------------------------
*
* (c) Westmount Technology 1993
*
* File: @(#)PtrSet.hxx 1.4
* Author: frmo
* Description: A set of pointers
*---------------------------------------------------------------------------
SccsId = @(#)PtrSet.hxx 1.4 13 Jan 1994 Copyright 1993 Westmount Technology */
#ifndef PTRSET_HXX
#define PTRSET_HXX
#ifndef TEMPLCONF_HXX
#include "TemplConf.hxx"
#endif
#ifndef HASHTBL_HXX
#include "HashTbl.hxx"
#endif
class PointerHash: public Hashable {
void *ptr;
public:
PointerHash(void *aPtr) : ptr(aPtr) {}
~PointerHash();
unsigned hash() const;
int isEqual(const Hashable &key) const;
void *getPtr() { return ptr; }
};
#if HAS_TEMPLATES
typedef hashTbl<PointerHash, PointerHash> PtrHashTbl;
#else
declare2(HashTbl,PointerHash,PointerHash);
typedef hashTbl(PointerHash,PointerHash) PtrHashTbl;
#endif /* HAS_TEMPLATES */
class GenPtrSet: private PtrHashTbl {
public:
int add(void *ptr);
void remove(void *ptr);
int isPresent(void *ptr) const;
unsigned size() const;
void *first();
void *next();
};
#if HAS_TEMPLATES
template<class T>
class PtrSet : private GenPtrSet {
public:
int add(T *ptr) { return GenPtrSet::add(ptr); }
void remove(T *ptr) { GenPtrSet::remove(ptr); }
int isPresent(T *ptr) const { return GenPtrSet::isPresent(ptr);}
unsigned size() const { return GenPtrSet::size();}
T *first() { return (T*) GenPtrSet::first(); }
T *next() { return (T*) GenPtrSet::next(); }
};
#else
#define PtrSet_(t) name2(t,_PtrSet)
#define PtrSetdeclare(t) \
class PtrSet_(t) : private GenPtrSet { \
public: \
int add(t *ptr) { return GenPtrSet::add(ptr); } \
void remove(t *ptr) { GenPtrSet::remove(ptr); } \
int isPresent(t *ptr) const { return GenPtrSet::isPresent(ptr);} \
unsigned size() const { return GenPtrSet::size();} \
\
t *first() { return (t *) GenPtrSet::first(); } \
t *next() { return (t *) GenPtrSet::next(); } \
}
#endif /* HAS_TEMPLATES */
#endif /* PTRSET_HXX */