Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1254 lines
29 KiB

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