增加针对enum class的ToInt/FromInt
This commit is contained in:
parent
098b87d8ce
commit
22a5749e6f
@ -1,9 +1,9 @@
|
|||||||
#ifndef HGL_TYPE_FUNC_INCLUDE
|
#pragma once
|
||||||
#define HGL_TYPE_FUNC_INCLUDE
|
|
||||||
|
|
||||||
#include<hgl/platform/Platform.h>
|
#include<hgl/platform/Platform.h>
|
||||||
#include<cmath>
|
#include<cmath>
|
||||||
#include<cstring>
|
#include<cstring>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
#define HGL_OFFICAL_WEB "www.hyzgame.com"
|
#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
|
#define ENUM_CLASS_RANGE(begin,end) BEGIN_RANGE=begin,END_RANGE=end,RANGE_SIZE=(END_RANGE-BEGIN_RANGE)+1
|
||||||
|
|
||||||
|
template<typename T> constexpr const int ToInt(const T &ec){return (int)ec;}
|
||||||
|
template<typename T> constexpr const T FromInt(int ec){return (enum class T)ec;}
|
||||||
|
|
||||||
|
template<typename T> constexpr const size_t RangeSize(){return T::RANGE_SIZE;}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline bool RangeCheck(const T &value)
|
inline bool RangeCheck(const T &value)
|
||||||
{
|
{
|
||||||
@ -493,4 +498,3 @@ namespace hgl
|
|||||||
hgl_free(items);
|
hgl_free(items);
|
||||||
}
|
}
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_TYPE_FUNC_INCLUDE
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user