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.

379 lines
7.7 KiB

  1. #ifndef __COLLMGR_HPP__
  2. #define __COLLMGR_HPP__
  3. /*++
  4. Copyright (C) 2000 Microsoft Corporation
  5. All rights reserved.
  6. Module Name:
  7. collmgr.hpp
  8. Abstract:
  9. This file contains the declaration of a generic
  10. linked list which could encapsulate any data type
  11. even if complex ones. The list is defined as a
  12. manager and a node. The manager manages the given
  13. nodes of that type.
  14. Author:
  15. Khaled Sedky (khaleds) 21-Jun-2000
  16. Revision History:
  17. --*/
  18. #ifndef __LDERROR_HPP__
  19. #include "lderror.hpp"
  20. #endif
  21. #ifndef __LDMGR_HPP__
  22. #include "ldmgr.hpp"
  23. #endif
  24. //
  25. // Forward Declarations
  26. //
  27. template <class E,class C> class TLstNd;
  28. template <class E,class C> class TLstMgr;
  29. //
  30. // E here is the element and C is a major content in this element.
  31. // or in other words the index of the element . It could be described
  32. // as the component by which the element is created or by which it
  33. // is compared against.C is the type used as a key for comparisons.
  34. //
  35. template <class E,class C> class TLstNd
  36. {
  37. //
  38. // Public methods of the class
  39. //
  40. public:
  41. friend class TLstMgr<E,C>;
  42. TLstNd<E,C>(
  43. VOID
  44. );
  45. //
  46. // Copy Constructor
  47. //
  48. TLstNd<E,C>(
  49. IN CONST TLstNd<E,C>&
  50. );
  51. //
  52. // Copy constructor based on the Element saved
  53. // in the list
  54. //
  55. TLstNd<E,C>(
  56. IN const E&
  57. );
  58. TLstNd<E,C>(
  59. IN E*
  60. );
  61. //
  62. // A Copy constructor based on the
  63. // component
  64. //
  65. TLstNd<E,C>(
  66. IN const C&
  67. );
  68. ~TLstNd<E,C>(
  69. VOID
  70. );
  71. const E&
  72. operator=(
  73. IN const E&
  74. );
  75. BOOL
  76. operator==(
  77. IN const E&
  78. ) const;
  79. BOOL
  80. operator==(
  81. IN const C&
  82. ) const;
  83. E&
  84. operator*(
  85. VOID
  86. );
  87. E*
  88. SetNodeData(
  89. IN E*
  90. );
  91. //
  92. // Private members and helper functions (if any)
  93. //
  94. private:
  95. E* m_pD;
  96. TLstNd<E,C> *m_pNext;
  97. TLstNd<E,C> *m_pPrev;
  98. };
  99. template <class E,class C> class TLstMgr : public TClassID,
  100. public TLd64BitDllsErrorHndlr
  101. {
  102. //
  103. // Public methods of the class
  104. //
  105. public:
  106. friend TLstNd<E,C>;
  107. //
  108. // To optimize the overhead of allocating
  109. // and Freeing memroy , the user of this
  110. // class might resort to using the FreeList
  111. // support which enable him to recycle nodes
  112. // when they are not longer required.
  113. //
  114. enum EListType
  115. {
  116. KFreeListSupport,
  117. KNoFreeListSupport,
  118. };
  119. //
  120. // Based on the index of the collection, Entries,
  121. // maybe or may not be unique. Based on this Flag
  122. // being set in the constructor, the List search
  123. // criteria is decided and so is the Appending
  124. // algorithm
  125. //
  126. enum EEntriesType
  127. {
  128. KUniqueEntries = 0,
  129. KNonUniqueEntries
  130. };
  131. TLstMgr<E,C>(
  132. IN typename TLstMgr<E,C>::EEntriesType ThisListEntriesType = TLstMgr<E,C>::KNonUniqueEntries,
  133. IN typename TLstMgr<E,C>::EListType ThisListType = TLstMgr<E,C>::KNoFreeListSupport,
  134. IN OUT HRESULT* hRes = NULL
  135. );
  136. ~TLstMgr<E,C>(
  137. VOID
  138. );
  139. TLstNd<E,C>*
  140. AppendListByElem(
  141. IN const E&
  142. );
  143. TLstNd<E,C>*
  144. AppendListByElem(
  145. IN E*
  146. );
  147. TLstNd<E,C>*
  148. AppendListByElem(
  149. IN const C &
  150. );
  151. HRESULT
  152. RmvElemFromList(
  153. IN const E&
  154. );
  155. HRESULT
  156. RmvElemFromList(
  157. IN const C&
  158. );
  159. HRESULT
  160. RmvElemAtPosFromList(
  161. IN DWORD
  162. );
  163. HRESULT
  164. RmvTail(
  165. VOID
  166. );
  167. HRESULT
  168. RmvHead(
  169. VOID
  170. );
  171. HRESULT
  172. DestructList(
  173. VOID
  174. );
  175. E&
  176. GetElementAtPos(
  177. IN DWORD
  178. ) const;
  179. E*
  180. GetElementAtPosByRef(
  181. IN DWORD
  182. ) const;
  183. E&
  184. operator[](
  185. IN DWORD
  186. ) const;
  187. TLstNd<E,C>*
  188. ElementInList(
  189. IN const C&
  190. ) const;
  191. BOOL
  192. HaveElements(
  193. VOID
  194. ) const;
  195. DWORD
  196. GetNumOfListNodes(
  197. VOID
  198. ) const;
  199. //
  200. // Private members and helper functions (if any)
  201. //
  202. private:
  203. TLstNd<E,C> *m_pHead;
  204. TLstNd<E,C> *m_pTail;
  205. DWORD m_cNumOfNodes;
  206. BOOL m_bUnique;
  207. //
  208. // To protect the linked list data members
  209. // in a multithread environment.
  210. //
  211. CRITICAL_SECTION *m_pLockSem;
  212. };
  213. template <class E,class C> class TLstItrtr : public TClassID
  214. {
  215. public:
  216. TLstItrtr<E,C>(
  217. IN const TLstMgr<E,C>&
  218. );
  219. ~TLstItrtr<E,C>();
  220. TLstNd<E,C>&
  221. operator*(
  222. VOID
  223. );
  224. TLstNd<E,C>&
  225. operator++(
  226. VOID
  227. );
  228. const
  229. TLstNd<E,C>
  230. operator++(
  231. int
  232. );
  233. TLstNd<E,C>&
  234. operator--(
  235. VOID
  236. );
  237. const
  238. TLstNd<E,C>
  239. operator--(
  240. int
  241. );
  242. private:
  243. TLstMgr<E,C> *m_pItrtdMgrPrxy;
  244. TLstNd<E,C> *m_pCrntNode;
  245. };
  246. //
  247. // This is an abstract class which never
  248. // get instantiated. Any Element other than
  249. // primitive Data types , has to inherit from
  250. // this class . There are some mandatory
  251. // methods that need to be implemented
  252. //
  253. class TGenericElement : public TRefCntMgr
  254. {
  255. public:
  256. //
  257. // A BOOL variable indicating Validity
  258. // of the object should be defined here.
  259. // This should be set by SetValidity and
  260. // queried by Validate.
  261. //
  262. TGenericElement()
  263. {};
  264. //
  265. // We internally create the elements in
  266. // the list to be independent of the client
  267. // and that is when we call the equal operator
  268. //
  269. /* virtual const TGenericElement&
  270. operator=(
  271. IN const TGenericElement&
  272. );
  273. //
  274. // Since many of the interfaces supplied by the
  275. // List Manager rely on comparisons between the
  276. // internally maintained elements , so we need
  277. // an == opoperator and a ! operator.
  278. //
  279. virtual BOOL
  280. operator==(
  281. IN const TGenericElement&
  282. ) const;
  283. virtual BOOL
  284. operator!(
  285. VOID
  286. ) const;*/
  287. //
  288. // Some times we might return a dummy invalid
  289. // element to invalidate the result of a list
  290. // manager method
  291. //
  292. virtual VOID
  293. SetValidity(
  294. IN DWORD
  295. ) = 0;
  296. virtual BOOL
  297. Validate(
  298. VOID
  299. ) const = 0;
  300. };
  301. //
  302. // Since our iimplementation of C++ does not have a #pragma implementation ,
  303. // so I am including the implementation file directly in the header file
  304. //
  305. #include "collmgr.cxx"
  306. #endif //__COLLMGR_HPP__