cmTypeMacro.h 2.0 KB

12345678910111213141516171819202122232425262728293031
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmTypeMacro_h
  4. #define cmTypeMacro_h
  5. // All subclasses of cmCommand or cmCTestGenericHandler should
  6. // invoke this macro.
  7. #define cmTypeMacro(thisClass, superclass) \
  8. const char* GetNameOfClass() CM_OVERRIDE { return #thisClass; } \
  9. typedef superclass Superclass; \
  10. static bool IsTypeOf(const char* type) \
  11. { \
  12. if (!strcmp(#thisClass, type)) { \
  13. return true; \
  14. } \
  15. return Superclass::IsTypeOf(type); \
  16. } \
  17. bool IsA(const char* type) CM_OVERRIDE \
  18. { \
  19. return thisClass::IsTypeOf(type); \
  20. } \
  21. static thisClass* SafeDownCast(cmObject* c) \
  22. { \
  23. if (c && c->IsA(#thisClass)) { \
  24. return static_cast<thisClass*>(c); \
  25. } \
  26. return 0; \
  27. } \
  28. class cmTypeMacro_UseTrailingSemicolon
  29. #endif