Skip to content

Commit bda3160

Browse files
Aidan63Aidan Lee
andauthored
Implement special callable comparison (#1313)
Co-authored-by: Aidan Lee <aidan.lee@evcam.com>
1 parent 2ce4afa commit bda3160

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

include/hx/Functions.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef HX_FUNCTIONS_H
22
#define HX_FUNCTIONS_H
33

4+
#include <typeindex>
5+
46
namespace hx
57
{
68
struct HXCPP_EXTERN_CLASS_ATTRIBUTES LocalFunc : public hx::Object
@@ -27,11 +29,16 @@ namespace hx
2729
template<typename T1>
2830
bool IsNotNull(const T1& v1);
2931

32+
struct HXCPP_EXTERN_CLASS_ATTRIBUTES ErasedCallable_obj : public hx::Object
33+
{
34+
virtual std::type_index callableId() const = 0;
35+
};
36+
3037
template<class TReturn, class... TArgs>
3138
class HXCPP_EXTERN_CLASS_ATTRIBUTES Callable_obj;
3239

3340
template<class TReturn, class... TArgs>
34-
class HXCPP_EXTERN_CLASS_ATTRIBUTES Callable_obj<TReturn(TArgs...)> : public hx::Object
41+
class HXCPP_EXTERN_CLASS_ATTRIBUTES Callable_obj<TReturn(TArgs...)> : public ErasedCallable_obj
3542
{
3643
public:
3744
HX_IS_INSTANCE_OF enum { _hx_ClassId = ::hx::clsIdClosure };
@@ -49,6 +56,22 @@ namespace hx
4956
Dynamic __Run(const Array<Dynamic>& inArgs) override = 0;
5057

5158
virtual TReturn HX_LOCAL_RUN(TArgs... args) = 0;
59+
60+
virtual std::type_index callableId() const
61+
{
62+
return std::type_index{ typeid(Callable_obj<TReturn(TArgs...)>) };
63+
}
64+
65+
virtual int __Compare(const ::hx::Object* other) const override
66+
{
67+
auto otherCallable = dynamic_cast<const ErasedCallable_obj*>(other);
68+
if (nullptr == otherCallable)
69+
{
70+
return -1;
71+
}
72+
73+
return callableId() == otherCallable->callableId() ? 0 : -1;
74+
}
5275
};
5376

5477
template<class TReturn, class... TArgs>

0 commit comments

Comments
 (0)