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.

1530 lines
35 KiB

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