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.

193 lines
4.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: cntxlist.hxx
  7. //
  8. // Contents: CContextList header
  9. //
  10. // Classes: CContext
  11. // CContextList
  12. //
  13. // History: 26-Oct-92 DrewB Created
  14. //
  15. //----------------------------------------------------------------------------
  16. #ifndef __CNTXLIST_HXX__
  17. #define __CNTXLIST_HXX__
  18. #include <ole.hxx>
  19. #include <cntxtid.hxx>
  20. //+---------------------------------------------------------------------------
  21. //
  22. // Class: CContext (ctx)
  23. //
  24. // Purpose: Holds a context's data
  25. //
  26. // Interface: See below
  27. //
  28. // History: 26-Oct-92 DrewB Created
  29. // 18-May-93 AlexT Added CMallocBased
  30. //
  31. //----------------------------------------------------------------------------
  32. class CContext; // forward declaration for SAFE macro
  33. SAFE_DFBASED_PTR(CBasedContextPtr, CContext);
  34. class CContext : public CMallocBased
  35. {
  36. public:
  37. ContextId ctxid;
  38. CBasedContextPtr pctxNext;
  39. };
  40. //+---------------------------------------------------------------------------
  41. //
  42. // Class: CContextList (cl)
  43. //
  44. // Purpose: Maintains a list of objects that are context-sensitive
  45. //
  46. // Interface: See below
  47. //
  48. // History: 26-Oct-92 DrewB Created
  49. // 18-May-93 AlexT Added CMallocBased
  50. //
  51. //----------------------------------------------------------------------------
  52. class CContextList : public CMallocBased
  53. {
  54. protected:
  55. inline CContextList(void);
  56. inline ~CContextList(void);
  57. public:
  58. inline void AddRef(void);
  59. inline void Release(void);
  60. inline CContext *_GetHead(void) const;
  61. CContext *_Find(ContextId ctxid);
  62. void Add(CContext *pctx);
  63. void Remove(CContext *pctx);
  64. inline ULONG CountContexts(void);
  65. private:
  66. CBasedContextPtr _pctxHead;
  67. LONG _cReferences;
  68. };
  69. // Macro to define methods for a derived class
  70. #define DECLARE_CONTEXT_LIST(type) \
  71. inline type *Find(ContextId cid) { return (type *)_Find(cid); }\
  72. inline type *GetHead(void) const { return (type *)_GetHead(); }\
  73. //+---------------------------------------------------------------------------
  74. //
  75. // Member: CContextList::CContextList, public
  76. //
  77. // Synopsis: Constructor
  78. //
  79. // History: 27-Oct-92 DrewB Created
  80. //
  81. //----------------------------------------------------------------------------
  82. inline CContextList::CContextList(void)
  83. {
  84. _pctxHead = NULL;
  85. _cReferences = 1;
  86. }
  87. //+---------------------------------------------------------------------------
  88. //
  89. // Member: CContextList::~CContextList, public
  90. //
  91. // Synopsis: Destructor
  92. //
  93. // History: 27-Oct-92 DrewB Created
  94. //
  95. //----------------------------------------------------------------------------
  96. inline CContextList::~CContextList(void)
  97. {
  98. olAssert(_pctxHead == NULL);
  99. olAssert(_cReferences == 0);
  100. }
  101. //+---------------------------------------------------------------------------
  102. //
  103. // Member: CContextList::AddRef, public
  104. //
  105. // Synopsis: Increments the ref count
  106. //
  107. // History: 27-Oct-92 DrewB Created
  108. //
  109. //----------------------------------------------------------------------------
  110. inline void CContextList::AddRef(void)
  111. {
  112. AtomicInc(&_cReferences);
  113. }
  114. //+---------------------------------------------------------------------------
  115. //
  116. // Member: CContextList::Release, public
  117. //
  118. // Synopsis: Decrements the ref count
  119. //
  120. // History: 27-Oct-92 DrewB Created
  121. //
  122. //----------------------------------------------------------------------------
  123. inline void CContextList::Release(void)
  124. {
  125. LONG lRet;
  126. olAssert(_cReferences > 0);
  127. lRet = AtomicDec(&_cReferences);
  128. if (lRet == 0)
  129. delete this;
  130. }
  131. //+---------------------------------------------------------------------------
  132. //
  133. // Member: CContextList::_GetHead, public
  134. //
  135. // Synopsis: Returns the head of the list
  136. //
  137. // History: 26-Oct-92 DrewB Created
  138. //
  139. //----------------------------------------------------------------------------
  140. inline CContext *CContextList::_GetHead(void) const
  141. {
  142. return (CContext *)_pctxHead;
  143. }
  144. //+---------------------------------------------------------------------------
  145. //
  146. // Member: CContextList::Count, public
  147. //
  148. // Synopsis: Counts the number of contexts
  149. //
  150. // Arguments:
  151. //
  152. // Returns: Count of the number of contexts
  153. //
  154. // History: 18-Mar-97 BChapman Created
  155. //
  156. //----------------------------------------------------------------------------
  157. inline ULONG CContextList::CountContexts()
  158. {
  159. CBasedContextPtr pctx;
  160. ULONG cnt=0;
  161. for (pctx = _pctxHead; pctx; pctx = pctx->pctxNext)
  162. ++cnt;
  163. return cnt;
  164. }
  165. #endif // #ifndef __CNTXLIST_HXX__