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.

297 lines
6.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1995 - 1997 **/
  4. /**********************************************************************/
  5. /*
  6. FILE HISTORY:
  7. */
  8. #ifndef _OBJPLUS_H_
  9. #define _OBJPLUS_H_
  10. //
  11. // Forward declarations
  12. //
  13. class CObjHelper ;
  14. class CObjectPlus ;
  15. class CObOwnedList ;
  16. class CObListIter ;
  17. class CObOwnedArray ;
  18. //
  19. // Wrappers for the *BROKEN* C8 TRY/CATCH stuff
  20. //
  21. #define CATCH_MEM_EXCEPTION \
  22. TRY
  23. #define END_MEM_EXCEPTION(err) \
  24. CATCH_ALL(e) { \
  25. err = ERROR_NOT_ENOUGH_MEMORY ; \
  26. } END_CATCH_ALL
  27. /****************************************************************************
  28. DEBUGAFX.H
  29. ****************************************************************************/
  30. //
  31. // ENUM for special debug output control tokens
  32. //
  33. enum ENUM_DEBUG_AFX { EDBUG_AFX_EOL = -1 } ;
  34. #if defined(_DEBUG)
  35. #define TRACEFMTPGM DbgFmtPgm( THIS_FILE, __LINE__ )
  36. #define TRACEOUT(x) { afxDump << x ; }
  37. #define TRACEEOL(x) { afxDump << x << EDBUG_AFX_EOL ; }
  38. #define TRACEEOLID(x) { afxDump << TRACEFMTPGM << x << EDBUG_AFX_EOL ; }
  39. #define TRACEEOLERR(err,x) { if (err) TRACEEOLID(x) }
  40. #else
  41. #define TRACEOUT(x) { ; }
  42. #define TRACEEOL(x) { ; }
  43. #define TRACEEOLID(x) { ; }
  44. #define TRACEEOLERR(err,x) { ; }
  45. #endif
  46. //
  47. // Append an EOL onto the debug output stream
  48. //
  49. CDumpContext & operator << ( CDumpContext & out, ENUM_DEBUG_AFX edAfx ) ;
  50. //
  51. // Format a program name and line number for output (removes the path info)
  52. //
  53. extern const char * DbgFmtPgm ( const char * szFn, int line ) ;
  54. /****************************************************************************
  55. OBJPLUS.H
  56. ****************************************************************************/
  57. //
  58. // Helper class for control of construction and API errors
  59. //
  60. class CObjHelper
  61. {
  62. protected:
  63. LONG m_ctor_err ;
  64. LONG m_api_err ;
  65. DWORD m_time_created ;
  66. BOOL m_b_dirty ;
  67. CObjHelper () ;
  68. public:
  69. void AssertValid () const ;
  70. virtual BOOL IsValid () const ;
  71. operator BOOL()
  72. {
  73. return (IsValid());
  74. }
  75. //
  76. // Update the Dirty flag
  77. //
  78. void SetDirty ( BOOL bDirty = TRUE )
  79. {
  80. m_b_dirty = bDirty ;
  81. }
  82. //
  83. // Query the Dirty flag
  84. //
  85. BOOL IsDirty () const
  86. {
  87. return m_b_dirty ;
  88. }
  89. //
  90. // Return the creation time of this object
  91. //
  92. DWORD QueryCreationTime() const
  93. {
  94. return m_time_created ;
  95. }
  96. //
  97. // Return the elapsed time this object has been alive.
  98. //
  99. DWORD QueryAge () const ;
  100. //
  101. // Query/set constuction failure
  102. //
  103. void ReportError ( LONG errInConstruction ) ;
  104. LONG QueryError () const
  105. {
  106. return m_ctor_err ;
  107. }
  108. //
  109. // Reset all error conditions.
  110. //
  111. void ResetErrors ()
  112. {
  113. m_ctor_err = m_api_err = 0 ;
  114. }
  115. //
  116. // Query/set API errors.
  117. //
  118. LONG QueryApiErr () const
  119. {
  120. return m_api_err ;
  121. }
  122. //
  123. // SetApiErr() echoes the error to the caller.for use in expressions.
  124. //
  125. LONG SetApiErr ( LONG errApi = 0 ) ;
  126. };
  127. class CObjectPlus : public CObject, public CObjHelper
  128. {
  129. public:
  130. CObjectPlus () ;
  131. //
  132. // Compare one object with another
  133. //
  134. virtual int Compare ( const CObjectPlus * pob ) const ;
  135. //
  136. // Define a typedef for an ordering function.
  137. //
  138. typedef int (CObjectPlus::*PCOBJPLUS_ORDER_FUNC) ( const CObjectPlus * pobOther ) const ;
  139. //
  140. // Helper function to release RPC memory from RPC API calls.
  141. //
  142. static void FreeRpcMemory ( void * pvRpcData ) ;
  143. };
  144. class CObListIter : public CObjectPlus
  145. {
  146. protected:
  147. POSITION m_pos ;
  148. const CObOwnedList & m_obList ;
  149. public:
  150. CObListIter ( const CObOwnedList & obList ) ;
  151. CObject * Next () ;
  152. void Reset () ;
  153. POSITION QueryPosition () const
  154. {
  155. return m_pos ;
  156. }
  157. void SetPosition(POSITION pos)
  158. {
  159. m_pos = pos;
  160. }
  161. };
  162. //
  163. // Object pointer list which "owns" the objects pointed to.
  164. //
  165. class CObOwnedList : public CObList, public CObjHelper
  166. {
  167. protected:
  168. BOOL m_b_owned ;
  169. static int _cdecl SortHelper ( const void * pa, const void * pb ) ;
  170. public:
  171. CObOwnedList ( int nBlockSize = 10 ) ;
  172. virtual ~ CObOwnedList () ;
  173. BOOL SetOwnership ( BOOL bOwned = TRUE )
  174. {
  175. BOOL bOld = m_b_owned ;
  176. m_b_owned = bOwned ;
  177. return bOld ;
  178. }
  179. CObject * Index ( int index ) ;
  180. CObject * RemoveIndex ( int index ) ;
  181. BOOL Remove ( CObject * pob ) ;
  182. void RemoveAll () ;
  183. int FindElement ( CObject * pobSought ) const ;
  184. //
  185. // Set all elements to dirty or clean. Return TRUE if
  186. // any element was dirty.
  187. //
  188. BOOL SetAll ( BOOL bDirty = FALSE ) ;
  189. //
  190. // Override of CObList::AddTail() to control exception handling.
  191. // Returns NULL if addition fails.
  192. //
  193. POSITION AddTail ( CObjectPlus * pobj, BOOL bThrowException = FALSE ) ;
  194. //
  195. // Sort the list elements according to the
  196. // given ordering function.
  197. //
  198. LONG Sort ( CObjectPlus::PCOBJPLUS_ORDER_FUNC pOrderFunc ) ;
  199. };
  200. //
  201. // Object array which "owns" the objects pointed to.
  202. //
  203. class CObOwnedArray : public CObArray, public CObjHelper
  204. {
  205. protected:
  206. BOOL m_b_owned ;
  207. static int _cdecl SortHelper ( const void * pa, const void * pb ) ;
  208. public:
  209. CObOwnedArray () ;
  210. virtual ~ CObOwnedArray () ;
  211. BOOL SetOwnership ( BOOL bOwned = TRUE )
  212. {
  213. BOOL bOld = m_b_owned ;
  214. m_b_owned = bOwned ;
  215. return bOld ;
  216. }
  217. void RemoveAt( int nIndex, int nCount = 1);
  218. void RemoveAll () ;
  219. int FindElement ( CObject * pobSought ) const ;
  220. //
  221. // Set all elements to dirty or clean. Return TRUE if
  222. // any element was dirty.
  223. //
  224. BOOL SetAll ( BOOL bDirty = FALSE ) ;
  225. //
  226. // Sort the list elements according to the
  227. // given ordering function.
  228. //
  229. LONG Sort ( CObjectPlus::PCOBJPLUS_ORDER_FUNC pOrderFunc ) ;
  230. private:
  231. void QuickSort(
  232. int nLow,
  233. int nHigh,
  234. CObjectPlus::PCOBJPLUS_ORDER_FUNC pOrderFunc
  235. );
  236. void Swap(
  237. int nIndex1,
  238. int nIndex2
  239. );
  240. };
  241. #endif // _OBJPLUS_H_