增加伪函数类Function
This commit is contained in:
parent
6578751de4
commit
e318679d3d
|
|
@ -0,0 +1,28 @@
|
||||||
|
#include "..\e2dcommon.h"
|
||||||
|
|
||||||
|
e2d::Function::Function()
|
||||||
|
: m_func(nullptr)
|
||||||
|
{}
|
||||||
|
|
||||||
|
e2d::Function::Function(std::nullptr_t)
|
||||||
|
: m_func(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
e2d::Function::Function(std::function<void()> func)
|
||||||
|
: m_func(func)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void e2d::Function::operator()(void) const
|
||||||
|
{
|
||||||
|
if (m_func)
|
||||||
|
{
|
||||||
|
m_func();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e2d::Function::operator bool() const
|
||||||
|
{
|
||||||
|
return static_cast<bool>(m_func);
|
||||||
|
}
|
||||||
|
|
@ -11,17 +11,6 @@ namespace e2d
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// 函数对象
|
|
||||||
typedef std::function<void()> Function;
|
|
||||||
|
|
||||||
// 创建函数对象
|
|
||||||
template<typename Object, typename Func>
|
|
||||||
inline Function CreateFunc(Object&& obj, Func&& func)
|
|
||||||
{
|
|
||||||
return std::bind(func, obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if HIGHER_THAN_VS2012
|
#if HIGHER_THAN_VS2012
|
||||||
|
|
||||||
// 初始化列表
|
// 初始化列表
|
||||||
|
|
@ -544,6 +533,46 @@ struct NodeProperty
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// º¯Êý¶ÔÏó
|
||||||
|
class Function
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Function();
|
||||||
|
|
||||||
|
Function(
|
||||||
|
std::nullptr_t
|
||||||
|
);
|
||||||
|
|
||||||
|
Function(
|
||||||
|
std::function<void()> func
|
||||||
|
);
|
||||||
|
|
||||||
|
template<typename Func>
|
||||||
|
Function(
|
||||||
|
Func func
|
||||||
|
)
|
||||||
|
: m_func(func)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Func, typename Object>
|
||||||
|
Function(
|
||||||
|
Func&& func,
|
||||||
|
Object&& obj
|
||||||
|
)
|
||||||
|
{
|
||||||
|
m_func = std::bind(func, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator() (void) const;
|
||||||
|
|
||||||
|
operator bool() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::function<void()> m_func;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// 基础对象
|
// 基础对象
|
||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -216,6 +216,7 @@
|
||||||
<ClCompile Include="..\..\core\Collider\ColliderEllipse.cpp" />
|
<ClCompile Include="..\..\core\Collider\ColliderEllipse.cpp" />
|
||||||
<ClCompile Include="..\..\core\Collider\ColliderRect.cpp" />
|
<ClCompile Include="..\..\core\Collider\ColliderRect.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
<ClCompile Include="..\..\core\Common\Color.cpp" />
|
||||||
|
<ClCompile Include="..\..\core\Common\Function.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\TextStyle.cpp" />
|
<ClCompile Include="..\..\core\Common\TextStyle.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
<ClCompile Include="..\..\core\Common\Object.cpp" />
|
||||||
<ClCompile Include="..\..\core\Common\Point.cpp" />
|
<ClCompile Include="..\..\core\Common\Point.cpp" />
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,9 @@
|
||||||
<ClCompile Include="..\..\core\Common\Color.cpp">
|
<ClCompile Include="..\..\core\Common\Color.cpp">
|
||||||
<Filter>Common</Filter>
|
<Filter>Common</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\core\Common\Function.cpp">
|
||||||
|
<Filter>Common</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\core\easy2d.h" />
|
<ClInclude Include="..\..\core\easy2d.h" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue