home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Maps / BCMap.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  2.8 KB  |  115 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCMap.h
  5. //
  6. //  This file contains the declaration of the map abstract base class
  7. //  and its iterators.
  8.  
  9. #ifndef BCMAP_H
  10. #define BCMAP_H 1
  11.  
  12. #include "BCType.h"
  13.  
  14. template<class Item, class Value>
  15. class BC_TMapActiveIterator;
  16.  
  17. template<class Item, class Value>
  18. class BC_TMapPassiveIterator;  
  19.   
  20. template<class Item, class Value, class Structure>
  21. class BC_TTablePersist;  
  22.  
  23. // Map abstract base class
  24.  
  25. template<class Item, class Value>
  26. class BC_TMap {
  27. public:
  28.  
  29.   BC_TMap();
  30.   BC_TMap(const BC_TMap<Item, Value>&);
  31.   virtual ~BC_TMap();
  32.  
  33.   virtual BC_TMap<Item, Value>& operator=(const BC_TMap<Item, Value>&);
  34.   virtual BC_Boolean operator==(const BC_TMap<Item, Value>&) const;
  35.   BC_Boolean operator!=(const BC_TMap<Item, Value>&) const;
  36.  
  37.   virtual void SetHashFunction(BC_Index (*)(const Item&)) = 0;
  38.   virtual void Clear() = 0;
  39.   virtual BC_Boolean Bind(const Item&, const Value&) = 0;
  40.   virtual BC_Boolean Rebind(const Item&, const Value&) = 0;
  41.   virtual BC_Boolean Unbind(const Item&) = 0;
  42.  
  43.   virtual BC_Index Extent() const = 0;
  44.   virtual BC_Boolean IsEmpty() const = 0;
  45.   virtual BC_Boolean IsBound(const Item&) const = 0;
  46.   virtual const Value* ValueOf(const Item&) const = 0;
  47.   virtual Value* ValueOf(const Item&) = 0;
  48.  
  49. protected:
  50.  
  51.   virtual void Purge() = 0;
  52.   virtual BC_Boolean Attach(const Item&, const Value&) = 0;
  53.   virtual BC_Index Cardinality() const = 0;
  54.   virtual BC_Index NumberOfBuckets() const = 0;
  55.   virtual BC_Index Length(BC_Index bucket) const = 0;
  56.   virtual BC_Boolean Exists(const Item&) const = 0;
  57.   virtual const Item& ItemAt(BC_Index bucket, BC_Index index) const = 0;
  58.   virtual const Value& ValueAt(BC_Index bucket, BC_Index index) const = 0;
  59.  
  60.   virtual void Lock();
  61.   virtual void Unlock();
  62.   
  63. private:
  64.  
  65.   friend class BC_TMapActiveIterator<Item, Value>;
  66.   friend class BC_TMapPassiveIterator<Item, Value>;
  67.   
  68.   friend class BC_TTablePersist<Item, Value, BC_TMap<Item, Value> >;
  69.  
  70. };
  71.  
  72. // Map iterators
  73.  
  74. template <class Item, class Value>
  75. class BC_TMapActiveIterator {
  76. public:
  77.  
  78.   BC_TMapActiveIterator(const BC_TMap<Item, Value>&);
  79.   ~BC_TMapActiveIterator();
  80.   
  81.   void Reset();
  82.   BC_Boolean Next();
  83.  
  84.   BC_Boolean IsDone() const;
  85.   const Item* CurrentItem() const;
  86.   Item* CurrentItem();
  87.   const Value* CurrentValue() const;
  88.   Value* CurrentValue();
  89.   
  90. protected:
  91.  
  92.   const BC_TMap<Item, Value>& fMap;
  93.   BC_ExtendedIndex fBucketIndex;
  94.   BC_ExtendedIndex fIndex;
  95.   
  96. };
  97.  
  98. template <class Item, class Value>
  99. class BC_TMapPassiveIterator {
  100. public:
  101.  
  102.   BC_TMapPassiveIterator(const BC_TMap<Item, Value>&);
  103.   ~BC_TMapPassiveIterator();
  104.   
  105.   BC_Boolean Apply(BC_Boolean (*)(const Item&, const Value&));
  106.   BC_Boolean Apply(BC_Boolean (*)(Item&, Value&));
  107.   
  108. protected:
  109.  
  110.   const BC_TMap<Item, Value>& fMap;
  111.  
  112. };
  113.  
  114. #endif
  115.