CommonHelper.h 1023 B

1234567891011121314151617181920212223242526272829303132333435
  1. // // ******************************************************************
  2. // // /\ /| @File CommonHelper.h
  3. // // \ V/ @Brief
  4. // // | "") @Author lijinwen, ghz005@uni-trend.com.cn
  5. // // / | @Creation 2024-05-16
  6. // // / \\ @Modified 2024-05-16
  7. // // *(__\_\
  8. // // ******************************************************************
  9. #pragma once
  10. #include <type_traits>
  11. #include <typeinfo>
  12. namespace Protocol
  13. {
  14. class CommonHelper
  15. {
  16. public:
  17. template <typename EnumType>
  18. static bool EnumIsDefined(int value)
  19. {
  20. static_assert(std::is_enum_v<EnumType>, "EnumType must be an enumeration type");
  21. return std::underlying_type_t<EnumType>(value) >= 0;
  22. }
  23. template <typename EnumType>
  24. struct EnumTypeInfo
  25. {
  26. static const std::type_info& GetTypeInfo()
  27. {
  28. return typeid(EnumType);
  29. }
  30. };
  31. };
  32. }