home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
- *
- * (c) Westmount Technology 1994
- *
- * File: @(#)OPSetDict.hxx 1.1
- * Author: peku
- * Description:
- *---------------------------------------------------------------------------
- SccsId = @(#)OPSetDict.hxx 1.1 18 Oct 1994 Copyright 1994 Westmount Technology */
-
- #ifndef OPSETDICT_HXX
- #define OPSETDICT_HXX
-
- #ifndef OPTRSET_HXX
- #include "OPtrSet.hxx"
- #endif
-
- #ifndef PTRDICT_HXX
- #include "PtrDict.hxx"
- #endif
-
- #if HAS_TEMPLATES
-
- template<class Key, class Value>
- class OPSetDict : private GenPtrDict {
- public:
- void append(const Key &key, Value *value)
- {
- OPtrSet<Value> *vptr;
- if (!(vptr = (OPtrSet<Value> *)GenPtrDict::get(key))) {
- vptr = new OPtrSet<Value>;
- GenPtrDict::set(new Key(key), (void *)vptr);
- }
- vptr->append(value);
- }
- OPtrSet<Value> *get(const Key &key) const
- {
- return (OPtrSet<Value> *) GenPtrDict::get(key);
- }
- void remove(const Key &key, Value *value)
- {
- OPtrSet<Value> *vptr;
- if (vptr = (OPtrSet<Value> *)GenPtrDict::get(key)) {
- vptr->remove(value);
- if (vptr->size()) {
- 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();
- }
- OPtrSet<Value> *firstValue()
- {
- return (OPtrSet<Value> *) GenPtrDict::firstValue();
- }
- OPtrSet<Value> *nextValue()
- {
- return (OPtrSet<Value> *) GenPtrDict::nextValue();
- }
- };
-
- #else
-
- #define OPSetDict_(key,value) name3(key,value,_OPSetDict)
-
- #define OPSetDictdeclare2(Key,Value) \
- class OPSetDict_(Key,Value) : private GenPtrDict { \
- public: \
- void add(const Key &key, Value *value) \
- { \
- OPtrSet_(Value) *vptr; \
- if (!(vptr = (OPtrSet_(Value) *)GenPtrDict::get(key))) { \
- vptr = new OPtrSet_(Value); \
- GenPtrDict::set(new Key(key), (void *)vptr); \
- } \
- vptr->add(value); \
- } \
- OPtrSet_(Value) *get(const Key &key) const \
- { \
- return (OPtrSet_(Value) *) GenPtrDict::get(key); \
- } \
- void remove(const Key &key, Value *value) \
- { \
- OPtrSet_(Value) *vptr; \
- if (vptr = (OPtrSet_(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(); \
- } \
- OPtrSet_(Value) *firstValue() \
- { \
- return (OPtrSet_(Value) *) GenPtrDict::firstValue(); \
- } \
- OPtrSet_(Value) *nextValue() \
- { \
- return (OPtrSet_(Value) *) GenPtrDict::nextValue(); \
- } \
- }
-
- #endif /* HAS_TEMPLATES */
-
- #endif /* OPSETDICT_HXX */
-