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.

338 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1990-2000 Microsoft Corporation
  3. Module Name:
  4. Object.hxx
  5. Abstract:
  6. This module contains the class declaration for the OBJECT class,
  7. the root of the Ulib hierarchy. OBJECT is a very important class as
  8. it provides default (and sometimes NONVIRTUAL) implementations for
  9. helping to identify and classify all other objects at run-time. This
  10. capability allows CONTAINERs to manipulate OBJECTs rather than a given
  11. derived class of objects. OBJECTs supply the most primitive support for
  12. polymorphism within the library. Along with CLASS_DESCRIPTORs they supply
  13. the ability to safely determine (Cast) if an OBJECT is of a given class
  14. at run-time.
  15. Author:
  16. David J. Gilman (davegi) 22-Oct-1990
  17. Environment:
  18. ULIB, User Mode
  19. --*/
  20. #if ! defined( _OBJECT_HXX_ )
  21. #define _OBJECT_HXX_
  22. #include "clasdesc.hxx"
  23. DECLARE_CLASS( OBJECT );
  24. #if DBG == 1
  25. extern "C" {
  26. #include <stdio.h>
  27. };
  28. #define DECLARE_OBJECT_DBG_FUNCTIONS \
  29. \
  30. VIRTUAL \
  31. VOID \
  32. DebugDump ( \
  33. IN BOOLEAN Deep DEFAULT FALSE \
  34. ) CONST; \
  35. \
  36. NONVIRTUAL \
  37. PCCLASS_NAME \
  38. DebugGetClassName ( \
  39. ) CONST;
  40. #define DEFINE_OBJECT_DBG_FUNCTIONS \
  41. \
  42. VOID \
  43. OBJECT::DebugDump ( \
  44. IN BOOLEAN Deep \
  45. ) CONST \
  46. { \
  47. (void)(Deep); \
  48. DebugPtrAssert( _ClassDescriptor ); \
  49. } \
  50. \
  51. PCCLASS_NAME \
  52. OBJECT::DebugGetClassName ( \
  53. ) CONST \
  54. { \
  55. DebugPtrAssert( _ClassDescriptor ); \
  56. return( _ClassDescriptor->DebugGetClassName( ));\
  57. }
  58. //
  59. // Debug functions should never be invoked directly. Instead use the
  60. // following Dbg macros. Inline functions are not used so that no space
  61. // is used in the object when debugging is disabled.
  62. //
  63. #define DbgDump( pobj ) \
  64. ( pobj )->DebugDump( FALSE );
  65. #define DbgDumpAll( pobj ) \
  66. ( pobj )->DebugDump( TRUE );
  67. #define DbgDumpDeep( pobj, flag ) \
  68. ( pobj )->DebugDump( flag );
  69. #else // DBG==0
  70. #define DECLARE_OBJECT_DBG_FUNCTIONS
  71. #define DEFINE_OBJECT_DBG_FUNCTIONS
  72. #define DbgDump( pobj )
  73. #define DbgDumpAll( pobj )
  74. #define DbgDumpDeep( pobj, flag )
  75. #endif // DBG
  76. class ULIB_EXPORT OBJECT {
  77. public:
  78. VIRTUAL
  79. ~OBJECT(
  80. );
  81. VIRTUAL
  82. LONG
  83. Compare(
  84. IN PCOBJECT Object
  85. ) CONST;
  86. NONVIRTUAL
  87. PCCLASS_DESCRIPTOR
  88. GetClassDescriptor(
  89. ) CONST;
  90. NONVIRTUAL
  91. BOOLEAN
  92. IsSameClass(
  93. IN PCOBJECT Object
  94. ) CONST;
  95. NONVIRTUAL
  96. BOOLEAN
  97. IsSameObject(
  98. IN PCOBJECT Object
  99. ) CONST;
  100. NONVIRTUAL
  101. CLASS_ID
  102. QueryClassId(
  103. ) CONST;
  104. DECLARE_OBJECT_DBG_FUNCTIONS
  105. protected:
  106. NONVIRTUAL
  107. OBJECT(
  108. );
  109. NONVIRTUAL
  110. VOID
  111. Construct(
  112. );
  113. NONVIRTUAL
  114. VOID
  115. SetClassDescriptor(
  116. IN PCCLASS_DESCRIPTOR ClassDescriptor
  117. );
  118. private:
  119. PCCLASS_DESCRIPTOR _ClassDescriptor;
  120. };
  121. INLINE
  122. VOID
  123. OBJECT::Construct(
  124. )
  125. {
  126. }
  127. INLINE
  128. CLASS_ID
  129. OBJECT::QueryClassId (
  130. ) CONST
  131. /*++
  132. Routine Description:
  133. Return the CLASSID for this object.
  134. Arguments:
  135. None.
  136. Return Value:
  137. CLASSID - The CLASSID as maintained by the object's CLASS_DESCRIPTOR.
  138. Notes:
  139. This function used to be at the end of clasdesac.hxx with th following
  140. note:
  141. This member functions is for OBJECT, not for CLASS_DESCRIPTOR. It is
  142. defined here because it requires CLASS_DESCRIPTOR to be defined in
  143. order to make it inline.
  144. --*/
  145. {
  146. DebugPtrAssert( _ClassDescriptor );
  147. return _ClassDescriptor->QueryClassId();
  148. }
  149. INLINE
  150. VOID
  151. OBJECT::SetClassDescriptor (
  152. IN PCCLASS_DESCRIPTOR ClassDescriptor
  153. )
  154. /*++
  155. Routine Description:
  156. Set the CLASS_DESCRIPTOR for a derived class.
  157. Arguments:
  158. ClassDescriptor - Supplies a pointer to the derived class'
  159. CLASS_DECRIPTOR.
  160. Return Value:
  161. None.
  162. Notes:
  163. This function should only be called by the DEFINE_CONSTRUCTOR macro.
  164. --*/
  165. {
  166. // DebugPtrAssert( ClassDescriptor );
  167. _ClassDescriptor = ClassDescriptor;
  168. }
  169. INLINE
  170. PCCLASS_DESCRIPTOR
  171. OBJECT::GetClassDescriptor (
  172. ) CONST
  173. /*++
  174. Routine Description:
  175. Gain access to the object's CLASS_DESCRIPTOR.
  176. Arguments:
  177. None.
  178. Return Value:
  179. PCCLASS_DESCRIPTOR - A pointer to the CLASS_DESCRIPTOR asscoicated with
  180. this object.
  181. --*/
  182. {
  183. DebugPtrAssert( _ClassDescriptor );
  184. return( _ClassDescriptor );
  185. }
  186. INLINE
  187. BOOLEAN
  188. OBJECT::IsSameClass (
  189. IN PCOBJECT Object
  190. ) CONST
  191. /*++
  192. Routine Description:
  193. Determine if this object and the supplied object are of the same class
  194. by checking their CLASS_IDs for equality.
  195. Arguments:
  196. Object - Supplies the object to compare class types against.
  197. Return Value:
  198. BOOLEAN - Returns TRUE if this object and the supplied object are of
  199. the same class.
  200. --*/
  201. {
  202. DebugPtrAssert( Object );
  203. return (BOOLEAN) (QueryClassId() == Object->QueryClassId());
  204. }
  205. INLINE
  206. BOOLEAN
  207. OBJECT::IsSameObject (
  208. IN PCOBJECT Object
  209. ) CONST
  210. /*++
  211. Routine Description:
  212. Determine if this object and the supplied object are the same by checking
  213. their CLASS_IDs and then their memory location.
  214. Arguments:
  215. Object - Supplies the object to compare for equivalence.
  216. Return Value:
  217. BOOLEAN - Returns TRUE if this object and the supplied object are
  218. equivalent.
  219. --*/
  220. {
  221. return (BOOLEAN) (this == Object);
  222. }
  223. #endif // OBJECT