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.

285 lines
5.7 KiB

  1. #ifndef __TREEPRIORITYQUEUE_CPP
  2. #define __TREEPRIORITYQUEUE_CPP
  3. /*
  4. * Class:
  5. *
  6. * WmiAllocator
  7. *
  8. * Description:
  9. *
  10. * Provides abstraction above heap allocation functions
  11. *
  12. * Version:
  13. *
  14. * Initial
  15. *
  16. * Last Changed:
  17. *
  18. * See Source Depot for change history
  19. *
  20. */
  21. #if 0
  22. #include <precomp.h>
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <TPQueue.h>
  26. #endif
  27. /******************************************************************************
  28. *
  29. * Name:
  30. *
  31. *
  32. * Description:
  33. *
  34. *
  35. *****************************************************************************/
  36. template <class WmiKey,class WmiElement>
  37. WmiTreePriorityQueue <WmiKey,WmiElement> :: WmiTreePriorityQueue (
  38. WmiAllocator &a_Allocator
  39. ) : m_Allocator ( a_Allocator ) ,
  40. m_Tree ( a_Allocator )
  41. {
  42. }
  43. /******************************************************************************
  44. *
  45. * Name:
  46. *
  47. *
  48. * Description:
  49. *
  50. *
  51. *****************************************************************************/
  52. template <class WmiKey,class WmiElement>
  53. WmiTreePriorityQueue <WmiKey,WmiElement> :: ~WmiTreePriorityQueue ()
  54. {
  55. WmiStatusCode t_StatusCode = UnInitialize () ;
  56. }
  57. /******************************************************************************
  58. *
  59. * Name:
  60. *
  61. *
  62. * Description:
  63. *
  64. *
  65. *****************************************************************************/
  66. template <class WmiKey,class WmiElement>
  67. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: Initialize ()
  68. {
  69. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  70. t_StatusCode = m_Tree.Initialize () ;
  71. return t_StatusCode ;
  72. }
  73. /******************************************************************************
  74. *
  75. * Name:
  76. *
  77. *
  78. * Description:
  79. *
  80. *
  81. *****************************************************************************/
  82. template <class WmiKey,class WmiElement>
  83. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: UnInitialize ()
  84. {
  85. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  86. t_StatusCode = m_Tree.UnInitialize () ;
  87. return t_StatusCode ;
  88. }
  89. /******************************************************************************
  90. *
  91. * Name:
  92. *
  93. *
  94. * Description:
  95. *
  96. *
  97. *****************************************************************************/
  98. template <class WmiKey,class WmiElement>
  99. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: EnQueue (
  100. const WmiKey &a_Key ,
  101. const WmiElement &a_Element
  102. )
  103. {
  104. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  105. WmiBasicTree <WmiKey,WmiElement> :: Iterator t_Iterator ;
  106. t_StatusCode = m_Tree.Insert ( a_Key , a_Element , t_Iterator ) ;
  107. return t_StatusCode ;
  108. }
  109. /******************************************************************************
  110. *
  111. * Name:
  112. *
  113. *
  114. * Description:
  115. *
  116. *
  117. *****************************************************************************/
  118. template <class WmiKey,class WmiElement>
  119. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: Top (
  120. Iterator &a_Iterator
  121. )
  122. {
  123. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  124. if ( m_Tree.Size () )
  125. {
  126. a_Iterator = m_Tree.Begin () ;
  127. }
  128. else
  129. {
  130. t_StatusCode = e_StatusCode_NotInitialized ;
  131. }
  132. return t_StatusCode ;
  133. }
  134. /******************************************************************************
  135. *
  136. * Name:
  137. *
  138. *
  139. * Description:
  140. *
  141. *
  142. *****************************************************************************/
  143. template <class WmiKey,class WmiElement>
  144. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: Top (
  145. WmiKey &a_Key ,
  146. WmiElement &a_Element
  147. )
  148. {
  149. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  150. if ( m_Tree.Size () )
  151. {
  152. WmiBasicTree <WmiKey,WmiElement> :: Iterator t_Iterator ;
  153. t_Iterator = m_Tree.Begin () ;
  154. try
  155. {
  156. a_Key = t_Iterator.GetKey () ;
  157. a_Element = t_Iterator.GetElement () ;
  158. }
  159. catch ( Wmi_Heap_Exception &a_Exception )
  160. {
  161. return e_StatusCode_OutOfMemory ;
  162. }
  163. catch ( ... )
  164. {
  165. return e_StatusCode_Unknown ;
  166. }
  167. }
  168. else
  169. {
  170. t_StatusCode = e_StatusCode_NotInitialized ;
  171. }
  172. return t_StatusCode ;
  173. }
  174. /******************************************************************************
  175. *
  176. * Name:
  177. *
  178. *
  179. * Description:
  180. *
  181. *
  182. *****************************************************************************/
  183. template <class WmiKey,class WmiElement>
  184. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: DeQueue ()
  185. {
  186. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  187. if ( m_Tree.Size () )
  188. {
  189. WmiBasicTree <WmiKey,WmiElement> :: Iterator t_Iterator ;
  190. t_Iterator = m_Tree.Begin () ;
  191. t_StatusCode = m_Tree.Delete ( t_Iterator.GetKey () ) ;
  192. }
  193. else
  194. {
  195. t_StatusCode = e_StatusCode_NotInitialized ;
  196. }
  197. return t_StatusCode ;
  198. }
  199. /******************************************************************************
  200. *
  201. * Name:
  202. *
  203. *
  204. * Description:
  205. *
  206. *
  207. *****************************************************************************/
  208. template <class WmiKey,class WmiElement>
  209. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: Delete (
  210. const WmiKey &a_Key
  211. )
  212. {
  213. WmiStatusCode t_StatusCode = m_Tree.Delete ( a_Key ) ;
  214. return t_StatusCode ;
  215. }
  216. /******************************************************************************
  217. *
  218. * Name:
  219. *
  220. *
  221. * Description:
  222. *
  223. *
  224. *****************************************************************************/
  225. template <class WmiKey,class WmiElement>
  226. WmiStatusCode WmiTreePriorityQueue <WmiKey,WmiElement> :: Merge (
  227. WmiTreePriorityQueue <WmiKey,WmiElement> &a_Queue
  228. )
  229. {
  230. WmiStatusCode t_StatusCode = e_StatusCode_Success ;
  231. t_StatusCode = m_Tree.Merge ( a_Queue.m_Tree ) ;
  232. return t_StatusCode ;
  233. }
  234. #endif __TREEPRIORITYQUEUE_CPP