Plasma Engine  2.0
Loading...
Searching...
No Matches
ConsoleFunctionHelper_inl.h
1// NO #pragma once in this file !
2
3template <typename R PL_COMMA_IF(ARG_COUNT) PL_LIST(typename P, ARG_COUNT)>
4class plConsoleFunction<R(PL_LIST(P, ARG_COUNT))> : public plConsoleFunctionBase
5{
6public:
7 using FUNC = plDelegate<R(PL_LIST(P, ARG_COUNT))>;
8
9 FUNC m_Func;
10
11 plConsoleFunction(plStringView sFunctionName, plStringView sDescription, FUNC f)
12 : plConsoleFunctionBase(sFunctionName, sDescription)
13 {
14 m_Func = f;
15 }
16
17 plUInt32 GetNumParameters() const override { return ARG_COUNT; }
18
19 virtual plVariant::Type::Enum GetParameterType(plUInt32 uiParam) const override
20 {
21 PL_ASSERT_DEV(uiParam < GetNumParameters(), "Invalid Parameter Index {0}", uiParam);
22
23#if (ARG_COUNT > 0)
24
25 switch (uiParam)
26 {
27 case 0:
29
30# if (ARG_COUNT > 1)
31 case 1:
33# endif
34# if (ARG_COUNT > 2)
35 case 2:
37# endif
38# if (ARG_COUNT > 3)
39 case 3:
41# endif
42# if (ARG_COUNT > 4)
43 case 4:
45# endif
46# if (ARG_COUNT > 5)
47 case 5:
49# endif
50 }
51
52#endif
54 }
55
56 virtual plResult Call(plArrayPtr<plVariant> params) override
57 {
58 plResult r = PL_FAILURE;
59 PL_IGNORE_UNUSED(r);
60
61#if (ARG_COUNT > 0)
62 P0 param0 = params[0].ConvertTo<P0>(&r);
63
64 if (r.Failed())
65 return PL_FAILURE;
66#endif
67
68#if (ARG_COUNT > 1)
69 P1 param1 = params[1].ConvertTo<P1>(&r);
70
71 if (r.Failed())
72 return PL_FAILURE;
73#endif
74
75#if (ARG_COUNT > 2)
76 P2 param2 = params[2].ConvertTo<P2>(&r);
77
78 if (r.Failed())
79 return PL_FAILURE;
80#endif
81
82#if (ARG_COUNT > 3)
83 P3 param3 = params[3].ConvertTo<P3>(&r);
84
85 if (r.Failed())
86 return PL_FAILURE;
87#endif
88
89#if (ARG_COUNT > 4)
90 P4 param4 = params[4].ConvertTo<P4>(&r);
91
92 if (r.Failed())
93 return PL_FAILURE;
94#endif
95
96#if (ARG_COUNT > 5)
97 P5 param5 = params[5].ConvertTo<P5>(&r);
98
99 if (r.Failed())
100 return PL_FAILURE;
101#endif
102
103 m_Func(PL_LIST(param, ARG_COUNT));
104 return PL_SUCCESS;
105 }
106};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
virtual plResult Call(plArrayPtr< plVariant > params) override
Calls the function. Each parameter must be put into an plVariant and all of them are passed along as ...
Definition ConsoleFunctionHelper_inl.h:56
plUInt32 GetNumParameters() const override
Returns the number of parameters that this function takes.
Definition ConsoleFunctionHelper_inl.h:17
virtual plVariant::Type::Enum GetParameterType(plUInt32 uiParam) const override
Returns the type of the n-th parameter.
Definition ConsoleFunctionHelper_inl.h:19
Base class for all types of plConsoleFunction, represents functions to be exposed to plConsole.
Definition ConsoleFunction.h:37
virtual plUInt32 GetNumParameters() const =0
Returns the number of parameters that this function takes.
plConsoleFunctionBase(plStringView sFunctionName, plStringView sDescription)
The constructor takes the function name and description as it should appear in the console.
Definition ConsoleFunction.h:42
Implements the functionality of plConsoleFunctionBase for functions with different parameter types....
Definition ConsoleFunction.h:76
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
A helper struct to convert the C++ type, which is passed as the template argument,...
Definition VariantType.h:97
Enum
This enum describes the type of data that is currently stored inside the variant. Note that changes t...
Definition VariantType.h:26
@ Invalid
The variant stores no (valid) data at the moment.
Definition VariantType.h:27