home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / aplusplus-1.01-src.lha / GNU / src / amiga / APlusPlus-1.01 / include / APlusPlus / environment / MapArray.h < prev    next >
C/C++ Source or Header  |  1994-05-04  |  2KB  |  66 lines

  1. #ifndef APP_MapArray_H
  2. #define APP_MapArray_H
  3. /******************************************************************************
  4.  **
  5.  **    C++ Class Library for the Amiga© system software.
  6.  **
  7.  **    Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  8.  **    All Rights Reserved.
  9.  **
  10.  **    $VER: apphome:APlusPlus/environment/MapArray.h 1.04 (04.05.94) $
  11.  **    
  12.  ******************************************************************************/
  13.  
  14. extern "C" {
  15. #include <exec/types.h>
  16. }
  17. #include <iostream.h>
  18.  
  19.  
  20. /******************************************************************************************
  21.       » MapArray class «
  22.  
  23.  
  24.  ******************************************************************************************/
  25. typedef void* MA_T;
  26. typedef ULONG MapKey;
  27.  
  28. class MapArrayIterator;
  29. class MapArray
  30. {
  31.     friend MapArrayIterator;
  32.     private:
  33.         struct Pair { MapKey key; MA_T entry; } *pairs;
  34.         int arraySize;
  35.         static Pair empty;
  36.         
  37.     public:
  38.         MapArray();
  39.         ~MapArray();
  40.         
  41.         MA_T& operator [] (MapKey tag);    
  42.         // returns reference to the MA_T object associated with 'tag' or if 'tag' was not found new MA_T object
  43.         MA_T find(MapKey tag);    // returns pointer to associated MA_T object or NULL if not found
  44.             
  45. };
  46.  
  47. class MapArrayIterator
  48. {
  49.     private:
  50.         MapArray *mapArray;
  51.         int cIndex;
  52.  
  53.     public:
  54.         MapArrayIterator(MapArray& ma) { cIndex = -1; mapArray = &ma; }
  55.             
  56.         void reset() { cIndex = -1; }
  57.         MA_T operator ()() { MapArray::Pair *p = &mapArray->pairs[++cIndex]; 
  58.                                     if (p->key) return p->entry; else return(MA_T)NULL; }
  59.         MA_T& operator [](int dummy) { return mapArray->pairs[cIndex].entry; }
  60.         
  61.         MapKey key() { return mapArray->pairs[cIndex].key; }
  62. };
  63.  
  64. #undef MA_T
  65. #endif
  66.