home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 18.ddi / MFC / INCLUDE / AFXCOLL.H_ / AFXCOLL.H
Encoding:
C/C++ Source or Header  |  1993-02-08  |  28.9 KB  |  1,257 lines

  1. // Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation, 
  3. // All rights reserved. 
  4.  
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and Microsoft
  7. // QuickHelp and/or WinHelp documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #ifndef __AFXCOLL_H__
  12. #define __AFXCOLL_H__
  13.  
  14. #ifndef __AFX_H__
  15. #include "afx.h"
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Classes declared in this file
  20.  
  21. //CObject
  22.     // Arrays
  23.     class CByteArray;           // array of BYTE
  24.     class CWordArray;           // array of WORD
  25.     class CDWordArray;          // array of DWORD
  26.     class CUIntArray;           // array of UINT
  27.     class CPtrArray;            // array of void*
  28.     class CObArray;             // array of CObject*
  29.  
  30.     // Lists
  31.     class CPtrList;             // list of void*
  32.     class CObList;              // list of CObject*
  33.  
  34.     // Maps (aka Dictionaries)
  35.     class CMapWordToOb;         // map from WORD to CObject*
  36.     class CMapWordToPtr;        // map from WORD to void*
  37.     class CMapPtrToWord;        // map from void* to WORD
  38.     class CMapPtrToPtr;         // map from void* to void*
  39.  
  40.     // Special String variants
  41.     class CStringArray;         // array of CStrings
  42.     class CStringList;          // list of CStrings
  43.     class CMapStringToPtr;      // map from CString to void*
  44.     class CMapStringToOb;       // map from CString to CObject*
  45.     class CMapStringToString;   // map from CString to CString
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48.  
  49. #undef AFXAPP_DATA
  50. #define AFXAPP_DATA     AFXAPI_DATA
  51.  
  52.  
  53. ////////////////////////////////////////////////////////////////////////////
  54.  
  55. class CByteArray : public CObject
  56. {
  57.  
  58.     DECLARE_SERIAL(CByteArray)
  59. public:
  60.  
  61. // Construction
  62.     CByteArray();
  63.  
  64. // Attributes
  65.     int GetSize() const;
  66.     int GetUpperBound() const;
  67.     void SetSize(int nNewSize, int nGrowBy = -1);
  68.  
  69. // Operations
  70.     // Clean up
  71.     void FreeExtra();
  72.     void RemoveAll();
  73.  
  74.     // Accessing elements
  75.     BYTE GetAt(int nIndex) const;
  76.     void SetAt(int nIndex, BYTE newElement);
  77.     BYTE& ElementAt(int nIndex);
  78.  
  79.     // Potentially growing the array
  80.     void SetAtGrow(int nIndex, BYTE newElement);
  81.     int Add(BYTE newElement);
  82.  
  83.     // overloaded operator helpers
  84.     BYTE operator[](int nIndex) const;
  85.     BYTE& operator[](int nIndex);
  86.  
  87.     // Operations that move elements around
  88.     void InsertAt(int nIndex, BYTE newElement, int nCount = 1);
  89.     void RemoveAt(int nIndex, int nCount = 1);
  90.     void InsertAt(int nStartIndex, CByteArray* pNewArray);
  91.  
  92. // Implementation
  93. protected:
  94.     BYTE* m_pData;   // the actual array of data
  95.     int m_nSize;     // # of elements (upperBound - 1)
  96.     int m_nMaxSize;  // max allocated
  97.     int m_nGrowBy;   // grow amount
  98.  
  99. public:
  100.     ~CByteArray();
  101.  
  102.     void Serialize(CArchive&);
  103. #ifdef _DEBUG
  104.     void Dump(CDumpContext&) const;
  105.     void AssertValid() const;
  106. #endif
  107. };
  108.  
  109.  
  110. ////////////////////////////////////////////////////////////////////////////
  111.  
  112. class CWordArray : public CObject
  113. {
  114.  
  115.     DECLARE_SERIAL(CWordArray)
  116. public:
  117.  
  118. // Construction
  119.     CWordArray();
  120.  
  121. // Attributes
  122.     int GetSize() const;
  123.     int GetUpperBound() const;
  124.     void SetSize(int nNewSize, int nGrowBy = -1);
  125.  
  126. // Operations
  127.     // Clean up
  128.     void FreeExtra();
  129.     void RemoveAll();
  130.  
  131.     // Accessing elements
  132.     WORD GetAt(int nIndex) const;
  133.     void SetAt(int nIndex, WORD newElement);
  134.     WORD& ElementAt(int nIndex);
  135.  
  136.     // Potentially growing the array
  137.     void SetAtGrow(int nIndex, WORD newElement);
  138.     int Add(WORD newElement);
  139.  
  140.     // overloaded operator helpers
  141.     WORD operator[](int nIndex) const;
  142.     WORD& operator[](int nIndex);
  143.  
  144.     // Operations that move elements around
  145.     void InsertAt(int nIndex, WORD newElement, int nCount = 1);
  146.     void RemoveAt(int nIndex, int nCount = 1);
  147.     void InsertAt(int nStartIndex, CWordArray* pNewArray);
  148.  
  149. // Implementation
  150. protected:
  151.     WORD* m_pData;   // the actual array of data
  152.     int m_nSize;     // # of elements (upperBound - 1)
  153.     int m_nMaxSize;  // max allocated
  154.     int m_nGrowBy;   // grow amount
  155.  
  156. public:
  157.     ~CWordArray();
  158.  
  159.     void Serialize(CArchive&);
  160. #ifdef _DEBUG
  161.     void Dump(CDumpContext&) const;
  162.     void AssertValid() const;
  163. #endif
  164. };
  165.  
  166.  
  167. ////////////////////////////////////////////////////////////////////////////
  168.  
  169. class CDWordArray : public CObject
  170. {
  171.  
  172.     DECLARE_SERIAL(CDWordArray)
  173. public:
  174.  
  175. // Construction
  176.     CDWordArray();
  177.  
  178. // Attributes
  179.     int GetSize() const;
  180.     int GetUpperBound() const;
  181.     void SetSize(int nNewSize, int nGrowBy = -1);
  182.  
  183. // Operations
  184.     // Clean up
  185.     void FreeExtra();
  186.     void RemoveAll();
  187.  
  188.     // Accessing elements
  189.     DWORD GetAt(int nIndex) const;
  190.     void SetAt(int nIndex, DWORD newElement);
  191.     DWORD& ElementAt(int nIndex);
  192.  
  193.     // Potentially growing the array
  194.     void SetAtGrow(int nIndex, DWORD newElement);
  195.     int Add(DWORD newElement);
  196.  
  197.     // overloaded operator helpers
  198.     DWORD operator[](int nIndex) const;
  199.     DWORD& operator[](int nIndex);
  200.  
  201.     // Operations that move elements around
  202.     void InsertAt(int nIndex, DWORD newElement, int nCount = 1);
  203.     void RemoveAt(int nIndex, int nCount = 1);
  204.     void InsertAt(int nStartIndex, CDWordArray* pNewArray);
  205.  
  206. // Implementation
  207. protected:
  208.     DWORD* m_pData;   // the actual array of data
  209.     int m_nSize;     // # of elements (upperBound - 1)
  210.     int m_nMaxSize;  // max allocated
  211.     int m_nGrowBy;   // grow amount
  212.  
  213. public:
  214.     ~CDWordArray();
  215.  
  216.     void Serialize(CArchive&);
  217. #ifdef _DEBUG
  218.     void Dump(CDumpContext&) const;
  219.     void AssertValid() const;
  220. #endif
  221. };
  222.  
  223.  
  224. ////////////////////////////////////////////////////////////////////////////
  225.  
  226. class CUIntArray : public CObject
  227. {
  228.  
  229.     DECLARE_DYNAMIC(CUIntArray)
  230. public:
  231.  
  232. // Construction
  233.     CUIntArray();
  234.  
  235. // Attributes
  236.     int GetSize() const;
  237.     int GetUpperBound() const;
  238.     void SetSize(int nNewSize, int nGrowBy = -1);
  239.  
  240. // Operations
  241.     // Clean up
  242.     void FreeExtra();
  243.     void RemoveAll();
  244.  
  245.     // Accessing elements
  246.     UINT GetAt(int nIndex) const;
  247.     void SetAt(int nIndex, UINT newElement);
  248.     UINT& ElementAt(int nIndex);
  249.  
  250.     // Potentially growing the array
  251.     void SetAtGrow(int nIndex, UINT newElement);
  252.     int Add(UINT newElement);
  253.  
  254.     // overloaded operator helpers
  255.     UINT operator[](int nIndex) const;
  256.     UINT& operator[](int nIndex);
  257.  
  258.     // Operations that move elements around
  259.     void InsertAt(int nIndex, UINT newElement, int nCount = 1);
  260.     void RemoveAt(int nIndex, int nCount = 1);
  261.     void InsertAt(int nStartIndex, CUIntArray* pNewArray);
  262.  
  263. // Implementation
  264. protected:
  265.     UINT* m_pData;   // the actual array of data
  266.     int m_nSize;     // # of elements (upperBound - 1)
  267.     int m_nMaxSize;  // max allocated
  268.     int m_nGrowBy;   // grow amount
  269.  
  270. public:
  271.     ~CUIntArray();
  272. #ifdef _DEBUG
  273.     void Dump(CDumpContext&) const;
  274.     void AssertValid() const;
  275. #endif
  276. };
  277.  
  278.  
  279. ////////////////////////////////////////////////////////////////////////////
  280.  
  281. class CPtrArray : public CObject
  282. {
  283.  
  284.     DECLARE_DYNAMIC(CPtrArray)
  285. public:
  286.  
  287. // Construction
  288.     CPtrArray();
  289.  
  290. // Attributes
  291.     int GetSize() const;
  292.     int GetUpperBound() const;
  293.     void SetSize(int nNewSize, int nGrowBy = -1);
  294.  
  295. // Operations
  296.     // Clean up
  297.     void FreeExtra();
  298.     void RemoveAll();
  299.  
  300.     // Accessing elements
  301.     void* GetAt(int nIndex) const;
  302.     void SetAt(int nIndex, void* newElement);
  303.     void*& ElementAt(int nIndex);
  304.  
  305.     // Potentially growing the array
  306.     void SetAtGrow(int nIndex, void* newElement);
  307.     int Add(void* newElement);
  308.  
  309.     // overloaded operator helpers
  310.     void* operator[](int nIndex) const;
  311.     void*& operator[](int nIndex);
  312.  
  313.     // Operations that move elements around
  314.     void InsertAt(int nIndex, void* newElement, int nCount = 1);
  315.     void RemoveAt(int nIndex, int nCount = 1);
  316.     void InsertAt(int nStartIndex, CPtrArray* pNewArray);
  317.  
  318. // Implementation
  319. protected:
  320.     void** m_pData;   // the actual array of data
  321.     int m_nSize;     // # of elements (upperBound - 1)
  322.     int m_nMaxSize;  // max allocated
  323.     int m_nGrowBy;   // grow amount
  324.  
  325. public:
  326.     ~CPtrArray();
  327. #ifdef _DEBUG
  328.     void Dump(CDumpContext&) const;
  329.     void AssertValid() const;
  330. #endif
  331. };
  332.  
  333.  
  334. ////////////////////////////////////////////////////////////////////////////
  335.  
  336. class CObArray : public CObject
  337. {
  338.  
  339.     DECLARE_SERIAL(CObArray)
  340. public:
  341.  
  342. // Construction
  343.     CObArray();
  344.  
  345. // Attributes
  346.     int GetSize() const;
  347.     int GetUpperBound() const;
  348.     void SetSize(int nNewSize, int nGrowBy = -1);
  349.  
  350. // Operations
  351.     // Clean up
  352.     void FreeExtra();
  353.     void RemoveAll();
  354.  
  355.     // Accessing elements
  356.     CObject* GetAt(int nIndex) const;
  357.     void SetAt(int nIndex, CObject* newElement);
  358.     CObject*& ElementAt(int nIndex);
  359.  
  360.     // Potentially growing the array
  361.     void SetAtGrow(int nIndex, CObject* newElement);
  362.     int Add(CObject* newElement);
  363.  
  364.     // overloaded operator helpers
  365.     CObject* operator[](int nIndex) const;
  366.     CObject*& operator[](int nIndex);
  367.  
  368.     // Operations that move elements around
  369.     void InsertAt(int nIndex, CObject* newElement, int nCount = 1);
  370.     void RemoveAt(int nIndex, int nCount = 1);
  371.     void InsertAt(int nStartIndex, CObArray* pNewArray);
  372.  
  373. // Implementation
  374. protected:
  375.     CObject** m_pData;   // the actual array of data
  376.     int m_nSize;     // # of elements (upperBound - 1)
  377.     int m_nMaxSize;  // max allocated
  378.     int m_nGrowBy;   // grow amount
  379.  
  380. public:
  381.     ~CObArray();
  382.  
  383.     void Serialize(CArchive&);
  384. #ifdef _DEBUG
  385.     void Dump(CDumpContext&) const;
  386.     void AssertValid() const;
  387. #endif
  388. };
  389.  
  390.  
  391. ////////////////////////////////////////////////////////////////////////////
  392.  
  393. class CStringArray : public CObject
  394. {
  395.  
  396.     DECLARE_SERIAL(CStringArray)
  397. public:
  398.  
  399. // Construction
  400.     CStringArray();
  401.  
  402. // Attributes
  403.     int GetSize() const;
  404.     int GetUpperBound() const;
  405.     void SetSize(int nNewSize, int nGrowBy = -1);
  406.  
  407. // Operations
  408.     // Clean up
  409.     void FreeExtra();
  410.     void RemoveAll();
  411.  
  412.     // Accessing elements
  413.     CString GetAt(int nIndex) const;
  414.     void SetAt(int nIndex, const char* newElement);
  415.     CString& ElementAt(int nIndex);
  416.  
  417.     // Potentially growing the array
  418.     void SetAtGrow(int nIndex, const char* newElement);
  419.     int Add(const char* newElement);
  420.  
  421.     // overloaded operator helpers
  422.     CString operator[](int nIndex) const;
  423.     CString& operator[](int nIndex);
  424.  
  425.     // Operations that move elements around
  426.     void InsertAt(int nIndex, const char* newElement, int nCount = 1);
  427.     void RemoveAt(int nIndex, int nCount = 1);
  428.     void InsertAt(int nStartIndex, CStringArray* pNewArray);
  429.  
  430. // Implementation
  431. protected:
  432.     CString* m_pData;   // the actual array of data
  433.     int m_nSize;     // # of elements (upperBound - 1)
  434.     int m_nMaxSize;  // max allocated
  435.     int m_nGrowBy;   // grow amount
  436.  
  437. public:
  438.     ~CStringArray();
  439.  
  440.     void Serialize(CArchive&);
  441. #ifdef _DEBUG
  442.     void Dump(CDumpContext&) const;
  443.     void AssertValid() const;
  444. #endif
  445. };
  446.  
  447.  
  448. /////////////////////////////////////////////////////////////////////////////
  449.  
  450. class CPtrList : public CObject
  451. {
  452.  
  453.     DECLARE_DYNAMIC(CPtrList)
  454.  
  455. protected:
  456.     struct CNode
  457.     {
  458.         CNode* pNext;
  459.         CNode* pPrev;
  460.         void* data;
  461.     };
  462. public:
  463.  
  464. // Construction
  465.     CPtrList(int nBlockSize=10);
  466.  
  467. // Attributes (head and tail)
  468.     // count of elements
  469.     int GetCount() const;
  470.     BOOL IsEmpty() const;
  471.  
  472.     // peek at head or tail
  473.     void*& GetHead();
  474.     void* GetHead() const;
  475.     void*& GetTail();
  476.     void* GetTail() const;
  477.  
  478. // Operations
  479.     // get head or tail (and remove it) - don't call on empty list !
  480.     void* RemoveHead();
  481.     void* RemoveTail();
  482.  
  483.     // add before head or after tail
  484.     POSITION AddHead(void* newElement);
  485.     POSITION AddTail(void* newElement);
  486.  
  487.     // add another list of elements before head or after tail
  488.     void AddHead(CPtrList* pNewList);
  489.     void AddTail(CPtrList* pNewList);
  490.  
  491.     // remove all elements
  492.     void RemoveAll();
  493.  
  494.     // iteration
  495.     POSITION GetHeadPosition() const;
  496.     POSITION GetTailPosition() const;
  497.     void*& GetNext(POSITION& rPosition); // return *Position++
  498.     void* GetNext(POSITION& rPosition) const; // return *Position++
  499.     void*& GetPrev(POSITION& rPosition); // return *Position--
  500.     void* GetPrev(POSITION& rPosition) const; // return *Position--
  501.  
  502.     // getting/modifying an element at a given position
  503.     void*& GetAt(POSITION position);
  504.     void* GetAt(POSITION position) const;
  505.     void SetAt(POSITION pos, void* newElement);
  506.     void RemoveAt(POSITION position);
  507.  
  508.     // inserting before or after a given position
  509.     POSITION InsertBefore(POSITION position, void* newElement);
  510.     POSITION InsertAfter(POSITION position, void* newElement);
  511.  
  512.     // helper functions (note: O(n) speed)
  513.     POSITION Find(void* searchValue, POSITION startAfter = NULL) const;
  514.                         // defaults to starting at the HEAD
  515.                         // return NULL if not found
  516.     POSITION FindIndex(int nIndex) const;
  517.                         // get the 'nIndex'th element (may return NULL)
  518.  
  519. // Implementation
  520. protected:
  521.     CNode* m_pNodeHead;
  522.     CNode* m_pNodeTail;
  523.     int m_nCount;
  524.     CNode* m_pNodeFree;
  525.     struct CPlex* m_pBlocks;
  526.     int m_nBlockSize;
  527.  
  528.     CNode* NewNode(CNode*, CNode*);
  529.     void FreeNode(CNode*);
  530.  
  531. public:
  532.     ~CPtrList();
  533. #ifdef _DEBUG
  534.     void Dump(CDumpContext&) const;
  535.     void AssertValid() const;
  536. #endif
  537. };
  538.  
  539.  
  540. /////////////////////////////////////////////////////////////////////////////
  541.  
  542. class CObList : public CObject
  543. {
  544.  
  545.     DECLARE_SERIAL(CObList)
  546.  
  547. protected:
  548.     struct CNode
  549.     {
  550.         CNode* pNext;
  551.         CNode* pPrev;
  552.         CObject* data;
  553.     };
  554. public:
  555.  
  556. // Construction
  557.     CObList(int nBlockSize=10);
  558.  
  559. // Attributes (head and tail)
  560.     // count of elements
  561.     int GetCount() const;
  562.     BOOL IsEmpty() const;
  563.  
  564.     // peek at head or tail
  565.     CObject*& GetHead();
  566.     CObject* GetHead() const;
  567.     CObject*& GetTail();
  568.     CObject* GetTail() const;
  569.  
  570. // Operations
  571.     // get head or tail (and remove it) - don't call on empty list !
  572.     CObject* RemoveHead();
  573.     CObject* RemoveTail();
  574.  
  575.     // add before head or after tail
  576.     POSITION AddHead(CObject* newElement);
  577.     POSITION AddTail(CObject* newElement);
  578.  
  579.     // add another list of elements before head or after tail
  580.     void AddHead(CObList* pNewList);
  581.     void AddTail(CObList* pNewList);
  582.  
  583.     // remove all elements
  584.     void RemoveAll();
  585.  
  586.     // iteration
  587.     POSITION GetHeadPosition() const;
  588.     POSITION GetTailPosition() const;
  589.     CObject*& GetNext(POSITION& rPosition); // return *Position++
  590.     CObject* GetNext(POSITION& rPosition) const; // return *Position++
  591.     CObject*& GetPrev(POSITION& rPosition); // return *Position--
  592.     CObject* GetPrev(POSITION& rPosition) const; // return *Position--
  593.  
  594.     // getting/modifying an element at a given position
  595.     CObject*& GetAt(POSITION position);
  596.     CObject* GetAt(POSITION position) const;
  597.     void SetAt(POSITION pos, CObject* newElement);
  598.     void RemoveAt(POSITION position);
  599.  
  600.     // inserting before or after a given position
  601.     POSITION InsertBefore(POSITION position, CObject* newElement);
  602.     POSITION InsertAfter(POSITION position, CObject* newElement);
  603.  
  604.     // helper functions (note: O(n) speed)
  605.     POSITION Find(CObject* searchValue, POSITION startAfter = NULL) const;
  606.                         // defaults to starting at the HEAD
  607.                         // return NULL if not found
  608.     POSITION FindIndex(int nIndex) const;
  609.                         // get the 'nIndex'th element (may return NULL)
  610.  
  611. // Implementation
  612. protected:
  613.     CNode* m_pNodeHead;
  614.     CNode* m_pNodeTail;
  615.     int m_nCount;
  616.     CNode* m_pNodeFree;
  617.     struct CPlex* m_pBlocks;
  618.     int m_nBlockSize;
  619.  
  620.     CNode* NewNode(CNode*, CNode*);
  621.     void FreeNode(CNode*);
  622.  
  623. public:
  624.     ~CObList();
  625.  
  626.     void Serialize(CArchive&);
  627. #ifdef _DEBUG
  628.     void Dump(CDumpContext&) const;
  629.     void AssertValid() const;
  630. #endif
  631. };
  632.  
  633.  
  634. /////////////////////////////////////////////////////////////////////////////
  635.  
  636. class CStringList : public CObject
  637. {
  638.  
  639.     DECLARE_SERIAL(CStringList)
  640.  
  641. protected:
  642.     struct CNode
  643.     {
  644.         CNode* pNext;
  645.         CNode* pPrev;
  646.         CString data;
  647.     };
  648. public:
  649.  
  650. // Construction
  651.     CStringList(int nBlockSize=10);
  652.  
  653. // Attributes (head and tail)
  654.     // count of elements
  655.     int GetCount() const;
  656.     BOOL IsEmpty() const;
  657.  
  658.     // peek at head or tail
  659.     CString& GetHead();
  660.     CString GetHead() const;
  661.     CString& GetTail();
  662.     CString GetTail() const;
  663.  
  664. // Operations
  665.     // get head or tail (and remove it) - don't call on empty list !
  666.     CString RemoveHead();
  667.     CString RemoveTail();
  668.  
  669.     // add before head or after tail
  670.     POSITION AddHead(const char* newElement);
  671.     POSITION AddTail(const char* newElement);
  672.  
  673.     // add another list of elements before head or after tail
  674.     void AddHead(CStringList* pNewList);
  675.     void AddTail(CStringList* pNewList);
  676.  
  677.     // remove all elements
  678.     void RemoveAll();
  679.  
  680.     // iteration
  681.     POSITION GetHeadPosition() const;
  682.     POSITION GetTailPosition() const;
  683.     CString& GetNext(POSITION& rPosition); // return *Position++
  684.     CString GetNext(POSITION& rPosition) const; // return *Position++
  685.     CString& GetPrev(POSITION& rPosition); // return *Position--
  686.     CString GetPrev(POSITION& rPosition) const; // return *Position--
  687.  
  688.     // getting/modifying an element at a given position
  689.     CString& GetAt(POSITION position);
  690.     CString GetAt(POSITION position) const;
  691.     void SetAt(POSITION pos, const char* newElement);
  692.     void RemoveAt(POSITION position);
  693.  
  694.     // inserting before or after a given position
  695.     POSITION InsertBefore(POSITION position, const char* newElement);
  696.     POSITION InsertAfter(POSITION position, const char* newElement);
  697.  
  698.     // helper functions (note: O(n) speed)
  699.     POSITION Find(const char* searchValue, POSITION startAfter = NULL) const;
  700.                         // defaults to starting at the HEAD
  701.                         // return NULL if not found
  702.     POSITION FindIndex(int nIndex) const;
  703.                         // get the 'nIndex'th element (may return NULL)
  704.  
  705. // Implementation
  706. protected:
  707.     CNode* m_pNodeHead;
  708.     CNode* m_pNodeTail;
  709.     int m_nCount;
  710.     CNode* m_pNodeFree;
  711.     struct CPlex* m_pBlocks;
  712.     int m_nBlockSize;
  713.  
  714.     CNode* NewNode(CNode*, CNode*);
  715.     void FreeNode(CNode*);
  716.  
  717. public:
  718.     ~CStringList();
  719.  
  720.     void Serialize(CArchive&);
  721. #ifdef _DEBUG
  722.     void Dump(CDumpContext&) const;
  723.     void AssertValid() const;
  724. #endif
  725. };
  726.  
  727.  
  728. /////////////////////////////////////////////////////////////////////////////
  729.  
  730. class CMapWordToPtr : public CObject
  731. {
  732.  
  733.     DECLARE_DYNAMIC(CMapWordToPtr)
  734. protected:
  735.     // Association
  736.     struct CAssoc
  737.     {
  738.         CAssoc* pNext;
  739.         UINT nHashValue;  // needed for efficient iteration
  740.         WORD key;
  741.         void* value;
  742.     };
  743. public:
  744.  
  745. // Construction
  746.     CMapWordToPtr(int nBlockSize=10);
  747.  
  748. // Attributes
  749.     // number of elements
  750.     int GetCount() const;
  751.     BOOL IsEmpty() const;
  752.  
  753.     // Lookup
  754.     BOOL Lookup(WORD key, void*& rValue) const;
  755.  
  756. // Operations
  757.     // Lookup and add if not there
  758.     void*& operator[](WORD key);
  759.  
  760.     // add a new (key, value) pair
  761.     void SetAt(WORD key, void* newValue);
  762.  
  763.     // removing existing (key, ?) pair
  764.     BOOL RemoveKey(WORD key);
  765.     void RemoveAll();
  766.  
  767.     // iterating all (key, value) pairs
  768.     POSITION GetStartPosition() const;
  769.     void GetNextAssoc(POSITION& rNextPosition, WORD& rKey, void*& rValue) const;
  770.  
  771.     // advanced features for derived classes
  772.     UINT GetHashTableSize() const;
  773.     void InitHashTable(UINT hashSize);
  774.  
  775. // Overridables: special non-virtual (see map implementation for details)
  776.     // Routine used to user-provided hash keys
  777.     UINT HashKey(WORD key) const;
  778.  
  779. // Implementation
  780. protected:
  781.     CAssoc** m_pHashTable;
  782.     UINT m_nHashTableSize;
  783.     int m_nCount;
  784.     CAssoc* m_pFreeList;
  785.     struct CPlex* m_pBlocks;
  786.     int m_nBlockSize;
  787.  
  788.     CAssoc* NewAssoc();
  789.     void FreeAssoc(CAssoc*);
  790.     CAssoc* GetAssocAt(WORD, UINT&) const;
  791.  
  792. public:
  793.     ~CMapWordToPtr();
  794. #ifdef _DEBUG
  795.     void Dump(CDumpContext&) const;
  796.     void AssertValid() const;
  797. #endif
  798. };
  799.  
  800.  
  801. /////////////////////////////////////////////////////////////////////////////
  802.  
  803. class CMapPtrToWord : public CObject
  804. {
  805.  
  806.     DECLARE_DYNAMIC(CMapPtrToWord)
  807. protected:
  808.     // Association
  809.     struct CAssoc
  810.     {
  811.         CAssoc* pNext;
  812.         UINT nHashValue;  // needed for efficient iteration
  813.         void* key;
  814.         WORD value;
  815.     };
  816. public:
  817.  
  818. // Construction
  819.     CMapPtrToWord(int nBlockSize=10);
  820.  
  821. // Attributes
  822.     // number of elements
  823.     int GetCount() const;
  824.     BOOL IsEmpty() const;
  825.  
  826.     // Lookup
  827.     BOOL Lookup(void* key, WORD& rValue) const;
  828.  
  829. // Operations
  830.     // Lookup and add if not there
  831.     WORD& operator[](void* key);
  832.  
  833.     // add a new (key, value) pair
  834.     void SetAt(void* key, WORD newValue);
  835.  
  836.     // removing existing (key, ?) pair
  837.     BOOL RemoveKey(void* key);
  838.     void RemoveAll();
  839.  
  840.     // iterating all (key, value) pairs
  841.     POSITION GetStartPosition() const;
  842.     void GetNextAssoc(POSITION& rNextPosition, void*& rKey, WORD& rValue) const;
  843.  
  844.     // advanced features for derived classes
  845.     UINT GetHashTableSize() const;
  846.     void InitHashTable(UINT hashSize);
  847.  
  848. // Overridables: special non-virtual (see map implementation for details)
  849.     // Routine used to user-provided hash keys
  850.     UINT HashKey(void* key) const;
  851.  
  852. // Implementation
  853. protected:
  854.     CAssoc** m_pHashTable;
  855.     UINT m_nHashTableSize;
  856.     int m_nCount;
  857.     CAssoc* m_pFreeList;
  858.     struct CPlex* m_pBlocks;
  859.     int m_nBlockSize;
  860.  
  861.     CAssoc* NewAssoc();
  862.     void FreeAssoc(CAssoc*);
  863.     CAssoc* GetAssocAt(void*, UINT&) const;
  864.  
  865. public:
  866.     ~CMapPtrToWord();
  867. #ifdef _DEBUG
  868.     void Dump(CDumpContext&) const;
  869.     void AssertValid() const;
  870. #endif
  871. };
  872.  
  873.  
  874. /////////////////////////////////////////////////////////////////////////////
  875.  
  876. class CMapPtrToPtr : public CObject
  877. {
  878.  
  879.     DECLARE_DYNAMIC(CMapPtrToPtr)
  880. protected:
  881.     // Association
  882.     struct CAssoc
  883.     {
  884.         CAssoc* pNext;
  885.         UINT nHashValue;  // needed for efficient iteration
  886.         void* key;
  887.         void* value;
  888.     };
  889. public:
  890.  
  891. // Construction
  892.     CMapPtrToPtr(int nBlockSize=10);
  893.  
  894. // Attributes
  895.     // number of elements
  896.     int GetCount() const;
  897.     BOOL IsEmpty() const;
  898.  
  899.     // Lookup
  900.     BOOL Lookup(void* key, void*& rValue) const;
  901.  
  902. // Operations
  903.     // Lookup and add if not there
  904.     void*& operator[](void* key);
  905.  
  906.     // add a new (key, value) pair
  907.     void SetAt(void* key, void* newValue);
  908.  
  909.     // removing existing (key, ?) pair
  910.     BOOL RemoveKey(void* key);
  911.     void RemoveAll();
  912.  
  913.     // iterating all (key, value) pairs
  914.     POSITION GetStartPosition() const;
  915.     void GetNextAssoc(POSITION& rNextPosition, void*& rKey, void*& rValue) const;
  916.  
  917.     // advanced features for derived classes
  918.     UINT GetHashTableSize() const;
  919.     void InitHashTable(UINT hashSize);
  920.  
  921. // Overridables: special non-virtual (see map implementation for details)
  922.     // Routine used to user-provided hash keys
  923.     UINT HashKey(void* key) const;
  924.  
  925. // Implementation
  926. protected:
  927.     CAssoc** m_pHashTable;
  928.     UINT m_nHashTableSize;
  929.     int m_nCount;
  930.     CAssoc* m_pFreeList;
  931.     struct CPlex* m_pBlocks;
  932.     int m_nBlockSize;
  933.  
  934.     CAssoc* NewAssoc();
  935.     void FreeAssoc(CAssoc*);
  936.     CAssoc* GetAssocAt(void*, UINT&) const;
  937.  
  938. public:
  939.     ~CMapPtrToPtr();
  940. #ifdef _DEBUG
  941.     void Dump(CDumpContext&) const;
  942.     void AssertValid() const;
  943. #endif
  944. };
  945.  
  946.  
  947. /////////////////////////////////////////////////////////////////////////////
  948.  
  949. class CMapWordToOb : public CObject
  950. {
  951.  
  952.     DECLARE_SERIAL(CMapWordToOb)
  953. protected:
  954.     // Association
  955.     struct CAssoc
  956.     {
  957.         CAssoc* pNext;
  958.         UINT nHashValue;  // needed for efficient iteration
  959.         WORD key;
  960.         CObject* value;
  961.     };
  962. public:
  963.  
  964. // Construction
  965.     CMapWordToOb(int nBlockSize=10);
  966.  
  967. // Attributes
  968.     // number of elements
  969.     int GetCount() const;
  970.     BOOL IsEmpty() const;
  971.  
  972.     // Lookup
  973.     BOOL Lookup(WORD key, CObject*& rValue) const;
  974.  
  975. // Operations
  976.     // Lookup and add if not there
  977.     CObject*& operator[](WORD key);
  978.  
  979.     // add a new (key, value) pair
  980.     void SetAt(WORD key, CObject* newValue);
  981.  
  982.     // removing existing (key, ?) pair
  983.     BOOL RemoveKey(WORD key);
  984.     void RemoveAll();
  985.  
  986.     // iterating all (key, value) pairs
  987.     POSITION GetStartPosition() const;
  988.     void GetNextAssoc(POSITION& rNextPosition, WORD& rKey, CObject*& rValue) const;
  989.  
  990.     // advanced features for derived classes
  991.     UINT GetHashTableSize() const;
  992.     void InitHashTable(UINT hashSize);
  993.  
  994. // Overridables: special non-virtual (see map implementation for details)
  995.     // Routine used to user-provided hash keys
  996.     UINT HashKey(WORD key) const;
  997.  
  998. // Implementation
  999. protected:
  1000.     CAssoc** m_pHashTable;
  1001.     UINT m_nHashTableSize;
  1002.     int m_nCount;
  1003.     CAssoc* m_pFreeList;
  1004.     struct CPlex* m_pBlocks;
  1005.     int m_nBlockSize;
  1006.  
  1007.     CAssoc* NewAssoc();
  1008.     void FreeAssoc(CAssoc*);
  1009.     CAssoc* GetAssocAt(WORD, UINT&) const;
  1010.  
  1011. public:
  1012.     ~CMapWordToOb();
  1013.  
  1014.     void Serialize(CArchive&);
  1015. #ifdef _DEBUG
  1016.     void Dump(CDumpContext&) const;
  1017.     void AssertValid() const;
  1018. #endif
  1019. };
  1020.  
  1021.  
  1022. /////////////////////////////////////////////////////////////////////////////
  1023.  
  1024. class CMapStringToPtr : public CObject
  1025. {
  1026.  
  1027.     DECLARE_DYNAMIC(CMapStringToPtr)
  1028. protected:
  1029.     // Association
  1030.     struct CAssoc
  1031.     {
  1032.         CAssoc* pNext;
  1033.         UINT nHashValue;  // needed for efficient iteration
  1034.         CString key;
  1035.         void* value;
  1036.     };
  1037. public:
  1038.  
  1039. // Construction
  1040.     CMapStringToPtr(int nBlockSize=10);
  1041.  
  1042. // Attributes
  1043.     // number of elements
  1044.     int GetCount() const;
  1045.     BOOL IsEmpty() const;
  1046.  
  1047.     // Lookup
  1048.     BOOL Lookup(const char* key, void*& rValue) const;
  1049.  
  1050. // Operations
  1051.     // Lookup and add if not there
  1052.     void*& operator[](const char* key);
  1053.  
  1054.     // add a new (key, value) pair
  1055.     void SetAt(const char* key, void* newValue);
  1056.  
  1057.     // removing existing (key, ?) pair
  1058.     BOOL RemoveKey(const char* key);
  1059.     void RemoveAll();
  1060.  
  1061.     // iterating all (key, value) pairs
  1062.     POSITION GetStartPosition() const;
  1063.     void GetNextAssoc(POSITION& rNextPosition, CString& rKey, void*& rValue) const;
  1064.  
  1065.     // advanced features for derived classes
  1066.     UINT GetHashTableSize() const;
  1067.     void InitHashTable(UINT hashSize);
  1068.  
  1069. // Overridables: special non-virtual (see map implementation for details)
  1070.     // Routine used to user-provided hash keys
  1071.     UINT HashKey(const char* key) const;
  1072.  
  1073. // Implementation
  1074. protected:
  1075.     CAssoc** m_pHashTable;
  1076.     UINT m_nHashTableSize;
  1077.     int m_nCount;
  1078.     CAssoc* m_pFreeList;
  1079.     struct CPlex* m_pBlocks;
  1080.     int m_nBlockSize;
  1081.  
  1082.     CAssoc* NewAssoc();
  1083.     void FreeAssoc(CAssoc*);
  1084.     CAssoc* GetAssocAt(const char*, UINT&) const;
  1085.  
  1086. public:
  1087.     ~CMapStringToPtr();
  1088. #ifdef _DEBUG
  1089.     void Dump(CDumpContext&) const;
  1090.     void AssertValid() const;
  1091. #endif
  1092. };
  1093.  
  1094.  
  1095. /////////////////////////////////////////////////////////////////////////////
  1096.  
  1097. class CMapStringToOb : public CObject
  1098. {
  1099.  
  1100.     DECLARE_SERIAL(CMapStringToOb)
  1101. protected:
  1102.     // Association
  1103.     struct CAssoc
  1104.     {
  1105.         CAssoc* pNext;
  1106.         UINT nHashValue;  // needed for efficient iteration
  1107.         CString key;
  1108.         CObject* value;
  1109.     };
  1110. public:
  1111.  
  1112. // Construction
  1113.     CMapStringToOb(int nBlockSize=10);
  1114.  
  1115. // Attributes
  1116.     // number of elements
  1117.     int GetCount() const;
  1118.     BOOL IsEmpty() const;
  1119.  
  1120.     // Lookup
  1121.     BOOL Lookup(const char* key, CObject*& rValue) const;
  1122.  
  1123. // Operations
  1124.     // Lookup and add if not there
  1125.     CObject*& operator[](const char* key);
  1126.  
  1127.     // add a new (key, value) pair
  1128.     void SetAt(const char* key, CObject* newValue);
  1129.  
  1130.     // removing existing (key, ?) pair
  1131.     BOOL RemoveKey(const char* key);
  1132.     void RemoveAll();
  1133.  
  1134.     // iterating all (key, value) pairs
  1135.     POSITION GetStartPosition() const;
  1136.     void GetNextAssoc(POSITION& rNextPosition, CString& rKey, CObject*& rValue) const;
  1137.  
  1138.     // advanced features for derived classes
  1139.     UINT GetHashTableSize() const;
  1140.     void InitHashTable(UINT hashSize);
  1141.  
  1142. // Overridables: special non-virtual (see map implementation for details)
  1143.     // Routine used to user-provided hash keys
  1144.     UINT HashKey(const char* key) const;
  1145.  
  1146. // Implementation
  1147. protected:
  1148.     CAssoc** m_pHashTable;
  1149.     UINT m_nHashTableSize;
  1150.     int m_nCount;
  1151.     CAssoc* m_pFreeList;
  1152.     struct CPlex* m_pBlocks;
  1153.     int m_nBlockSize;
  1154.  
  1155.     CAssoc* NewAssoc();
  1156.     void FreeAssoc(CAssoc*);
  1157.     CAssoc* GetAssocAt(const char*, UINT&) const;
  1158.  
  1159. public:
  1160.     ~CMapStringToOb();
  1161.  
  1162.     void Serialize(CArchive&);
  1163. #ifdef _DEBUG
  1164.     void Dump(CDumpContext&) const;
  1165.     void AssertValid() const;
  1166. #endif
  1167. };
  1168.  
  1169.  
  1170. /////////////////////////////////////////////////////////////////////////////
  1171.  
  1172. class CMapStringToString : public CObject
  1173. {
  1174.  
  1175.     DECLARE_SERIAL(CMapStringToString)
  1176. protected:
  1177.     // Association
  1178.     struct CAssoc
  1179.     {
  1180.         CAssoc* pNext;
  1181.         UINT nHashValue;  // needed for efficient iteration
  1182.         CString key;
  1183.         CString value;
  1184.     };
  1185. public:
  1186.  
  1187. // Construction
  1188.     CMapStringToString(int nBlockSize=10);
  1189.  
  1190. // Attributes
  1191.     // number of elements
  1192.     int GetCount() const;
  1193.     BOOL IsEmpty() const;
  1194.  
  1195.     // Lookup
  1196.     BOOL Lookup(const char* key, CString& rValue) const;
  1197.  
  1198. // Operations
  1199.     // Lookup and add if not there
  1200.     CString& operator[](const char* key);
  1201.  
  1202.     // add a new (key, value) pair
  1203.     void SetAt(const char* key, const char* newValue);
  1204.  
  1205.     // removing existing (key, ?) pair
  1206.     BOOL RemoveKey(const char* key);
  1207.     void RemoveAll();
  1208.  
  1209.     // iterating all (key, value) pairs
  1210.     POSITION GetStartPosition() const;
  1211.     void GetNextAssoc(POSITION& rNextPosition, CString& rKey, CString& rValue) const;
  1212.  
  1213.     // advanced features for derived classes
  1214.     UINT GetHashTableSize() const;
  1215.     void InitHashTable(UINT hashSize);
  1216.  
  1217. // Overridables: special non-virtual (see map implementation for details)
  1218.     // Routine used to user-provided hash keys
  1219.     UINT HashKey(const char* key) const;
  1220.  
  1221. // Implementation
  1222. protected:
  1223.     CAssoc** m_pHashTable;
  1224.     UINT m_nHashTableSize;
  1225.     int m_nCount;
  1226.     CAssoc* m_pFreeList;
  1227.     struct CPlex* m_pBlocks;
  1228.     int m_nBlockSize;
  1229.  
  1230.     CAssoc* NewAssoc();
  1231.     void FreeAssoc(CAssoc*);
  1232.     CAssoc* GetAssocAt(const char*, UINT&) const;
  1233.  
  1234. public:
  1235.     ~CMapStringToString();
  1236.  
  1237.     void Serialize(CArchive&);
  1238. #ifdef _DEBUG
  1239.     void Dump(CDumpContext&) const;
  1240.     void AssertValid() const;
  1241. #endif
  1242. };
  1243.  
  1244. /////////////////////////////////////////////////////////////////////////////
  1245. // Inline function declarations
  1246.  
  1247. #ifdef _AFX_ENABLE_INLINES
  1248. #define _AFXCOLL_INLINE inline
  1249. #include "afxcoll.inl"
  1250. #endif
  1251.  
  1252. #undef AFXAPP_DATA
  1253. #define AFXAPP_DATA     NEAR
  1254.  
  1255. #endif //!__AFXCOLL_H__
  1256.  
  1257.