afxcoll.h 34 KB

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