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.

56 lines
1.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1997
  6. //
  7. // File: dyncast.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // dyncast.h: Handle dynamic and static casting
  12. //
  13. #ifndef _DYNCAST_H_
  14. #define _DYNCAST_H_
  15. // Macro to perform const_cast; i.e., cast away "const-ness" without
  16. // changing base type.
  17. #define CONST_CAST(type,arg) const_cast<type>(arg)
  18. //
  19. // Function templates for generating error-detecting dynamic casts.
  20. // The compiler will generate the needed version of this based upon the types
  21. // provided. 'DynCastThrow' should be used when you're certain of the
  22. // type of an object. 'PdynCast" should be used when you intend to check
  23. // whether the conversion was successful (result != NULL).
  24. // If 'USE_STATIC_CAST' is defined, static casting is done in DynCastThrow().
  25. //
  26. //#define USE_STATIC_CAST // Uncomment to force static casting
  27. //#define TIME_DYN_CASTS // Uncomment to generate timing information
  28. template <class BASE, class SUB>
  29. void DynCastThrow ( BASE * pbase, SUB * & psub )
  30. {
  31. #ifdef TIME_DYN_CASTS
  32. extern int g_cDynCasts;
  33. g_cDynCasts++;
  34. #endif
  35. #if defined(USE_STATIC_CAST) && !defined(_DEBUG)
  36. psub = (SUB *) pbase;
  37. #else
  38. psub = dynamic_cast<SUB *>(pbase);
  39. ASSERT_THROW( psub, EC_DYN_CAST,"subclass pointer conversion failure");
  40. #endif
  41. }
  42. template <class BASE, class SUB>
  43. SUB * PdynCast ( BASE * pbase, SUB * psub )
  44. {
  45. return dynamic_cast<SUB *>(pbase);
  46. }
  47. #endif // _DYNCAST_H_