From 22a5749e6f8520e12fd17ec0ccbf015697c0afac Mon Sep 17 00:00:00 2001 From: hyzboy Date: Sat, 7 Jun 2025 23:29:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=92=88=E5=AF=B9enum=20clas?= =?UTF-8?q?s=E7=9A=84ToInt/FromInt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/hgl/TypeFunc.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/inc/hgl/TypeFunc.h b/inc/hgl/TypeFunc.h index 31c7e27..852b657 100644 --- a/inc/hgl/TypeFunc.h +++ b/inc/hgl/TypeFunc.h @@ -1,9 +1,9 @@ -#ifndef HGL_TYPE_FUNC_INCLUDE -#define HGL_TYPE_FUNC_INCLUDE +#pragma once #include #include #include + namespace hgl { #define HGL_OFFICAL_WEB "www.hyzgame.com" @@ -12,6 +12,11 @@ namespace hgl #define ENUM_CLASS_RANGE(begin,end) BEGIN_RANGE=begin,END_RANGE=end,RANGE_SIZE=(END_RANGE-BEGIN_RANGE)+1 + template constexpr const int ToInt(const T &ec){return (int)ec;} + template constexpr const T FromInt(int ec){return (enum class T)ec;} + + template constexpr const size_t RangeSize(){return T::RANGE_SIZE;} + template inline bool RangeCheck(const T &value) { @@ -493,4 +498,3 @@ namespace hgl hgl_free(items); } }//namespace hgl -#endif//HGL_TYPE_FUNC_INCLUDE