Skip to content

Commit 5dff885

Browse files
committed
feat: add ClassMethod implementation
1 parent e13508a commit 5dff885

File tree

3 files changed

+88
-2
lines changed

3 files changed

+88
-2
lines changed

engine/foundation/core/private/rtti/func/class_method.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,29 @@ namespace core {
4444
//[-------------------------------------------------------]
4545
//[ Classes ]
4646
//[-------------------------------------------------------]
47+
ClassMethod::ClassMethod()
48+
: mFunc(nullptr) {
49+
}
4750

51+
ClassMethod::ClassMethod(const String& name, FuncBase* func)
52+
: mName(name)
53+
, mFunc((func)){
54+
}
55+
56+
ClassMethod::~ClassMethod() {
57+
}
58+
59+
bool ClassMethod::operator==(const ClassMethod& other) const {
60+
return (mFunc == other.mFunc);
61+
}
62+
63+
DynamicObject ClassMethod::invoke(Vector<DynamicObject>* args) {
64+
if (mFunc) {
65+
return mFunc->invoke(args);
66+
}
67+
68+
return DynamicObject();
69+
}
4870

4971
//[-------------------------------------------------------]
5072
//[ Namespace ]

engine/foundation/core/public/core/rtti/func/class_method.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ClassMethod : public RttiMember {
5959

6060
ClassMethod();
6161

62-
ClassMethod(const String, FuncBase* func);
62+
ClassMethod(const String& name, FuncBase* func);
6363

6464
~ClassMethod() override;
6565

@@ -82,4 +82,10 @@ class ClassMethod : public RttiMember {
8282
//[-------------------------------------------------------]
8383
//[ Namespace ]
8484
//[-------------------------------------------------------]
85-
}
85+
}
86+
87+
88+
//[-------------------------------------------------------]
89+
//[ Includes ]
90+
//[-------------------------------------------------------]
91+
#include "core/rtti/func/class_method.inl"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
////////////////////////////////////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2025 RacoonStudios
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
5+
// software and associated documentation files (the "Software"), to deal in the Software
6+
// without restriction, including without limitation the rights to use, copy, modify, merge,
7+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
8+
// to whom the Software is furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all copies or
11+
// substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
15+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
16+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18+
// DEALINGS IN THE SOFTWARE.
19+
////////////////////////////////////////////////////////////////////////////////////////////////////
20+
21+
22+
//[-------------------------------------------------------]
23+
//[ Includes ]
24+
//[-------------------------------------------------------]
25+
26+
27+
//[-------------------------------------------------------]
28+
//[ Forward declarations ]
29+
//[-------------------------------------------------------]
30+
#include "core/utility/invokable.h"
31+
32+
33+
//[-------------------------------------------------------]
34+
//[ Namespace ]
35+
//[-------------------------------------------------------]
36+
namespace core {
37+
38+
39+
//[-------------------------------------------------------]
40+
//[ Forward declarations ]
41+
//[-------------------------------------------------------]
42+
43+
44+
//[-------------------------------------------------------]
45+
//[ Classes ]
46+
//[-------------------------------------------------------]
47+
template<typename TReturn, typename TObject, typename... TArgs>
48+
TReturn ClassMethod::call_direct(TObject* obj, TArgs... args) const {
49+
typedef Invokable<TReturn, TObject*, TArgs...> InvokableType;
50+
InvokableType* casted = (InvokableType*)mFunc;
51+
return casted->invoke(args...);
52+
}
53+
54+
55+
//[-------------------------------------------------------]
56+
//[ Namespace ]
57+
//[-------------------------------------------------------]
58+
}

0 commit comments

Comments
 (0)