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.

334 lines
8.0 KiB

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