Source code of Windows XP (NT5)
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.

262 lines
5.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999.
  5. //
  6. // File: B I N D I N G S . H
  7. //
  8. // Contents: The basic datatypes for binding objects. Bindpaths are
  9. // ordered collections of component pointers. Bindsets
  10. // are a collection of bindpaths. This module declares the
  11. // objects which represent them.
  12. //
  13. // Notes:
  14. //
  15. // Author: shaunco 15 Jan 1999
  16. //
  17. //----------------------------------------------------------------------------
  18. #pragma once
  19. #include "comp.h"
  20. class CComponentList;
  21. // A bindpath is an ordered collection of pointers to components.
  22. // The order in the collection is the order of the components on
  23. // the bindpath from top to bottom.
  24. // e.g.
  25. // a, b, c, and d represent components.
  26. // a bindpath of a -> b -> c -> d is represented in this data
  27. // structure by a vector:
  28. // vector offset: 0 1 2 3
  29. // vector data : a b c d
  30. // hence, the zeroth element in this data structure is the top-most
  31. // (first) component in the bindpath. The last element in this
  32. // data structure is the bottom-most (last) component.
  33. //
  34. // vector was chosen as the base class because it implements
  35. // contiguous storage with fast inserts at the end. Since, we only
  36. // build bindpaths by inserting components at the end, it was a
  37. // natural choice. list uses non-contiguous storage which tends to
  38. // fragment the heap -- especially with lots of small allocations.
  39. // We create many CBindPath instances, and since each node is a pointer,
  40. // using vector over list is much easier on the heap.
  41. //
  42. // For a bindpath to be valid, it must not be empty and it must not
  43. // contain any dupliate component pointers.
  44. //
  45. class CBindPath : public vector<CComponent*>
  46. {
  47. public:
  48. bool
  49. operator< (
  50. const CBindPath& OtherPath) const;
  51. bool
  52. operator> (
  53. const CBindPath& OtherPath) const;
  54. VOID
  55. Clear ()
  56. {
  57. clear ();
  58. }
  59. UINT
  60. CountComponents () const
  61. {
  62. return size();
  63. }
  64. BOOL
  65. FAllComponentsLoadedOkayIfLoadedAtAll () const;
  66. BOOL
  67. FContainsComponent (
  68. IN const CComponent* pComponent) const
  69. {
  70. return (find (begin(), end(), pComponent) != end());
  71. }
  72. BOOL
  73. FGetPathToken (
  74. OUT PWSTR pszToken,
  75. IN OUT ULONG* pcchToken) const;
  76. BOOL
  77. FIsEmpty () const
  78. {
  79. return empty();
  80. }
  81. BOOL
  82. FIsSameBindPathAs (
  83. IN const CBindPath* pOtherPath) const;
  84. BOOL
  85. FIsSubPathOf (
  86. IN const CBindPath* pOtherPath) const;
  87. HRESULT
  88. HrAppendBindPath (
  89. IN const CBindPath* pBindPath);
  90. HRESULT
  91. HrAppendComponent (
  92. IN const CComponent* pComponent);
  93. HRESULT
  94. HrGetComponentsInBindPath (
  95. IN OUT CComponentList* pComponents) const;
  96. HRESULT
  97. HrInsertComponent (
  98. IN const CComponent* pComponent);
  99. HRESULT
  100. HrReserveRoomForComponents (
  101. IN UINT cComponents);
  102. CComponent*
  103. PGetComponentAtIndex (
  104. IN UINT unIndex) const
  105. {
  106. return (unIndex < size()) ? (*this)[unIndex] : NULL;
  107. }
  108. CComponent*
  109. POwner () const
  110. {
  111. AssertH (CountComponents() > 1);
  112. AssertH (front());
  113. return front();
  114. }
  115. CComponent*
  116. PLastComponent () const
  117. {
  118. AssertH (CountComponents() > 1);
  119. AssertH (back());
  120. return back();
  121. }
  122. CComponent*
  123. RemoveFirstComponent ()
  124. {
  125. CComponent* pComponent = NULL;
  126. if (size() > 0)
  127. {
  128. pComponent = front();
  129. AssertH(pComponent);
  130. erase(begin());
  131. }
  132. return pComponent;
  133. }
  134. CComponent*
  135. RemoveLastComponent ()
  136. {
  137. CComponent* pComponent = NULL;
  138. if (size() > 0)
  139. {
  140. pComponent = back();
  141. AssertH(pComponent);
  142. pop_back();
  143. }
  144. return pComponent;
  145. }
  146. #if DBG
  147. VOID DbgVerifyBindpath ();
  148. #else
  149. VOID DbgVerifyBindpath () {}
  150. #endif
  151. };
  152. // A binding set is a set of bindpaths. Each bindpath in the set
  153. // must be unique and cannot be empty.
  154. //
  155. class CBindingSet : public vector<CBindPath>
  156. {
  157. public:
  158. VOID
  159. Clear ()
  160. {
  161. clear ();
  162. }
  163. UINT
  164. CountBindPaths () const
  165. {
  166. return size();
  167. }
  168. VOID
  169. Printf (
  170. TRACETAGID ttid,
  171. PCSTR pszPrefixLine) const;
  172. BOOL
  173. FContainsBindPath (
  174. IN const CBindPath* pBindPath) const;
  175. BOOL
  176. FContainsComponent (
  177. IN const CComponent* pComponent) const;
  178. BOOL
  179. FIsEmpty () const
  180. {
  181. return empty();
  182. }
  183. HRESULT
  184. HrAppendBindingSet (
  185. IN const CBindingSet* pBindSet);
  186. HRESULT
  187. HrAddBindPath (
  188. IN const CBindPath* pBindPath,
  189. IN DWORD dwFlags /* INS_FLAGS */);
  190. HRESULT
  191. HrAddBindPathsInSet1ButNotInSet2 (
  192. IN const CBindingSet* pSet1,
  193. IN const CBindingSet* pSet2);
  194. HRESULT
  195. HrCopyBindingSet (
  196. IN const CBindingSet* pSourceSet);
  197. HRESULT
  198. HrGetAffectedComponentsInBindingSet (
  199. IN OUT CComponentList* pComponents) const;
  200. HRESULT
  201. HrReserveRoomForBindPaths (
  202. IN UINT cBindPaths);
  203. CBindPath*
  204. PGetBindPathAtIndex (
  205. IN UINT unIndex)
  206. {
  207. return (unIndex < size()) ? (begin() + unIndex) : end();
  208. }
  209. VOID
  210. RemoveBindPath (
  211. IN const CBindPath* pBindPath);
  212. VOID
  213. RemoveBindPathsWithComponent (
  214. IN const CComponent* pComponent);
  215. VOID
  216. RemoveSubpaths ();
  217. VOID
  218. SortForPnpBind ();
  219. VOID
  220. SortForPnpUnbind ();
  221. };