home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 2.7 KB | 116 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // BCSet.h
- //
- // This file contains the declaration of the set abstract base class
- // and its iterators.
-
- #ifndef BCSET_H
- #define BCSET_H 1
-
- #include "BCType.h"
-
- template<class Item>
- class BC_TSetActiveIterator;
-
- template<class Item>
- class BC_TSetPassiveIterator;
-
- template<class Item, class Value, class Structure>
- class BC_TTablePersist;
-
- // Set abstract base class
-
- template<class Item>
- class BC_TSet {
- public:
-
- BC_TSet();
- BC_TSet(const BC_TSet<Item>&);
- virtual ~BC_TSet();
-
- virtual BC_TSet<Item>& operator=(const BC_TSet<Item>&);
- virtual BC_Boolean operator==(const BC_TSet<Item>&) const;
- BC_Boolean operator!=(const BC_TSet<Item>&) const;
-
- virtual void SetHashFunction(BC_Index (*)(const Item&)) = 0;
- virtual void Clear() = 0;
- virtual BC_Boolean Add(const Item&) = 0;
- virtual BC_Boolean Remove(const Item& at) = 0;
- virtual void Union(const BC_TSet<Item>&);
- virtual void Intersection(const BC_TSet<Item>&);
- virtual void Difference(const BC_TSet<Item>&);
-
- virtual BC_Index Extent() const = 0;
- virtual BC_Boolean IsEmpty() const = 0;
- virtual BC_Boolean IsMember(const Item&) const = 0;
- virtual BC_Boolean IsSubset(const BC_TSet<Item>&) const;
- virtual BC_Boolean IsProperSubset(const BC_TSet<Item>&) const;
-
- protected:
-
- virtual void Purge() = 0;
- virtual BC_Boolean Attach(const Item&, const BC_Boolean&);
- virtual BC_Boolean Attach(const Item&) = 0;
- virtual BC_Boolean Detach(const Item&) = 0;
- virtual BC_Index Cardinality() const = 0;
- virtual BC_Index NumberOfBuckets() const = 0;
- virtual BC_Index Length(BC_Index bucket) const = 0;
- virtual BC_Boolean Exists(const Item&) const = 0;
- virtual const Item& ItemAt(BC_Index bucket, BC_Index index) const = 0;
-
- virtual void Lock();
- virtual void Unlock();
-
- private:
-
- friend class BC_TSetActiveIterator<Item>;
- friend class BC_TSetPassiveIterator<Item>;
-
- friend class BC_TTablePersist<Item, BC_Boolean, BC_TSet<Item> >;
-
- };
-
- // Set iterators
-
- template <class Item>
- class BC_TSetActiveIterator {
- public:
-
- BC_TSetActiveIterator(const BC_TSet<Item>&);
- ~BC_TSetActiveIterator();
-
- void Reset();
- BC_Boolean Next();
-
- BC_Boolean IsDone() const;
- const Item* CurrentItem() const;
- Item* CurrentItem();
-
- protected:
-
- const BC_TSet<Item>& fSet;
- BC_ExtendedIndex fBucketIndex;
- BC_ExtendedIndex fIndex;
-
- };
-
- template <class Item>
- class BC_TSetPassiveIterator {
- public:
-
- BC_TSetPassiveIterator(const BC_TSet<Item>&);
- ~BC_TSetPassiveIterator();
-
- BC_Boolean Apply(BC_Boolean (*)(const Item&));
- BC_Boolean Apply(BC_Boolean (*)(Item&));
-
- protected:
-
- const BC_TSet<Item>& fSet;
-
- };
-
- #endif
-